server-filesystem: MCP roots protocol overwrites CLI-provided allowed directories
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- typescript
- 领域
- backend
调研方向
从 dist/index.js 第 564 行附近开始,然后检查 updateAllowedDirectoriesFromRoots 和 RootsListChangedNotificationSchema handler。使用多个 CLI 目录和一个客户端 root 进行复现,调用 list_allowed_directories,并验证所有现有的 CLI 和客户端目录在初始化后以及 root-list 发生变化后仍然都列在列表中。
由索引模型根据 Issue 内容生成。
描述
Description
When the MCP client supports the roots protocol, the filesystem server's oninitialized handler replaces all command-line allowed directories with only the roots provided by the client. This means any additional directories passed via CLI args are silently discarded.
Steps to Reproduce
- Configure the filesystem MCP server with multiple allowed directories via CLI args:
npx @modelcontextprotocol/server-filesystem /home/user /mnt/Storage /mnt/Games /mnt/Emulators - Connect from a client that supports the MCP roots protocol (e.g., Claude Code) where the working directory is
/home/user - Call
list_allowed_directories
Expected Behavior
All four directories should be listed as allowed:
/home/user
/mnt/Storage
/mnt/Games
/mnt/Emulators
Actual Behavior
Only the client-provided root is listed:
/home/user
The other three directories are silently dropped and become inaccessible.
Root Cause
In dist/index.js, the oninitialized handler (around line 564) unconditionally replaces allowedDirectories with the client roots when the client supports the roots protocol:
server.server.oninitialized = async () => {
const clientCapabilities = server.server.getClientCapabilities();
if (clientCapabilities?.roots) {
const response = await server.server.listRoots();
if (response && 'roots' in response) {
await updateAllowedDirectoriesFromRoots(response.roots);
}
}
};
And updateAllowedDirectoriesFromRoots does a full replacement:
allowedDirectories = [...validatedRootDirs];
Suggested Fix
CLI-provided directories should be preserved and merged with client roots, not replaced. For example:
async function updateAllowedDirectoriesFromRoots(requestedRoots) {
const validatedRootDirs = await getValidRootDirectories(requestedRoots);
if (validatedRootDirs.length > 0) {
// Merge with existing CLI-provided directories instead of replacing
const merged = new Set([...allowedDirectories, ...validatedRootDirs]);
allowedDirectories = [...merged];
setAllowedDirectories(allowedDirectories);
}
}
The same fix should apply to the RootsListChangedNotificationSchema handler.
Environment
@modelcontextprotocol/server-filesystemversion: 2026.1.14- Client: Claude Code (supports MCP roots protocol)
- OS: Linux (openSUSE Tumbleweed)
- All directories exist and are mounted ext4 partitions
- 主要语言
- TypeScript
- 星标
- 90.5k
- 派生
- 11.7k
- 平均合并
- 5 天 19 小时
- 30 天内合并 PR
- 6
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/servers 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/servers#4830 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/servers#4829 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
modelcontextprotocol/servers#4812 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
modelcontextprotocol/servers#4804 · 1 条评论 ·
-
README gate confirmation command can be used by any commenter, bypassing the "readme: pending" gate 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
modelcontextprotocol/servers#4796 ·
查看 modelcontextprotocol/servers 的全部 Issue
相似的 Issue
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
-
Crush 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
catppuccin/catppuccin#3125 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
ElementsProject/cln-application#167 · 1 条评论 · 1 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Quantco/pnpm-licenses#17 ·
-
难度 2/5 1-3 小时 新手友好度 75/100