filesystem: expandHome() does not handle Windows backslash separator (~\path)
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
- 领域
- backend
调研方向
阅读 src/filesystem/path-utils.ts 和 src/filesystem/roots-utils.ts,issue 在这两个文件中展示了波浪号展开检查。比较 ~/ 和 ~\ 路径的处理方式,然后查找覆盖 expandHome 和根路径展开的测试。当 Windows 反斜杠波浪号路径能够展开到主目录,且现有用例继续正常工作时,任务即完成。
由索引模型根据 Issue 内容生成。
描述
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
- Run
@modelcontextprotocol/server-filesystemon Windows. - Supply an allowed directory argument or path with native Windows backslash tilde notation, e.g.,
~\projectsor~\Documents\notes.txt. expandHomeinsrc/filesystem/path-utils.tsexecutes:
And similarly inexport function expandHome(filepath: string): string { if (filepath.startsWith("~/") || filepath === "~") { return path.join(os.homedir(), filepath.slice(1)); } return filepath; }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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/servers 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/servers#5216 ·
维护者通常 1 天内回复
-
bug v2
难度 2/5 1-3 小时 新手友好度 79/100
modelcontextprotocol/servers#5215 ·
维护者通常 1 天内回复
-
documentation server-git server-time v2
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/servers#5213 · 2 条评论 ·
维护者通常 1 天内回复
-
documentation v2
难度 1/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/servers#5212 · 1 条评论 ·
维护者通常 1 天内回复
-
documentation v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/servers#5211 · 1 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/servers 的全部 Issue
相似的 Issue
-
frontend
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
ranxianglei/billion-context#4172 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
awslabs/threat-composer#362 ·
维护者通常 1 天内回复
-
Area/Cloud Needs Triage Type/Bug
难度 1/5 1-3 小时 新手友好度 86/100
wso2/product-integrator#2847 ·
维护者通常 1 天内回复