fix(cli): quote the cmd.exe command path with real quotes on Windows
On Windows, firecrawl setup mcp and every other setup step that runs npx fail when Node is installed under C:\Program Files\, the default location:
'"C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Error: Failed to configure Firecrawl MCP.
Fixes #188
Cause
runClientCommand() starts .cmd shims through cmd.exe /d /s /c and escapes the program path with escapeCmdArg(), giving ^"C:\Program Files\nodejs\npx.cmd^". That escaping is right for arguments, because cmd.exe strips the carets and the program's C runtime sees the quotes. cmd.exe parses the program path itself. There ^" is a literal character, so cmd.exe splits the path at the first space.
Changes
- Add
quoteCmdCommand()and use it for the program path only. It wraps the path in plain quotes. cmd.exe still expands%VAR%and!VAR!inside quotes, soquoteCmdCommand()moves each%and!outside the quotes and caret-escapes it. Argument escaping is unchanged. - Export
runClientCommandso tests can call it. - Update the mocked win32 test in
setup.test.ts. It asserted the broken^"…^"form, so it passed while the real spawn failed. - Add
setup-windows-spawn.test.ts. It spawns a realcmd.exewith a.cmdshim underProgram Files (x86)and checks that arguments arrive unchanged, including&and${FIRECRAWL_API_KEY}. It also covers paths containing%USERNAME%. - Add a
test-windows-spawnCI job onwindows-latestthat runs that one file on pull requests. The maintestjob runs on Linux and skips those tests. The new job uses the same pinned action SHAs, read-onlycontentspermission andpersist-credentials: falseas the other jobs, and takes the pnpm version frompackageManager.
This differs from the patch suggested in #188, which changed escapeCmdArg for every argument. With unescaped outer quotes cmd.exe stops stripping the carets, so https://x.dev/mcp?a=1&b=2 would arrive as a=1^&b=2. Thanks to @matheusjosedesouzabispo-blip for pointing to escapeCmdArg.
#187 moves runClientCommand to src/utils/run-client-command.ts with the same escapeCmdArg(resolved) line. If #187 merges first, I'll rebase and apply the same change there.
Testing
Windows 11, Node 26, pnpm 10.12.1:
- The 3 new real-spawn tests fail before the fix and pass after.
- End to end, I ran
firecrawl setup mcp --project --agent claude-code -y --keylessin a temporary directory. Published 1.24.4 fails with the error above. This branch printsDone!and writes.mcp.json. - The full suite has the same 28 failures on
mainand on this branch. All 28 are in unrelated tests whose path assumptions don't hold on Windows. This PR adds none.
Linux, Node 22: main has 619 passing. This branch has 619 passing plus 3 skipped win32-only tests. pnpm type-check, pnpm build and Prettier pass.