Skip to content

Conversation

@wonderwhy-er
Copy link
Owner

@wonderwhy-er wonderwhy-er commented Nov 15, 2025

User description

Problem

On Windows, using npx.cmd or just npx directly in MCP server configurations has been failing with errors like:

  • Cannot read properties of undefined (reading 'cmd')
  • Connection failures when Claude Desktop tries to start the server

Root Cause

Windows requires a cmd /c wrapper to properly execute npx commands because:

  • Node.js has difficulties spawning batch files like npx.cmd without setting the shell option
  • npx is a script, not a traditional binary executable
  • This is the officially recommended approach by Anthropic

Solution

Updated setup-claude-server.js to use the cmd /c wrapper 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

  • ✅ Updated debug npx configuration to use cmd /c wrapper
  • ✅ Updated standard npx configuration to use cmd /c wrapper
  • ✅ Added -y flag to auto-accept npx prompts in standard mode
  • ✅ Maintains compatibility with macOS/Linux (unchanged)

References

Testing

Tested on Windows 11 with:

  • Claude Desktop latest version
  • Node.js v22.17.1
  • Both npx and local installation modes

CodeAnt-AI Description

Wrap Windows npx server launches with cmd /c

What Changed

  • Windows debug mode now starts via cmd /c npx --inspect-brk=9229 so the debugger-targeted process launches instead of failing to spawn npx directly
  • Windows standard mode now runs cmd /c npx -y, aligning with the existing Linux/macOS flow and preventing npx from hanging on prompts

Impact

✅ 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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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

    • Improved Windows handling for starting the server, ensuring debug/instrumentation flags work reliably.
    • Uniform application of environment settings across platforms.
  • Refactor

    • Standardized invocation paths so installation/start commands behave consistently on Windows and non-Windows.
    • Added automatic confirmation for command-line installs and clarified debug vs. normal start flows.

- 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
Copy link
Contributor

codeant-ai bot commented Nov 15, 2025

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 ·
Reddit ·
LinkedIn

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2025

Walkthrough

Refactors 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

Cohort / File(s) Summary
Cross-platform npx execution refactor
setup-claude-server.js
Replaces platform-specific command construction with explicit Windows (cmd /c wrapper) and non-Windows (direct npx) code paths; adds --inspect-brk=9229 for debug mode and -y flag for package auto-confirmation in both standard and debug modes

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify Windows cmd /c wrapper syntax and argument ordering
  • Confirm debug mode --inspect-brk flag placement and port value (9229)
  • Check -y flag behavior for package auto-confirmation on both platforms
  • Test cross-platform compatibility paths

Possibly related PRs

  • DesktopCommanderMCP#93: Modifies the same file with overlapping changes to server configuration and npx launch logic in debug and standard modes.

Suggested labels

size:S

Suggested reviewers

  • serg33v

Poem

🐰 A rabbit hops through Windows and Unix with glee,
cmd /c and npx dancing in harmony,
With --inspect-brk to debug the way,
And -y flags confirming, hip-hip-hooray!
Cross-platform paths aligned at last,
The server setup's running fast!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change—fixing Windows npx execution via cmd /c wrapper, which is the primary objective and code modification in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/windows-npx-cmd-wrapper

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeant-ai codeant-ai bot added the size:M This PR changes 30-99 lines, ignoring generated files label Nov 15, 2025
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Nov 15, 2025

CodeAnt AI finished reviewing your PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 -y flag in debug mode for consistency.

The standard mode includes -y to 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 -y to 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

📥 Commits

Reviewing files that changed from the base of the PR and between c4fc187 and bf14fd4.

📒 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 /c wrapper 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 /c wrapper and -y flag additions correctly address the PR objectives:

  • Fixes Windows npx execution failures with the cmd wrapper
  • Prevents installation prompts with the -y flag
  • 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
@wonderwhy-er
Copy link
Owner Author

Additional Fix Applied

Fixed 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
const debugEnv = {
'NODE_OPTIONS': '--inspect-brk=9229 --trace-warnings --trace-exit',
'DEBUG': '*'
};
\\

Now the flag is properly passed to Node.js instead of npx, allowing the debugger to attach correctly.

Commit: 8f05cd4

@wonderwhy-er wonderwhy-er merged commit ff0f5fb into main Nov 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants