Skip to content

fix(desktop): resolve Windows npx stdio MCP via node and fnm - #1012

Closed
zhao624 wants to merge 1 commit into
vastsa:mainfrom
zhao624:fix/mcp-stdio-windows-npx
Closed

zhao624 wants to merge 1 commit into
vastsa:mainfrom
zhao624:fix/mcp-stdio-windows-npx

Conversation

@zhao624

@zhao624 zhao624 commented Sep 24, 2026

Copy link
Copy Markdown

Summary

Windows stdio MCP with command: "npx" fails even when Node is installed: spawn({ shell: false }) cannot start npx.cmd (ENOENT / EINVAL). GUI PATH also often omits fnm.

Electron main now resolves bare npx / uvx before spawn:

  • PATH node.exe first, then fnm / nvm-windows / Volta
  • Prefer node.exe + npx-cli.js (no cmd.exe)
  • Remaining .cmd shims go through cmd.exe /d /s /c with quoted literal args
  • MCP editor exposes npx / uvx presets so users do not have to paste an absolute path

Test plan

  • node --test apps/desktop/test/mcp-stdio-launch.test.mjs apps/desktop/test/plugin-mcp.test.mjs apps/desktop/test/plugin-child-env.test.mjs apps/desktop/test/user-mcp.test.mjs (72 pass after rebase)
  • pnpm --filter @pi-desktop/desktop typecheck
  • i18n catalog + renderer-keys
  • Windows: official Node Memory MCP (npx -y @modelcontextprotocol/server-memory) Test connection
  • Windows: fnm-managed Node with fnm default set, same market install

fixes #789

GUI-launched Electron still uses spawn({ shell: false }). On Windows the
official npm entry is npx.cmd (ENOENT for bare npx, EINVAL for the
shim), and fnm is often absent from the GUI PATH. Resolve npx/uvx to a
real PE binary (PATH node, then fnm/nvm/Volta) or wrap remaining .cmd
files with quoted cmd.exe so market servers can start.

fixes vastsa#789
@vastsa vastsa closed this Sep 24, 2026
hui455 pushed a commit to hui455/PI-Desktop that referenced this pull request Sep 24, 2026
Cherry-pick PR vastsa#1012 with security fixes:

- quoteWindowsCmdArg: escape % as %% so cmd.exe does not expand env vars
- wrapCmdShim: wrap the /s /c line in outer quotes so paths with spaces
  survive cmd.exe's first/last quote stripping (prevents injection)
- defaultFs.isFile: return false on statSync error instead of existsSync
  which could match directories
- Remove bun/bunx from NODE_LAUNCHERS (dead path: bun has its own
  install location unrelated to node)

fixes vastsa#789
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.

[Bug] Windows 下 npx 类型 MCP 无法启动,错误提示 command not found,但 npx 已安装且位于 PATH

2 participants