Merge pull request #6020 from cmppoon/fix-mcp-servers-edit-json

fix connected servers status not in sync when edit mcp json
This commit is contained in:
Louis 2025-08-05 11:06:05 +07:00 committed by GitHub
commit 48004024ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 13 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

@ -83,11 +83,7 @@ function MCPServers() {
} }
const handleSaveServer = async (name: string, config: MCPServerConfig) => { const handleSaveServer = async (name: string, config: MCPServerConfig) => {
try { toggleServer(name, false)
await toggleServer(name, false)
} catch (error) {
console.error('Error deactivating server:', error)
}
if (editingKey) { if (editingKey) {
// If server name changed, delete old one and add new one // If server name changed, delete old one and add new one
if (editingKey !== name) { if (editingKey !== name) {
@ -102,7 +98,7 @@ function MCPServers() {
} }
syncServers() syncServers()
await toggleServer(name, true) toggleServer(name, true)
} }
const handleEdit = (serverKey: string) => { const handleEdit = (serverKey: string) => {
@ -147,25 +143,26 @@ 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) toggleServer(serverKey, false)
deleteServer(serverKey)
}) })
// 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)
} }
) )
} }