Skip to content

Commit 25ecf5d

Browse files
committed
fix: prevent MCP connection errors when toggling auto-approve on running tools
- Modified updateServerToolList to update local tool state without making MCP requests - Added fallback error handling for cases where MCP requests fail - Fixes issue where clicking auto-approve checkbox on running tools caused connection errors Fixes #7189
1 parent e7e827a commit 25ecf5d

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/services/mcp/McpHub.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,31 @@ export class McpHub {
16901690

16911691
await fs.writeFile(normalizedPath, JSON.stringify(config, null, 2))
16921692

1693-
if (connection) {
1694-
connection.server.tools = await this.fetchToolsList(serverName, source)
1693+
// Update the local tools list without making an MCP request
1694+
// This avoids connection issues when toggling auto-approve on running tools
1695+
if (connection && connection.server.tools) {
1696+
// Update the local tool's alwaysAllow or enabledForPrompt property
1697+
const tool = connection.server.tools.find((t) => t.name === toolName)
1698+
if (tool) {
1699+
if (listName === "alwaysAllow") {
1700+
tool.alwaysAllow = addTool
1701+
} else if (listName === "disabledTools") {
1702+
tool.enabledForPrompt = !addTool
1703+
}
1704+
}
1705+
await this.notifyWebviewOfServerChanges()
1706+
} else if (connection && connection.type === "connected") {
1707+
// Only fetch tools list if we don't have it cached and the connection is active
1708+
try {
1709+
connection.server.tools = await this.fetchToolsList(serverName, source)
1710+
await this.notifyWebviewOfServerChanges()
1711+
} catch (error) {
1712+
// If fetching fails, just notify with current state
1713+
console.warn(`Failed to refresh tools list for ${serverName}, using cached state:`, error)
1714+
await this.notifyWebviewOfServerChanges()
1715+
}
1716+
} else {
1717+
// For disconnected servers, just notify with current state
16951718
await this.notifyWebviewOfServerChanges()
16961719
}
16971720
}

0 commit comments

Comments
 (0)