[BUG] MCP servers on Windows fail to start when the executable path contains a space or &
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 56/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- github, node.js, typescript
調査の方向性
Start with src/services/mcp/McpHub.ts around lines 752–762 and the Windows command wrapping suite in src/services/mcp/__tests__/McpHub.spec.ts around line 2520. Reproduce the failure with a spaced executable path plus a spaced argument, then check how wrapped commands are passed to StdioClientTransport and how cross-spawn escapes them. Done means Windows tests cover spaced .exe paths and wrapped shims, and the generated arguments successfully start a server.
索引モデルが issue の本文から書いたものです。
説明
On Windows, Zoo Code launches every stdio MCP server through a cmd.exe /c wrapper. When the executable path contains a space and an argument also contains a space, or the path contains a cmd metacharacter (&), cmd.exe mis-splits the command line and tries to launch C:\Program instead of the real executable. The server dies at startup; the MCP panel shows only the cmd error ("…is not recognized").
Am I affected?
You are affected when all of the following hold on your Windows machine:
- The server is a
stdioMCP server inmcp_settings.json(global or project). commandis an absolute path (e.g.C:\Program Files\nodejs\node.exe, a tool installed underC:\Users\John Doe\…), and at least one of these triggers is present:- the path contains a space and any entry in
argsalso contains a space — very common in practice (a filesystem-server root, a${workspaceFolder}path, or a config file under a profile folder with a space in the user name); or - the path contains a cmd metacharacter such as
&, with no space required.
- the path contains a space and any entry in
You are not affected (works by accident) when the executable path has a space, no cmd metacharacter, and every argument is space-free: cmd.exe keeps a lone pair of quotes. You are also unaffected on Linux/macOS, where no wrapper is applied.
Quoting the command yourself in the config ("command": "\"C:\\Program Files\\…\\server.exe\"") does not help — the wrapper does not recognize it and the quotes survive to cmd.exe as literals.
Reproduction
The wrapper behavior can be reproduced without Zoo Code using plain Node — this is what StdioClientTransport effectively executes after McpHub wraps the command:
const { spawn } = require("child_process")
const exe = "C:\\Program Files\\nodejs\\node.exe" // any exe in a spaced dir
// A) exe with space, simple args -> works
spawn("cmd.exe", ["/c", exe, "--version"]) // prints the version
// B) exe with space + one arg that contains a space -> fails
spawn("cmd.exe", ["/c", exe, "-e", "console.log('hi')", "C:\\Users\\John Doe\\x.txt"])
// stderr: 'C:\Program' is not recognized as an internal or external command
// C) exe in a path containing a space and '&' -> fails
spawn("cmd.exe", ["/c", "C:\\Users\\John Doe\\Temp\\MCP & tools\\node.exe", "--version"])
// stderr: 'C:\Users\John' is not recognized as an internal or external command
Observed on Windows 11 with Node v24.19.0 (all three cases verified on a real machine). Inside Zoo Code the effect is identical: the connection goes disconnected and the error text is appended to the server entry.
Root cause
McpHub.connectToServer wraps every stdio command on Windows (src/services/mcp/McpHub.ts, lines 752–762):
const command = isWindows && !isAlreadyWrapped ? "cmd.exe" : configInjected.command
const args =
isWindows && !isAlreadyWrapped
? ["/c", configInjected.command, ...(configInjected.args || [])]
: configInjected.args
The command path is passed unquoted. The MCP SDK's StdioClientTransport then spawns through cross-spawn with shell: false; because the command is already cmd.exe, cross-spawn's cmd-escaping path (which would build a single escaped /d /s /c "<command line>" token) is skipped, and Node's plain argument quoting applies.
That combination collides with cmd.exe /c's documented quote rules: cmd strips the first and last quote of the rest of the command line when the first character is a quote and any disqualifying condition holds (a second quoted token, or a special character like & between the quotes). After stripping, the path is re-split at the first space and cmd tries to execute C:\Program.
The wrapper itself was added for a different problem (PowerShell shims like npx.ps1 from node version managers, see upstream Roo Code issue #1246), so it cannot simply be removed.
Why the tests miss it
The Windows command wrapping suite in src/services/mcp/__tests__/McpHub.spec.ts (line 2520) asserts on the cmd.exe//c shape of the transport arguments, but every fixture uses space-free arguments — the failure mode needs a second spaced token and is never constructed.
Possible fix
Fix direction (sketch, not a decided design): stop wrapping .exe/.com commands — spawning them directly handles spaces — and where the cmd.exe wrapper is still needed (.ps1/.cmd shims), reuse cross-spawn's own escaping instead of the raw /c join. Four steps, each with its done-criterion:
- In
src/services/mcp/McpHub.ts:752-762, classify the command withcross-spawn's executable regex/\.(?:com|exe)$/i, applied to the raw command string (McpHubhas no resolver to test a resolved file the waycross-spawndoes atparse.js:36), and pass matching commands through without the wrapper:cross-spawnspawns such files via directCreateProcess, which handles spaces in the path and in arguments without any shell quoting. Done when a config with a spaced.execommand and one spaced argument (the scenario repro case B models) produces transport arguments containing nocmd.exe, and a spaced&path (case C) connects too. - Every command that does not match that regex (extensionless shims like
npx,.ps1and.cmdpaths) keeps thecmd.exewrapper — this is the scenario the wrapper was added for (upstream #1246). Done when every extensionless/.ps1/.cmdfixture still routes through the wrapper. - For the wrapped branch, escape before joining, mirroring
cross-spawn'sparseNonShell(lib/parse.js:45-59):escape.command(command)plusescape.argument(arg, needsDoubleEscapeMetaChars)per argument — the second parameter is true only fornode_modules\…\.bin\…cmdshims — joined with spaces into one string, then wrapped in literal double quotes and passed as the single tokenargs = ["/d", "/s", "/c", '"<inner>"'](the exact shape ofparse.js:57). Take the helpers fromcross-spawn/lib/util/escapeand addcross-spawnas a direct dependency insrc/package.json(today it is transitive via the SDK only). One open question decides the final form: the single quoted token must survive Node's own argument quoting, andStdioClientTransport— unlikecross-spawn, which sets it in this path (parse.js:59) — never setswindowsVerbatimArguments: true. Probespawn("cmd.exe", ["/d", "/s", "/c", '"<spaced line>"'])on Windows first; if the probe is red, subclass the transport to inject that option. Done when the probe passes in one of the two forms and the choice is recorded in the PR description. - Fix the tests: both existing
npxwrapping tests (starting at lines 2543 and 2733) assert the old shape twice each —config.command/config.argsinside themockImplementation(2557, 2760–2761) and the outertoHaveBeenCalledWith(2600, 2805) — and must be updated to the escaped shape. Then extend theWindows command wrappingsuite (src/services/mcp/__tests__/McpHub.spec.ts:2520) with: spaced.exepath + one spaced argument, spaced path containing&, and a user-quotedcommand; assert the exactStdioClientTransportconstructor arguments, and prove at least one case end-to-end by spawning the produced arguments with realcmd.exeand asserting observable stdout (e.g.node --version). Done when the updated and new tests pass on the fix and turn red on the current wrapping.
Environment
- Zoo Code Version: 3.94.0 (ee65d211)
- Windows 11, Node v24.19.0 (reproduction);
@modelcontextprotocol/sdk1.32.0,cross-spawn7.0.6 (transitive via the SDK) - Not a duplicate of #349: that report's failing config used no spaced paths at all, and its closure (PR #632) touched test ordering/mocking in
McpHub.spec.ts— never the wrapper inMcpHub.ts
- 主要言語
- TypeScript
- スター
- 2k
- フォーク
- 301
- 平均マージ
- 3日 14時間
- マージ済み PR(30日)
- 103
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Zoo-Code-Org/Zoo-Code のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Zoo-Code-Org/Zoo-Code#2773 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Zoo-Code-Org/Zoo-Code#2717 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
Zoo-Code-Org/Zoo-Code#2515 ·
メンテナーはふだん 3 日以内に返信
-
fix(scripts): stryker-diff.mjs spawns the extensionless .bin shim and cannot run on Windows対応中かも @easonLiangWorldedtech が 15 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Zoo-Code-Org/Zoo-Code#2514 ·
メンテナーはふだん 3 日以内に返信
-
[BUG] search_files hides matching text on long lines対応中かも @DananjayaNadun が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
Zoo-Code-Org/Zoo-Code#2496 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
Zoo-Code-Org/Zoo-Code の issue をすべて見る
似ている issue
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
EPPIcenter/sampledb3#162 ·
-
Particle-1 modelオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
tashfeenahmed/freellmapi#2169 ·
メンテナーはふだん 1 日以内に返信
-
via-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
🎙️ task - feat(mechanic): pave git.pull.close, a close of a superseded pull with its why on recordオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ehmpathy/rhachet-roles-ehmpathy#1576 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
vercel-labs/ui#1563 ·
メンテナーはふだん 1 日以内に返信