zai-org / zai-org/feedback

[Bug] `.mcp.json` env values pass `${workspaceFolder}` through literally (no expansion)

Open
#24 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
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.json env.)
  • 我已阅读 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
  1. 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}" }
        }
      }
    }
    
  2. Start the MCP server (open the workspace / trigger the server).
  3. 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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.