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

filesystem: expandHome() does not handle Windows backslash separator (~\path)

未关闭 适合新手
#5,180 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@BOHAOYUAN 已经在做这个了。

开始于 2026年10月20日。

  • #1 来自 @BOHAOYUAN —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend

调研方向

阅读 src/filesystem/path-utils.ts 和 src/filesystem/roots-utils.ts,issue 在这两个文件中展示了波浪号展开检查。比较 ~/ 和 ~\ 路径的处理方式,然后查找覆盖 expandHome 和根路径展开的测试。当 Windows 反斜杠波浪号路径能够展开到主目录,且现有用例继续正常工作时,任务即完成。

由索引模型根据 Issue 内容生成。

描述

bug server-filesystem v2
Which server?

filesystem (@modelcontextprotocol/server-filesystem)

Server version

latest (v2/main)

How did you run the server?

npx (npm package)

Transport

stdio

Protocol era

Modern (2026-07-28)

MCP client and version

Claude Desktop / MCP Inspector

Operating system and runtime

Windows 11 / Windows Server, Node.js v20+ / v22+

Server configuration
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "~\\projects"]
    }
  }
}
Steps to reproduce
  1. Run @modelcontextprotocol/server-filesystem on Windows.
  2. Supply an allowed directory argument or path with native Windows backslash tilde notation, e.g., ~\projects or ~\Documents\notes.txt.
  3. expandHome in src/filesystem/path-utils.ts executes:
    export function expandHome(filepath: string): string {
        if (filepath.startsWith("~/") || filepath === "~") {
            return path.join(os.homedir(), filepath.slice(1));
        }
        return filepath;
    }
    
    And similarly in src/filesystem/roots-utils.ts:
    if (rawPath.startsWith("~/") || rawPath === "~") { ... }
    
Expected behavior

On Windows platforms, tilde followed by a backslash (~\) is the natural path separator convention when invoking CLI commands or passing configurations (e.g. ~\workspace). expandHome should recognize both ~/ and ~\ prefixes and expand them to os.homedir().

Actual behavior

Because the condition strictly checks .startsWith("~/"), any path formatted with backslashes (such as ~\projects or ~\\projects) fails to match. expandHome returns the raw string unchanged.

Downstream, path.resolve() interprets ~ as a literal directory name relative to the current working directory (e.g. C:\current\dir\~\projects), causing directory validation to fail with:
Access denied - Path does not exist or is outside allowed directories

Logs or error output
Node.js REPL test:
> const path = require('path');
> const os = require('os');
> function expandHome(p) { if (p.startsWith('~/') || p === '~') return path.join(os.homedir(), p.slice(1)); return p; }

> expandHome('~/test')
'C:\\Users\\User\\test'   // OK (POSIX slash)

> expandHome('~\\test')
'~\\test'                 // Fails to expand Windows backslash
Already prototyped a fix?

Update expandHome in src/filesystem/path-utils.ts and roots-utils.ts to recognize ~\:

export function expandHome(filepath: string): string {
    if (filepath === "~" || filepath.startsWith("~/") || filepath.startsWith("~\\")) {
        return path.join(os.homedir(), filepath.slice(1));
    }
    return filepath;
}
Before you submit
  • I searched existing issues and this is not a duplicate.
  • This is not a security vulnerability report (those go through the private advisory form).
主要语言
TypeScript
星标
91.4k
派生
11.8k
平均合并
7 小时 36 分钟
30 天内合并 PR
126

环境准备

从这里开始

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

modelcontextprotocol/servers 的其他 Issue

查看 modelcontextprotocol/servers 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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