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 editServer: (key: string, config: MCPServerConfig) => void
deleteServer: (key: string) => void deleteServer: (key: string) => void
setServers: (servers: MCPServers) => void setServers: (servers: MCPServers) => void
syncServers: () => void syncServers: () => Promise<void>
syncServersAndRestart: () => void syncServersAndRestart: () => Promise<void>
} }
export const useMCPServers = create<MCPServerStoreState>()((set, get) => ({ export const useMCPServers = create<MCPServerStoreState>()((set, get) => ({

View File

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