-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent MCP connection errors when toggling auto-approve on running tools #7190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
|---|---|---|
|
|
@@ -1690,8 +1690,31 @@ export class McpHub { | |
|
|
||
| await fs.writeFile(normalizedPath, JSON.stringify(config, null, 2)) | ||
|
|
||
| if (connection) { | ||
| connection.server.tools = await this.fetchToolsList(serverName, source) | ||
| // Update the local tools list without making an MCP request | ||
| // This avoids connection issues when toggling auto-approve on running tools | ||
| if (connection && connection.server.tools) { | ||
| // Update the local tool's alwaysAllow or enabledForPrompt property | ||
| const tool = connection.server.tools.find((t) => t.name === toolName) | ||
| if (tool) { | ||
| if (listName === "alwaysAllow") { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we consider extracting this duplicated logic into a helper method? This same pattern appears in the This would make the code more maintainable and reduce duplication. |
||
| tool.alwaysAllow = addTool | ||
| } else if (listName === "disabledTools") { | ||
| tool.enabledForPrompt = !addTool | ||
| } | ||
| } | ||
| await this.notifyWebviewOfServerChanges() | ||
| } else if (connection && connection.type === "connected") { | ||
| // Only fetch tools list if we don't have it cached and the connection is active | ||
| try { | ||
| connection.server.tools = await this.fetchToolsList(serverName, source) | ||
| await this.notifyWebviewOfServerChanges() | ||
| } catch (error) { | ||
| // If fetching fails, just notify with current state | ||
| console.warn(`Failed to refresh tools list for ${serverName}, using cached state:`, error) | ||
| await this.notifyWebviewOfServerChanges() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional that we don't handle the case where tools might be undefined after a failed fetch? The catch block logs a warning but continues, and if |
||
| } | ||
| } else { | ||
| // For disconnected servers, just notify with current state | ||
| await this.notifyWebviewOfServerChanges() | ||
| } | ||
| } | ||
|
|
||
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.
The comment could be more specific about which connection issues this prevents. Consider: