[Bug] `.mcp.json` env values pass `${workspaceFolder}` through literally (no expansion)
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate. (Closest existing issue is #15, which requests an MCP reload command — different concern; nothing covers variable expansion in
.mcp.jsonenv.) - 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category
工具调用 / MCP · Tool use / MCP
涉及的 Agent 框架 · Agent framework
不涉及框架 · Not framework-specific
严重程度 · Severity
影响体验 · Major (功能可用但体验受损 / works but degraded)
复现频率 · Reproducibility
必现 · Always
问题描述 · Description
When an MCP server's env block in .mcp.json contains the VS Code-style variable ${workspaceFolder}, ZCode passes the literal string ${workspaceFolder} to the spawned server process instead of expanding it to the workspace path. The workspace path is already known to ZCode at spawn time (the server's cwd is correctly set to the workspace), so the variable is simply not being substituted in env values.
复现步骤 · Steps to reproduce
- In any workspace, add to
.mcp.json:{ "mcpServers": { "echo-ws": { "type": "stdio", "command": "node", "args": ["-e", "console.log('WS=' + process.env.WORKSPACE_ROOT)"], "env": { "WORKSPACE_ROOT": "${workspaceFolder}" } } } } - Start the MCP server (open the workspace / trigger the server).
- Observe the server prints
WS=${workspaceFolder}— the literal token, not the workspace path.
期望表现 · Expected behavior
${workspaceFolder} should expand to the workspace root (e.g. /Users/.../myproject), as the VS Code variable convention documents — or, at minimum, an unrecognized token should be left unset so server-side fallbacks (e.g. process.cwd()) can apply.
实际表现 · Actual behavior
The literal token ${workspaceFolder} reaches the child process, which then uses it as a real path component — e.g. file-delivery code resolves paths to ${workspaceFolder}/generated/... and creates bogus directories under the cwd. Observed via ps eww <pid> on the running server:
HERMES_WORKSPACE_ROOT=${workspaceFolder}
HERMES_OUTPUT_DIR=${workspaceFolder}/.hermes-output
ZCode 版本 · ZCode version
3.1.2.1786
设备 / 系统 / 浏览器 · Device / OS / Browser
Mac (Apple Silicon) / macOS 15.5 (darwin 25.5.0 arm64)
截图 / 录屏 / 日志 · Screenshots / Recordings / Logs
Notes:
- This matches the open VS Code issue https://github.com/microsoft/vscode/issues/251263, and equivalent reports in Cursor (https://forum.cursor.com/t/allow-workspacefolder-in-mcp-project-configration/74861) and Roo Code (https://github.com/RooCodeInc/Roo-Code/issues/4017). Since ZCode already sets the spawned server's
cwdto the workspace, expanding${workspaceFolder}inenvvalues should be straightforward. - Tangentially related to #15 (MCP reload): a reload command would also help users pick up
.mcp.jsonedits, which currently require a full app restart and still don't reliably re-read (observed env values on a post-restart server did not reflect edited.mcp.jsonvalues).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the MCP server spawn path that reads .mcp.json and sets env alongside the already-mentioned workspace cwd; trace how env values are passed to the child process. Define the supported ${workspaceFolder} behavior and cover the reproduction with a focused test; done means the child receives the workspace path rather than the literal token.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100