-
-
Notifications
You must be signed in to change notification settings - Fork 558
fix: Use cmd /c wrapper for npx on Windows #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Windows requires 'cmd /c' wrapper to properly execute npx commands - Changed both debug and standard npx configurations - Fixes 'Cannot read properties of undefined (reading 'cmd')' error - Follows Anthropic's official recommendation for Windows MCP servers - Resolves issues with npx.cmd failing in recent Claude Desktop versions
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
WalkthroughRefactors platform-specific npx execution in setup-claude-server.js, implementing cmd /c wrapper for Windows and direct npx invocation for non-Windows, while adding --inspect-brk=9229 flag for debug mode and -y flag for auto-confirmed installation across both platforms. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
setup-claude-server.js (1)
766-788: Consider adding the-yflag in debug mode for consistency.The standard mode includes
-yto auto-accept npx installation prompts (line 822, 830), but debug mode omits it. While developers in debug mode may want more control, unexpected prompts could interrupt the debugging workflow.Consider adding
-yto debug mode as well for a smoother experience:if (isWindows) { serverConfig = { "command": "cmd", "args": [ "/c", "npx", + "-y", "--inspect-brk=9229", packageSpec ], "env": debugEnv }; } else { serverConfig = { "command": "npx", "args": [ + "-y", "--inspect-brk=9229", packageSpec ], "env": debugEnv }; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
setup-claude-server.js(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
setup-claude-server.js (1)
uninstall-claude-server.js (1)
isWindows(367-367)
🔇 Additional comments (2)
setup-claude-server.js (2)
766-788: Windows wrapper implementation looks correct.The
cmd /cwrapper for npx on Windows is the correct solution to handle npx.cmd batch file execution issues. The platform-specific branching is clear and follows the recommended pattern from Anthropic documentation.
814-834: LGTM! Standard mode configuration is well-implemented.The Windows
cmd /cwrapper and-yflag additions correctly address the PR objectives:
- Fixes Windows npx execution failures with the cmd wrapper
- Prevents installation prompts with the
-yflag- Maintains clean separation between Windows and non-Windows paths
- Inspector flag must be passed via NODE_OPTIONS environment variable - Passing --inspect-brk as npx argument doesn't work with cmd /c wrapper - Fixes debug mode to properly attach debugger on startup - Addresses code review feedback
Additional Fix AppliedFixed the debug inspector flag handling based on code review: Problem: The --inspect-brk=9229 flag was being passed as an npx argument, which doesn't work. Solution: Moved the inspector flag to NODE_OPTIONS environment variable: \\javascript Now the flag is properly passed to Node.js instead of npx, allowing the debugger to attach correctly. Commit: 8f05cd4 |
User description
Problem
On Windows, using
npx.cmdor justnpxdirectly in MCP server configurations has been failing with errors like:Cannot read properties of undefined (reading 'cmd')Root Cause
Windows requires a
cmd /cwrapper to properly execute npx commands because:npx.cmdwithout setting the shell optionSolution
Updated
setup-claude-server.jsto use thecmd /cwrapper pattern for Windows npx installations:Before:
{ "command": "npx.cmd", "args": ["@wonderwhy-er/desktop-commander"] }After:
{ "command": "cmd", "args": ["/c", "npx", "-y", "@wonderwhy-er/desktop-commander"] }Changes
cmd /cwrappercmd /cwrapper-yflag to auto-accept npx prompts in standard modeReferences
Testing
Tested on Windows 11 with:
CodeAnt-AI Description
Wrap Windows npx server launches with cmd /c
What Changed
cmd /c npx --inspect-brk=9229so the debugger-targeted process launches instead of failing to spawn npx directlycmd /c npx -y, aligning with the existing Linux/macOS flow and preventing npx from hanging on promptsImpact
✅ Fewer Windows startup failures✅ Reliable debugger attachment on Windows✅ No manual prompts when launching npx on Windows💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
Bug Fixes
Refactor