fix connected servers status not in sync when edit mcp json

This commit is contained in:
Chaiyapruek Muangsiri 2025-08-01 09:03:52 +08:00 committed by Ramon Perez
parent 890a917dec
commit 00f686a733
2 changed files with 14 additions and 9 deletions

View File

@ -25,8 +25,8 @@ type MCPServerStoreState = {
editServer: (key: string, config: MCPServerConfig) => void
deleteServer: (key: string) => void
setServers: (servers: MCPServers) => void
syncServers: () => void
syncServersAndRestart: () => void
syncServers: () => Promise<void>
syncServersAndRestart: () => Promise<void>
}
export const useMCPServers = create<MCPServerStoreState>()((set, get) => ({

View File

@ -84,7 +84,7 @@ function MCPServers() {
const handleSaveServer = async (name: string, config: MCPServerConfig) => {
try {
await toggleServer(name, false)
toggleServer(name, false)
} catch (error) {
console.error('Error deactivating server:', error)
}
@ -102,7 +102,7 @@ function MCPServers() {
}
syncServers()
await toggleServer(name, true)
toggleServer(name, true)
}
const handleEdit = (serverKey: string) => {
@ -147,25 +147,30 @@ function MCPServers() {
) => {
if (jsonServerName) {
try {
await toggleServer(jsonServerName, false)
toggleServer(jsonServerName, false)
} catch (error) {
console.error('Error deactivating server:', error)
}
// Save single server
editServer(jsonServerName, data as MCPServerConfig)
syncServers()
toggleServer(jsonServerName, true)
toggleServer(jsonServerName, (data as MCPServerConfig).active || false)
} else {
// Save all servers
// Clear existing servers first
Object.keys(mcpServers).forEach((key) => {
deleteServer(key)
Object.keys(mcpServers).forEach((serverKey) => {
try {
toggleServer(serverKey, false)
deleteServer(serverKey)
} catch (error) {
console.error('Error deactivating server:', error)
}
})
// Add all servers from the JSON
Object.entries(data as Record<string, MCPServerConfig>).forEach(
([key, config]) => {
addServer(key, config)
toggleServer(key, config.active || false)
}
)
}