Skip to content

fix: Windows support (npx spawn, absolute paths, array options)#18

Open
danscMax wants to merge 1 commit into
nikhaldi:mainfrom
danscMax:fix/windows-support
Open

fix: Windows support (npx spawn, absolute paths, array options)#18
danscMax wants to merge 1 commit into
nikhaldi:mainfrom
danscMax:fix/windows-support

Conversation

@danscMax
Copy link
Copy Markdown

Fixes the MCP server on Windows. Closes #17.

Three independent platform bugs (details in #17):

  1. spawn npx ENOENT — added resolveNpx(): on Windows it invokes npm's npx-cli.js with the current node binary (no shell, no .cmd, argv passed verbatim → no quoting/injection issues), falling back to npx.cmd + shell: true if the CLI script isn't found. Non-Windows behaviour is unchanged.
  2. Empty report on absolute paths — added normalizeScanPath() (\/, Windows-only), applied to the positional scan path so fast-glob can match it.
  3. Array options droppedbuildArgs now joins array values into a single comma-separated flag (jscpd's expected form) instead of repeating the flag.

servers/jscpd.js is regenerated via npm run build.

Verification (Windows 11, Node 24)

  • spawn npx ENOENT is gone — a real scan returns status: ok.
  • An absolute path containing a space now scans (previously an empty report).
  • Array ignore now honours every pattern (a vendored directory is correctly excluded: 696 → 242 clones).
  • npm run build and the existing test/server.test.js smoke test pass.

Note

npm test as-is matches 0 files on Windows (its glob 'test/**/*.test.js'; a separate pre-existing issue), so I ran test/server.test.js explicitly.

Three platform bugs prevented the MCP server from running on Windows:

1. `spawn npx ENOENT` — runJscpd called execFile("npx", …). On Windows npx
   is a `.cmd` shim that execFile can't resolve, and execFile("npx.cmd", …)
   throws EINVAL on patched Node (CVE-2024-27980). Add resolveNpx(): on
   Windows invoke npm's npx-cli.js with the current `node` binary (no shell,
   no `.cmd`, argv passed verbatim), with a `npx.cmd` + shell fallback. Other
   platforms keep the plain `npx` call.

2. Empty report on absolute scan paths — jscpd globs the path with fast-glob,
   which treats `\` as an escape on every platform, so a Windows absolute path
   (e.g. `E:\proj\src`) matches nothing. Add normalizeScanPath() (Windows:
   `\`→`/`) and apply it to the positional path in jscpd.js.

3. Array options silently dropped — buildArgs expanded array values (e.g.
   `ignore`) into repeated `--flag` entries, but jscpd keeps only the last
   occurrence, so all but one ignore pattern were dropped. Join array values
   into a single comma-separated flag instead.

servers/jscpd.js regenerated via `npm run build`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nikhaldi
Copy link
Copy Markdown
Owner

nikhaldi commented Jun 1, 2026

Thanks so much for submitting a fix! The array options bug was indeed quite bad, good catch. The tests are failing on that part of your change and I also wanted to merge a fix immediately, so I went ahead and merged that as a separate PR (#19).

Your Windows fixes look good, I would like to merge them. I don't have access to a Windows machine right now, so can't truly verify them though. Do you think you could rebase this PR and make sure the tests pass? I also just added Windows runs to CI btw, so hopefully going forward we can maintain better Windows compatibility.

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.

MCP server is broken on Windows: spawn npx ENOENT (+ empty reports on absolute paths, dropped array options)

2 participants