fix(filesystem): preserve CLI directories when MCP roots are available#3970
Open
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix(filesystem): preserve CLI directories when MCP roots are available#3970Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
CLI-provided allowed directories are now respected as the authoritative source when present. Previously, the oninitialized handler and roots/list_changed notification handler would unconditionally replace CLI directories with the client's MCP roots, making it impossible to scope the server to directories outside the client's project root. The fix tracks whether directories were explicitly provided via CLI arguments and skips root resolution in both handlers when they were. MCP roots are still used as a fallback when no CLI directories are given. Fixes modelcontextprotocol#3929
…oots Covers the cliDirectoriesProvided flag behavior: - oninitialized skips MCP roots when CLI dirs are provided - roots/list_changed notification is ignored when CLI dirs are provided - MCP roots are still used when no CLI dirs are given (backward compat)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
oninitializedhandler and theroots/list_changednotification handler respect this precedenceProblem
When configuring the filesystem server with an explicit directory (e.g.,
/path/to/external-project) and using it from a client that supports MCP roots (e.g., Claude Code with project root at/path/to/my-repo), the server would replace the CLI directory with the client's root on initialization. This made it impossible to scope the server to directories outside the client's project root.Fix
A
cliDirectoriesProvidedflag tracks whether directories were explicitly provided via CLI arguments. When set, both the initialization and runtime roots update handlers skip root resolution and keep the CLI-provided directories.Fixes #3929
Test plan
list_allowed_directoriesreturns CLI directory