Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

heyseth
Copy link

@heyseth heyseth commented Oct 12, 2025

Related GitHub Issue

Closes: #8231

Description

Problem

Toggling the "Always allow" checkbox for MCP tools in the chat view was causing unnecessary server restarts, disrupting active sessions and chat flow. This occurred because programmatic configuration file updates triggered the file watcher, which then restarted the server as if the user had manually edited the config.

Implementation

Implemented a flag-based mechanism to distinguish between programmatic configuration updates and user-initiated file changes:

  1. Added isProgrammaticUpdate boolean flag to McpHub class
  2. Modified debounceConfigChange() to skip processing when flag is set
  3. Wrapped file write operations in both updateServerToolList() and updateServerConfig() with flag protection
  4. Added 600ms delay (exceeding the 500ms debounce timer) to ensure the flag remains set throughout the watcher's debounce period

Changes Made

  • McpHub.ts:154 - Added isProgrammaticUpdate flag
  • McpHub.ts:282-284 - Skip file watcher processing during programmatic updates
  • McpHub.ts:1703-1711 - Protected updateServerToolList() file writes with flag
  • McpHub.ts:1472-1480 - Protected updateServerConfig() file writes with flag
  • McpHub.ts:1822 - Reset flag during disposal for cleanup

Test Procedure

Manually tested by toggling "Always allow" for MCP tools in the chatview and verifying:

  1. Server connection status remains green
  2. No "Retrying..." message appears
  3. No server restart logs in console
  4. Configuration changes are persisted correctly

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

Get in Touch

Discord: @ocean.smith


Important

Prevents unnecessary MCP server restarts by using a flag to differentiate programmatic updates from user-initiated changes in McpHub.

  • Behavior:
    • Prevents unnecessary server restarts when toggling "Always allow" for MCP tools by using isProgrammaticUpdate flag in McpHub.
    • Skips file watcher processing in debounceConfigChange() when isProgrammaticUpdate is true.
  • Implementation:
    • Adds isProgrammaticUpdate flag to McpHub.
    • Wraps file writes in updateServerToolList() and updateServerConfig() with isProgrammaticUpdate protection.
    • Adds 600ms delay after file writes to ensure flag is active during debounce period.
  • Misc:
    • Resets isProgrammaticUpdate flag during disposal in dispose() method.

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

Add isProgrammaticUpdate flag to distinguish between programmatic config
updates and user-initiated file changes. Skip file watcher processing
during programmatic updates to prevent unnecessary server restarts.
@heyseth heyseth requested review from cte, jr and mrubens as code owners October 12, 2025 23:22
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Oct 12, 2025
src/services/mcp/McpHub.ts Outdated Show resolved Hide resolved
src/services/mcp/McpHub.ts Outdated Show resolved Hide resolved
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 12, 2025
Fixed bug where MCP servers would reconnect instead of staying disabled when toggled off. The issue was that toggleServerDisabled() used stale in-memory config instead of reading the fresh config from disk after writing the disabled flag.

Changes:
Added readServerConfigFromFile() helper to read and validate server config from disk
Updated disable path to read fresh config before calling connectToServer()
Updated enable path to read fresh config before calling connectToServer()
This ensures the disabled: true flag is properly read, causing connectToServer() to create a disabled placeholder connection instead of actually connecting the server.

+ refactor(mcp): use safeWriteJson for atomic config writes

Replace JSON.stringify + fs.writeFile with safeWriteJson in McpHub.ts
to prevent data corruption through atomic writes with file locking.
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 13, 2025
src/services/mcp/McpHub.ts Outdated Show resolved Hide resolved
src/services/mcp/McpHub.ts Outdated Show resolved Hide resolved
Replace multiple independent reset timers with a single timer that gets
cleared and rescheduled on each programmatic config update. This prevents
the flag from being reset prematurely when multiple rapid updates occur,
which could cause unwanted server restarts during the file watcher's
debounce period.

+ fix(mcp): ensure isProgrammaticUpdate flag cleanup with try-finally

Wrap safeWriteJson() calls in try-finally blocks to guarantee the
isProgrammaticUpdate flag is always reset, even if the write operation
fails. This prevents the flag from being stuck at true indefinitely,
which would cause subsequent user-initiated config changes to be
silently ignored.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 13, 2025
@heyseth
Copy link
Author

heyseth commented Oct 13, 2025

While testing these fixes I discovered a bug (not caused by my changes):

Steps to reproduce:

  1. Open Roo in a workspace
  2. Open a second Roo tab in the same workspace
  3. In the newly open Roo tab, give Roo instructions to call an MCP tool
  4. If the user tries to check/uncheck the "always allow" checkbox for the mcp tool, the changes are not recognized, and do not persist.
  5. Changes in the "MCP Servers" menu made from the second Roo tab also don't persist.
  6. It appears that the changes are being applied to the original Roo tab in the workspace.

Should I create a new issue for this bug, or try to fix this behavior as part of my PR?

@roomote

Copy link

roomote bot commented Oct 13, 2025

Thanks for the detailed repro steps. This appears to be a cross-tab state sync bug in the MCP settings flow, where changes made in a second Roo tab are applied to the first tab process and do not persist locally. To keep this PR focused on preventing unintended server restarts, I suggest we track the multi-tab persistence issue separately. I will open a new issue with your steps and link it here next.

Copy link

roomote bot commented Oct 13, 2025

Filed tracking issue for this: #8634 (#8634). We will handle the multi-tab persistence bug there and keep this PR focused on preventing unintended server restarts when toggling MCP permissions.

Copy link

roomote bot commented Oct 13, 2025

Summary:

No further changes planned in this PR for that bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Toggling "Always allow" for MCP tool in Chatview restarts server

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.