Skip to content

Commit ff0f5fb

Browse files
authored
fix: Use cmd /c wrapper for npx on Windows (#279)
* fix: Use cmd /c wrapper for npx on Windows - 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 * fix: Move --inspect-brk flag to NODE_OPTIONS instead of npx args - 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
1 parent c4fc187 commit ff0f5fb

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

setup-claude-server.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -757,23 +757,34 @@ export default async function setup() {
757757
// Debug with npx
758758
logToFile('Setting up debug configuration with npx. The process will pause on start until a debugger connects.');
759759
// Add environment variables to help with debugging
760+
// Inspector flag must be in NODE_OPTIONS, not passed as npx argument
760761
const debugEnv = {
761-
"NODE_OPTIONS": "--trace-warnings --trace-exit",
762+
"NODE_OPTIONS": "--inspect-brk=9229 --trace-warnings --trace-exit",
762763
"DEBUG": "*"
763764
};
764765

765766
const packageSpec = getPackageSpec(versionArg);
766-
serverConfig = {
767-
"command": isWindows ? "node.exe" : "node",
768-
"args": [
769-
"--inspect-brk=9229",
770-
isWindows ?
771-
join(process.env.APPDATA || '', "npm", "npx.cmd").replace(/\\/g, '\\\\') :
772-
"$(which npx)",
773-
packageSpec
774-
],
775-
"env": debugEnv
776-
};
767+
768+
// Windows requires cmd /c wrapper for npx
769+
if (isWindows) {
770+
serverConfig = {
771+
"command": "cmd",
772+
"args": [
773+
"/c",
774+
"npx",
775+
packageSpec
776+
],
777+
"env": debugEnv
778+
};
779+
} else {
780+
serverConfig = {
781+
"command": "npx",
782+
"args": [
783+
packageSpec
784+
],
785+
"env": debugEnv
786+
};
787+
}
777788
await trackEvent('npx_setup_config_debug_npx', { packageSpec });
778789
} else {
779790
// Debug with local installation path
@@ -799,12 +810,27 @@ export default async function setup() {
799810
// Standard configuration without debug
800811
if (isNpx) {
801812
const packageSpec = getPackageSpec(versionArg);
802-
serverConfig = {
803-
"command": isWindows ? "npx.cmd" : "npx",
804-
"args": [
805-
packageSpec
806-
]
807-
};
813+
814+
// Windows requires cmd /c wrapper for npx
815+
if (isWindows) {
816+
serverConfig = {
817+
"command": "cmd",
818+
"args": [
819+
"/c",
820+
"npx",
821+
"-y",
822+
packageSpec
823+
]
824+
};
825+
} else {
826+
serverConfig = {
827+
"command": "npx",
828+
"args": [
829+
"-y",
830+
packageSpec
831+
]
832+
};
833+
}
808834
await trackEvent('npx_setup_config_standard_npx', { packageSpec });
809835
} else {
810836
// For local installation, use absolute path to handle Windows properly

0 commit comments

Comments
 (0)