Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

server-filesystem: MCP roots protocol overwrites CLI-provided allowed directories

未关闭 适合新手
#3,602 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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

  1. Configure the filesystem MCP server with multiple allowed directories via CLI args:
    npx @modelcontextprotocol/server-filesystem /home/user /mnt/Storage /mnt/Games /mnt/Emulators
    
  2. Connect from a client that supports the MCP roots protocol (e.g., Claude Code) where the working directory is /home/user
  3. 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-filesystem version: 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/servers 的其他 Issue

查看 modelcontextprotocol/servers 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。