Skip to content

Commit c89233d

Browse files
committed
fix: prevent disabled MCP servers from restarting due to config file watcher
- Added check in handleConfigFileChange to ignore file change events for servers with active toggle operations - This prevents the race condition where disabling a server triggers a config write, which triggers the file watcher, which would restart the server - Fixes the issue where disabled servers would immediately restart after being shut down
1 parent 3f50226 commit c89233d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/services/mcp/McpHub.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,19 @@ export class McpHub {
315315
return
316316
}
317317

318-
await this.updateServerConnections(result.data.mcpServers || {}, source)
318+
// Check if any servers have toggle operations in progress
319+
const servers = result.data.mcpServers || {}
320+
const hasActiveToggleOperations = Object.keys(servers).some((serverName) => {
321+
const operationKey = `${serverName}-${source}`
322+
return this.toggleOperations.has(operationKey)
323+
})
324+
325+
if (hasActiveToggleOperations) {
326+
console.log(`Skipping config file change for ${source} - toggle operations in progress`)
327+
return
328+
}
329+
330+
await this.updateServerConnections(servers, source)
319331
} catch (error) {
320332
// Check if the error is because the file doesn't exist
321333
if (error.code === "ENOENT" && source === "project") {

0 commit comments

Comments
 (0)