8000 fix(windows): spawn npm/uv shims (npx.cmd) for stdio backends by ozkanerbatuhan · Pull Request #123 · avelino/mcp · GitHub
[go: up one dir, main page]

Skip to content

fix(windows): spawn npm/uv shims (npx.cmd) for stdio backends - #123

Merged
avelino merged 1 commit into
avelino:mainfrom
ozkanerbatuhan:fix/windows-cmd-shims
Nov 9, 2026
Merged

avelino merged 1 commit into
avelino:mainfrom
ozkanerbatuhan:fix/windows-cmd-shims

Conversation

@ozkanerbatuhan
Copy link
Copy Markdown
Contributor

Part of #121 (item 2).

CreateProcess only appends .exe to a bare name, so "command": "npx" failed with program not found although resolve_command had found npx.cmd. New which::program_for_spawn resolves a bare, extensionless name through PATH + PATHEXT and passes the full path to Command::new (std runs .cmd/.bat via cmd.exe with its escaping). PATHEXT matches win over an extensionless file in the same dir (nodejs ships a POSIX npx next to npx.cmd). Applied at the three spawn sites. Unix unchanged.

Tests added for both branches of the helper. This branch also carries the two cfg(unix) test gates from #121 item 1 (identical hunks, merge cleanly) so it tests standalone; on Windows it needs the Cargo.toml fix to build.

Tested live: npx, uvx, npm .cmd CLIs, node, python and a native exe all spawn and list tools through mcp serve --http.

🤖 Generated with Claude Code

On Windows `CreateProcess` only appends `.exe` to a bare program name, so a
backend configured as `"command": "npx"` (or any npm-installed CLI, which is a
`.cmd` shim) failed with "program not found" even though
`resolve_command` had just found it via PATHEXT. Most published MCP servers
are started through `npx`, so the proxy could not run them on Windows.

Add `which::program_for_spawn`: for a bare, extensionless name on Windows,
resolve it through PATH + PATHEXT and hand the full path to `Command::new`
(std runs `.cmd`/`.bat` through cmd.exe with its escaping). A PATHEXT match
wins over an extensionless file in the same directory, because nodejs ships a
POSIX `npx` script next to `npx.cmd`. Used at all three spawn sites (stdio
transport, CLI transport, CLI discovery). No change on unix.

Tests: program_for_spawn keeps explicit paths/extensions; on Windows it picks
`shim.cmd` over a bare `shim` script. Also carries the two `cfg(unix)` test
gates from the Windows build fix so this branch tests standalone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avelino avelino left a comment
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ozkanerbatuhan, this one is clean. Resolving the bare name through PATH + PATHEXT only at spawn time, letting std run .cmd through cmd.exe with its own quoting, and preferring npx.cmd over the POSIX npx that nodejs ships next to it is exactly how I'd want it. Unix stays a no-op, and the live check with npx, uvx and native exes is appreciated.

I read the full diff and merged it locally on top of current main (together with #125): cargo test --all-targets passes, 1138 tests.

The red advisories job on this PR is from Oct 17 and isn't about your change, main has moved since. Could you rebase on main so CI gets a fresh run? I'll merge as soon as it's green.

@avelino
avelino merged commit 1442348 into avelino:main Nov 9, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0