-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat(filesystem): implement MCP roots protocol for dynamic directory management #2002
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
feat(filesystem): implement MCP roots protocol for dynamic directory management #2002
Conversation
|
Sure @olaservo, thanks for adding the tests and reaching out |
e510f9f to
1264dba
Compare
|
Hi @olaservo, refactored roots processing logic into |
olaservo
left a comment
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.
Left a few comments on docs and logging, otherwise I think this LGTM.
1264dba to
d59bffd
Compare
|
Thanks again @olaservo! Applied the updates from your suggestions. Appreciate you taking the time! |
|
@nandsha Sorry one quick ask - can you pull in the latest from main? We merged in a couple updates to CI that I'd like to run on this PR. Thanks! |
fd0344a to
5a780bb
Compare
|
All good @olaservo, rebased and ready! |
|
Thanks @nandsha , LGTM! Heads up I'm still checking in on another PR from the core team that might need to go ahead of this, but I'll plan to merge this one on Monday. |
…management - Add support for dynamic directory updates via MCP roots protocol - Allow clients to override command-line directories at runtime - Maintain backwards compatibility with existing command-line args - Add comprehensive error handling for edge cases - Update documentation to explain both configuration methods Fixes modelcontextprotocol#401
…management - Extract roots processing logic from index.ts into testable roots-utils.ts module and add Test suite - Update README to recommend MCP roots protocol for dynamic directory management
Co-authored-by: Ola Hungerford <olahungerford@gmail.com>
f30e6a7 to
f3891aa
Compare
…o roots protocol - Add symlink resolution using fs.realpath() for security consistency - Support home directory expansion (~/) in root URI specifications - Improve error handling with null checks, detailed error messages, and informative logging - Change allowedDirectories from constant to variable to support roots protocol directory management
8a80d19 to
2c922a9
Compare
|
Hi @olaservo, I have synced the latest changes and added symlink resolution and home directory expansion support for roots URI processing. Thanks! |
|
Hi @nandsha , I checked this out locally on my Windows machine since I realized that platform differences can have a big impact with this server. I ran into some issues running the race condition tests on Windows, that were due to the environment being less permissive with creating symlinks by default. There is also a Windows-specific issue with the way the path is being validated. However, there is also an incoming PR I'm helping prepare to add Windows fixes, so I am going to go ahead and merge this and then address those as a fast follow. One other thing I'm thinking about is how to validate this more fully end-to-end with a client that is actually integrated with a model. I think that is outside of the scope of the groundwork you did here, since this change has been validated with Inspector. Basically this PR is still ahead of the curve on where most host apps are at wrt Roots (to the best of my knowledge). But I think it will actually be useful in helping us solve that chicken or egg problem. If you have any interest in getting involved with a new Community Working Group around validation and reference implementations, please take a look at the CWG repo for more info on how to get involved there too: https://github.com/modelcontextprotocol-community/working-groups?tab=readme-ov-file#participation-and-contributions |
feat(filesystem): implement MCP roots protocol for dynamic directory management
|
No directory root |
Description
Implements the MCP roots protocol in the filesystem server to enable dynamic directory access management. This allows clients to update the list of accessible directories at runtime without restarting the server.
Server Details
Motivation and Context
Fixes #401 - The filesystem server previously had a fixed set of allowed directories specified via command-line arguments. This implementation adds support for the MCP roots protocol, enabling flexible directory access configuration and runtime updates to accessible filesystem paths.
How Has This Been Tested?
Breaking Changes
No breaking changes. The implementation maintains full backwards compatibility:
Types of changes
Checklist
Additional context
Implementation Details:
oninitializedcallback)roots/list_changednotificationKey Changes:
index.ts:
oninitializedcallbackroots/list_changedREADME.md:
roots-utils.ts: