Skip to content

fix(filesystem): preserve CLI directories when MCP roots are available#3970

Open
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/cli-dirs-override-roots
Open

fix(filesystem): preserve CLI directories when MCP roots are available#3970
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/cli-dirs-override-roots

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Summary

  • CLI-provided allowed directories now take precedence over MCP roots, fixing the issue where clients that support the roots protocol would unconditionally override explicitly configured directories
  • MCP roots are still used as a fallback when no CLI directories are provided, preserving backward compatibility
  • Both the oninitialized handler and the roots/list_changed notification handler respect this precedence

Problem

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 cliDirectoriesProvided flag 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

  • All 146 existing tests pass
  • Existing startup validation tests confirm the new "CLI directories provided, ignoring MCP roots" log path is hit when CLI args are present
  • Manual: configure server with explicit directory, connect from roots-capable client, verify list_allowed_directories returns CLI directory
  • Manual: start server without CLI args, connect from roots-capable client, verify roots are used as before

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP roots protocol overrides CLI-provided allowed directories

1 participant