fix: keep disabled state across in-flight reconnect results

A reconnect request that completes after the server was disabled no
longer overwrites the disabled state. Connection attempts fold into
disabled when the config no longer allows the server, closing any
fresh connection and clearing its caches; the mcp_toggle enable and
mcp_reconnect handlers apply the same check before writing their
results, and the reconnect failure path keeps disabled when the server
was disabled mid-flight.
This commit is contained in:
vzionv
2026-09-02 09:47:07 +08:00
parent b6fced9af5
commit 65a9fedcfe
2 changed files with 159 additions and 78 deletions
+139 -77
View File
File diff suppressed because it is too large Load Diff
+20 -1
View File
@@ -325,6 +325,21 @@ export function useManageMCPConnections(
commands: Command[]
resources?: ServerResource[]
}) => {
// A connect that completes after the server was disabled (e.g. disable
// during a reconnect request) must not resurrect the server: close any
// fresh connection, clear its caches, and mark it disabled instead.
if (isMcpServerDisabled(client.name)) {
if (client.type === 'connected') {
void clearServerCache(client.name, client.config)
}
updateServer({
name: client.name,
type: 'disabled',
config: client.config,
})
return
}
updateServer({ ...client, tools, commands, resources })
// Handle side effects based on client state
@@ -1027,7 +1042,11 @@ export function useManageMCPConnections(
`Max reconnection attempts (${MAX_RECONNECT_ATTEMPTS}) reached, giving up`,
)
reconnectTimersRef.current.delete(name)
updateServer({ ...client, type: 'failed' })
if (isMcpServerDisabled(name)) {
updateServer({ name, type: 'disabled', config: client.config })
} else {
updateServer({ ...client, type: 'failed' })
}
return
}
}