Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Aug 18, 2025

Summary

This PR fixes an issue where clicking the auto-approve checkbox on a running MCP tool would cause a connection error.

Problem

When a user clicks the auto-approve checkbox for an MCP tool that is already running, the system attempts to refresh the tools list by making an MCP request. This can fail if:

  • The MCP connection is in an unexpected state
  • The server doesn't handle concurrent requests properly
  • The tool is actively executing

This results in the error: "Error executing MCP tool: MCP error -32000: Connection closed"

Solution

Modified the updateServerToolList method in McpHub.ts to:

  1. Update the local tool state (alwaysAllow/enabledForPrompt) without making MCP requests when possible
  2. Only fetch the tools list if it's not already cached and the connection is active
  3. Add error handling to gracefully fall back to cached state if MCP requests fail

Testing

  • All existing tests pass
  • Type checking passes
  • Linting passes

Related Issue

Fixes #7189


Important

Fixes MCP connection errors when toggling auto-approve on running tools by updating local state in updateServerToolList in McpHub.ts.

  • Behavior:
    • Fixes connection error when toggling auto-approve on running MCP tools by updating local tool state in updateServerToolList in McpHub.ts.
    • Avoids unnecessary MCP requests by updating local state directly if possible.
    • Adds error handling to use cached state if MCP requests fail.
  • Testing:
    • All existing tests pass.
    • Type checking and linting pass.

This description was created by Ellipsis for 25ecf5d. You can customize this summary. It will automatically update as commits are pushed.

…ing 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
@roomote roomote bot requested review from mrubens, cte and jr as code owners August 18, 2025 15:40
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Aug 18, 2025
Copy link
Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in production - technically possible but morally questionable.

} 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()
Copy link
Author

Choose a reason for hiding this comment

The 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 connection.server.tools becomes undefined after the fetch fails, the subsequent code might not behave as expected.

@@ -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
Copy link
Author

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:

// Update the local tool's alwaysAllow or enabledForPrompt property
const tool = connection.server.tools.find((t) => t.name === toolName)
if (tool) {
if (listName === "alwaysAllow") {
Copy link
Author

Choose a reason for hiding this comment

The 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 fetchToolsList method. Something like:

This would make the code more maintainable and reduce duplication.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 18, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 19, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 19, 2025
@daniel-lxs
Copy link
Collaborator

Closing this PR as it doesn't actually fix the root cause.

The problem is that when we write to the config file, the file watcher triggers and calls updateServerConnections, which detects the config change via deepEqual and restarts the server anyway. This PR only avoided the fetchToolsList call but the server still gets restarted, causing the running tool to fail.

The real fix needs to prevent the server restart when only alwaysAllow or disabledTools arrays change.

@daniel-lxs daniel-lxs closed this Aug 20, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 20, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR - Needs Preliminary Review size:S This PR changes 10-29 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

MCP Server connection closes when clicking to Auto-Approve a MCP tool
3 participants