-
Notifications
You must be signed in to change notification settings - Fork 46
fix(mcp): persist MCP toggle state to config #608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -254,6 +254,25 @@ export namespace MCP { | |||
| return commands | ||||
| } | ||||
|
|
||||
| async function persistEnabled(name: string, enabled: boolean, fallback?: Config.Mcp) { | ||||
| const cfg = await Config.get() | ||||
| const config = cfg.mcp ?? {} | ||||
| const current = config[name] | ||||
| const entry = isMcpConfigured(current) ? current : fallback | ||||
| if (!entry) return | ||||
|
|
||||
| await Config.updateGlobal({ | ||||
| mcp: { | ||||
| [name]: { | ||||
| ...entry, | ||||
|
||||
| ...entry, |
Copilot
AI
Feb 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling Config.updateGlobal() on every connect/disconnect has a large side effect: it triggers Instance.disposeAll() (via Config.updateGlobal), which will dispose state for all instances and close existing MCP clients. This can cause unrelated runtime state to reset and other MCP connections to drop when toggling a single server. Consider persisting the flag without disposing instances (or provide a lighter-weight config write path) since runtime status is already updated in-memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Persisting enabled: true even when create() returned null (connection failed) will cause Config.updateGlobal → Instance.disposeAll() to fire, tearing down all other healthy MCP connections. On a failed connect, the side-effect cost of disposal is especially undesirable since there's no new client to show for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING:
Config.updateGlobaltriggersvoid Instance.disposeAll()as a side effect (seeconfig.ts:1556). This means every call topersistEnabledwill asynchronously tear down all instances — including the MCP state — closing every connected MCP client.In
connect(), this causes the just-connected client (and all other MCP clients) to be disposed in the background. The state will lazily re-initialize on next access (re-reading config and reconnecting), but this creates:Consider writing the config file directly without going through
updateGlobal, or adding a mechanism to persist config without triggering full instance disposal.