Skip to content

Conversation

@01Rian
Copy link
Contributor

@01Rian 01Rian commented Mar 17, 2025

Context

#906

The core issues are:

  1. Hardcoded path detection (build/index.js) prevents watching files in alternate directories
  2. File watchers overwrite each other due to reusing the same Map key
  3. No support for flexible path configurations beyond the hardcoded pattern
  4. Inability to watch multiple files or directories without custom configuration

Implementation

  1. Added support for multiple file watchers per server in the McpHub class

    • Changed the fileWatchers map to store arrays of watchers instead of a single watcher
    • Updated the setupFileWatcher method to maintain multiple watchers per server
    • Modified the removeAllFileWatchers method to handle arrays of watchers
  2. Fixed issue where custom watchPaths watchers would overwrite the fallback build/index.js watcher

    • Previous implementation used the server name as a key, causing one watcher to replace the other
    • Now multiple watchers can coexist for the same server, each monitoring different paths
  3. Added proper error handling to file watcher callbacks

    • Made change event callbacks async functions
    • Added try/catch blocks around await this.restartConnection(name) calls
    • Included detailed error logging that identifies which watcher and path triggered the error
  4. Improved logging to distinguish between different types of watchers

    • Added clear console messages to indicate which watcher detected a change
    • Included the changed file path in error messages for easier debugging

Screenshots

before after

How to Test

Configure an MCP server with explicit watchPaths:

{
  "mcpServers": {
    "my-server": {
      "type": "stdio",
      "command": "node",
      "args": ["./dist/index.js"],
      "watchPaths": ["./dist/**/*.js"]
    }
  }
}

Get in Touch


Important

Adds watchPaths option to McpHub for custom file change detection and server restart.

  • Behavior:
    • Adds watchPaths option to BaseConfigSchema in McpHub.ts for custom file path watching.
    • Implements file watchers in setupFileWatcher() to restart servers on file changes.
  • Configuration:
    • Updates BaseConfigSchema to include watchPaths as an optional array of strings.
  • Testing:
    • Example configuration provided for testing with watchPaths in MCP server setup.

This description was created by Ellipsis for c5202d4. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2025

⚠️ No Changeset found

Latest commit: f2711e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Mar 17, 2025
add support multiple watchers per server.

modified the setupFileWatcher method to properly handle asynchronous operations and prevent unhandled promise rejections.

error handling now includes specific error messages that identify exactly where the error occurred.
@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 Mar 17, 2025
@01Rian 01Rian changed the title #906 Add watchPaths option to McpHub for file change detection #906 - Add watchPaths option to McpHub for file change detection Mar 18, 2025
@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap Mar 21, 2025
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 24, 2025
@mrubens mrubens merged commit 809e8cd into RooCodeInc:main Mar 24, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap Mar 24, 2025
@01Rian 01Rian deleted the fix/MCP_Server_Auto-Restart_Path_Issue branch March 26, 2025 18:04
@hannesrudolph
Copy link
Collaborator

@01Rian Do you happen to have discord? would love to include you in our contributors private channel. My username is hrudolph if you can please reach out to me.

@01Rian
Copy link
Contributor Author

01Rian commented May 24, 2025

@hannesrudolph Yes, I sent you a private message on discord.

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

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants