-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: prevent MCP connection error when toggling Always Allow #8599
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 |
|---|---|---|
|
|
@@ -1689,7 +1689,17 @@ export class McpHub { | |
| await fs.writeFile(normalizedPath, JSON.stringify(config, null, 2)) | ||
|
|
||
| if (connection) { | ||
| connection.server.tools = await this.fetchToolsList(serverName, source) | ||
| // Check if the connection is still active before fetching tools | ||
| if (connection.type === "connected" && connection.server.status === "connected") { | ||
| try { | ||
| connection.server.tools = await this.fetchToolsList(serverName, source) | ||
| } catch (error) { | ||
| // If fetching tools fails, log the error but don't throw | ||
| // This prevents the "Connection closed" error from disrupting the UI | ||
| console.error(`Failed to fetch tools after updating ${listName} for ${serverName}:`, error) | ||
| // The tools list will be refreshed on the next successful connection | ||
| } | ||
| } | ||
| await this.notifyWebviewOfServerChanges() | ||
| } | ||
| } | ||
|
|
@@ -1701,6 +1711,18 @@ export class McpHub { | |
| shouldAllow: boolean, | ||
| ): Promise<void> { | ||
| try { | ||
| // Check if the connection exists and is active before proceeding | ||
| const connection = this.findConnection(serverName, source) | ||
| if (!connection) { | ||
| throw new Error(`Server ${serverName} with source ${source} not found`) | ||
| } | ||
|
|
||
| // If the server is disconnected, we can still update the config | ||
| // but we should handle it gracefully | ||
| if (connection.type === "disconnected" || connection.server.status === "disconnected") { | ||
| console.warn(`Server ${serverName} is disconnected. Updating configuration only.`) | ||
| } | ||
|
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. Critical: This validation is redundant and creates misleading behavior. The warning message suggests the operation might fail, but
Suggestion: Remove this pre-flight validation entirely. The
The current implementation adds no value and confuses the control flow. |
||
|
|
||
| await this.updateServerToolList(serverName, source, toolName, "alwaysAllow", shouldAllow) | ||
| } catch (error) { | ||
| this.showErrorMessage( | ||
|
|
||
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.
Minor: The error is caught and logged, but the UI isn't notified that the tools list might be stale. Consider adding a visual indicator or updating
connection.server.errorto inform users that the tools list couldn't be refreshed, even though the config was updated successfully.