Skip to content

Commit 59e9f87

Browse files
committed
fix: disconnect MCP servers immediately when MCP is disabled
- Modified webviewMessageHandler to actively disconnect all running MCP servers when the 'Enable MCP Servers' checkbox is unchecked - Added logic to reconnect servers when MCP is re-enabled - This ensures servers are shut down immediately without requiring a plugin reload
1 parent 9ee690e commit 59e9f87

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,23 @@ export const webviewMessageHandler = async (
880880
case "mcpEnabled":
881881
const mcpEnabled = message.bool ?? true
882882
await updateGlobalState("mcpEnabled", mcpEnabled)
883+
884+
// If MCP is being disabled, disconnect all servers
885+
const mcpHubInstance = provider.getMcpHub()
886+
if (!mcpEnabled && mcpHubInstance) {
887+
// Disconnect all existing connections
888+
const existingConnections = [...mcpHubInstance.connections]
889+
for (const conn of existingConnections) {
890+
await mcpHubInstance.deleteConnection(conn.server.name, conn.server.source)
891+
}
892+
893+
// Re-initialize servers to track them in disconnected state
894+
await mcpHubInstance.refreshAllConnections()
895+
} else if (mcpEnabled && mcpHubInstance) {
896+
// If MCP is being enabled, reconnect all servers
897+
await mcpHubInstance.refreshAllConnections()
898+
}
899+
883900
await provider.postStateToWebview()
884901
break
885902
case "enableMcpServerCreation":

0 commit comments

Comments
 (0)