Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/services/mcp/McpHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

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.error to inform users that the tools list couldn't be refreshed, even though the config was updated successfully.

// The tools list will be refreshed on the next successful connection
}
}
await this.notifyWebviewOfServerChanges()
}
}
Expand All @@ -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.`)
}
Copy link
Author

Choose a reason for hiding this comment

The 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 updateServerToolList (called on line 1726) performs the exact same connection checks and handles disconnected servers gracefully. This creates two problems:

  1. Redundant checks: Connection state is validated twice
  2. Misleading warning: The warning implies failure, but the config update succeeds regardless of connection state

Suggestion: Remove this pre-flight validation entirely. The updateServerToolList method already handles disconnected servers correctly by:

  • Checking connection state before fetching tools (line 1693)
  • Catching and logging fetch errors (line 1696-1700)
  • Still updating the config file even if tools can't be fetched

The current implementation adds no value and confuses the control flow.


await this.updateServerToolList(serverName, source, toolName, "alwaysAllow", shouldAllow)
} catch (error) {
this.showErrorMessage(
Expand Down