Skip to content

Commit 84642b1

Browse files
committed
fix: complete disabled server handling - UI shows grey status and no retry button
1 parent b4e1337 commit 84642b1

File tree

3 files changed

+236
-158
lines changed

3 files changed

+236
-158
lines changed

src/services/mcp/McpHub.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,15 @@ export class McpHub {
12071207
}
12081208
}
12091209

1210+
// Store disabled state before clearing connections
1211+
const disabledServers = new Map<string, boolean>()
1212+
for (const conn of this.connections) {
1213+
if (conn.server.disabled) {
1214+
const key = `${conn.server.name}-${conn.server.source || "global"}`
1215+
disabledServers.set(key, true)
1216+
}
1217+
}
1218+
12101219
// Clear all existing connections first
12111220
const existingConnections = [...this.connections]
12121221
for (const conn of existingConnections) {
@@ -1218,6 +1227,15 @@ export class McpHub {
12181227
await this.initializeMcpServers("global")
12191228
await this.initializeMcpServers("project")
12201229

1230+
// Re-apply disabled state to servers that were disabled before refresh
1231+
for (const conn of this.connections) {
1232+
const key = `${conn.server.name}-${conn.server.source || "global"}`
1233+
if (disabledServers.has(key) && !conn.server.disabled) {
1234+
// Server was disabled before refresh but got re-enabled, disable it again
1235+
await this.toggleServerDisabled(conn.server.name, true, conn.server.source)
1236+
}
1237+
}
1238+
12211239
await delay(100)
12221240

12231241
await this.notifyWebviewOfServerChanges()
@@ -1339,8 +1357,35 @@ export class McpHub {
13391357

13401358
// If disabling the server, update the connection state and disconnect
13411359
if (disabled) {
1360+
// First update the config file
13421361
connection.server.disabled = true
1362+
1363+
// Store the config before deleting the connection
1364+
const storedConfig = connection.server.config
1365+
1366+
// Delete the connection (this closes transport and client)
13431367
await this.deleteConnection(serverName, serverSource)
1368+
1369+
// Create a placeholder connection for disabled servers
1370+
// This is needed so the server still appears in the UI
1371+
const parsedConfig = JSON.parse(storedConfig)
1372+
parsedConfig.disabled = true
1373+
1374+
const placeholderConnection: McpConnection = {
1375+
server: {
1376+
name: serverName,
1377+
config: JSON.stringify(parsedConfig),
1378+
status: "disconnected",
1379+
disabled: true,
1380+
source: serverSource,
1381+
projectPath:
1382+
serverSource === "project" ? vscode.workspace.workspaceFolders?.[0]?.uri.fsPath : undefined,
1383+
errorHistory: [],
1384+
},
1385+
client: null as any,
1386+
transport: null as any,
1387+
}
1388+
this.connections.push(placeholderConnection)
13441389
} else {
13451390
// If enabling the server, we need to re-read the config and reconnect
13461391
// Get the updated config from the file

src/services/mcp/__tests__/McpHub.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,13 @@ describe("McpHub", () => {
484484
const mockConnection: McpConnection = {
485485
server: {
486486
name: "test-server",
487-
type: "stdio",
488-
command: "node",
489-
args: ["test.js"],
487+
config: JSON.stringify({
488+
type: "stdio",
489+
command: "node",
490+
args: ["test.js"],
491+
disabled: false,
492+
}),
493+
status: "connected",
490494
disabled: false,
491495
source: "global",
492496
} as any,
@@ -734,7 +738,12 @@ describe("McpHub", () => {
734738
// Verify the server was disconnected
735739
expect(mockTransport.close).toHaveBeenCalled()
736740
expect(mockClient.close).toHaveBeenCalled()
737-
expect(mcpHub.connections.length).toBe(0)
741+
// Should have 1 placeholder connection for the disabled server
742+
expect(mcpHub.connections.length).toBe(1)
743+
expect(mcpHub.connections[0].server.disabled).toBe(true)
744+
expect(mcpHub.connections[0].server.status).toBe("disconnected")
745+
expect(mcpHub.connections[0].client).toBeNull()
746+
expect(mcpHub.connections[0].transport).toBeNull()
738747
})
739748

740749
it("should reconnect server when toggling to enabled", async () => {

0 commit comments

Comments
 (0)