Fix spawn npx ENOENT for MCP servers on Windows (the cmd /c fix) A developer documented a fix for the `spawn npx ENOENT` error that breaks local MCP servers on Windows: change the client config's command from `npx` to `cmd` and prepend `/c` and `npx` to the args, so the server launches through `cmd.exe`. The issue stems from Windows resolving `npx` to the non-executable `npx.cmd` script, which Node refuses to spawn without a shell since the April 2024 security releases (CVE-2024-27980) return `EINVAL`. The same `cmd /c` pattern applies across Claude Desktop, Claude Code CLI and `.mcp.json` configs, and users reported it in Claude Code issues #3369, #9594 and #68221. Checked against the official docs: Oct 27, 2026 You add a local MCP server that starts with npx , it works on a Mac, and on Windows your AI client reports spawn npx ENOENT or a vague "Connection closed" or "Failed to connect" . This is a well-known Windows quirk, and the usual fix is a three-word change to your config. This guide explains why it happens, gives the exact fix for each client, and lists the other causes to rule out. "command": "npx" to "command": "cmd" . "/c" and "npx" at the start of args , before the rest of the arguments. Only the command and the first two args change // before: fails on Windows in some clients { "command": "npx", "args": "-y", "@modelcontextprotocol/server-memory" } // after { "command": "cmd", "args": "/c", "npx", "-y", "@modelcontextprotocol/server-memory" } Not every client needs this. The official MCP quickstart for Claude Desktop uses plain npx on Windows, and if your server already connects you should leave it alone. Use the wrapper when you see the error. ENOENT means "no such file": the program that started your MCP server could not find the command you gave it. On Windows, npx is not a program npx.exe but a script launcher called npx.cmd . Many MCP clients start servers directly, with no shell in between, and a directly-started process cannot resolve npx to npx.cmd . Node's own documentation says that .bat and .cmd files are not executable on their own without a terminal and can only be run through cmd.exe or by spawning with a shell . You also cannot fix it by pointing at npx.cmd . Since the April 2024 Node.js security releases CVE-2024-27980 , starting a .cmd or .bat file without a shell fails with EINVAL on Node 18.20.2, 20.12.2 and later. So the reliable route is to start cmd.exe yourself, and let it run npx : cmd /c npx ... . /c tells cmd to run the rest as a command and exit. The MCP server READMEs use this pattern for Windows. The official Filesystem server README, for instance, has a Windows config that starts with "command": "cmd" and "/c", "npx" . Users reported the same fix in Claude Code issue 3369, where a native-Windows setup showed MCP error -32000: Connection closed until the config was changed to cmd /c . A reply there said the cmd solutions fix it. Every client uses the same idea: command is cmd , and args begins with /c and npx . Each argument stays a separate string. The server here is the official Memory server https://www.pluginstackai.com/plugins/memory-mcp/ ; swap in your own package and arguments. With the CLI, everything after -- is the command. Keep each word separate do not wrap the whole command in one pair of quotes and keep the -- : Run in PowerShell or Command Prompt claude mcp add memory -- cmd /c npx -y @modelcontextprotocol/server-memory To change an existing entry, remove it first claude mcp remove memory and add it again. Or add it from JSON, which keeps the arguments exactly as you write them: Bash or Git Bash quoting. In PowerShell, escape the inner quotes or put the JSON in a .mcp.json file instead claude mcp add-json memory '{"type":"stdio","command":"cmd","args": "/c","npx","-y","@modelcontextprotocol/server-memory" }' In a project .mcp.json file at the repository root, use the same command and args shape under mcpServers . Check the result with claude mcp get memory , which prints the command Claude Code will run, and claude mcp list . A note on versions: Claude Code's current MCP docs say that executables on your PATH such as npx or uvx work as-is, and do not mention cmd /c . Users on native Windows have reported otherwise in issues 3369, 9594 and 68221 the last one traces it to the EINVAL behaviour above . Some Claude Code versions have printed a warning that a Windows npx server needs the cmd /c wrapper. If plain npx connects for you, you do not need the wrapper. Open the config from Settings , then Developer , then Edit Config . The file is %APPDATA%\Claude\claude desktop config.json on Windows. %APPDATA%\Claude\claude desktop config.json { "mcpServers": { "memory": { "command": "cmd", "args": "/c", "npx", "-y", "@modelcontextprotocol/server-memory" } } } Save the file, then completely quit Claude Desktop and reopen it; the MCP docs say it must restart to load the new configuration. Same shape in ~/.cursor/mcp.json global or .cursor/mcp.json project . More in how to add an MCP server to Cursor https://www.pluginstackai.com/guides/add-mcp-server-to-cursor/ , which also shows this wrapper in its troubleshooting section. ~/.cursor/mcp.json { "mcpServers": { "memory": { "command": "cmd", "args": "/c", "npx", "-y", "@modelcontextprotocol/server-memory" } } } VS Code uses a servers key not mcpServers in .vscode/mcp.json for a workspace, or in your user profile's mcp.json . Open either from the Command Palette with MCP: Open Workspace Folder MCP Configuration or MCP: Open User Configuration . .vscode/mcp.json { "servers": { "memory": { "type": "stdio", "command": "cmd", "args": "/c", "npx", "-y", "@modelcontextprotocol/server-memory" } } } Update Codex first. A fix merged on 16 November 2025 pull request 3828, "resolve Windows MCP server execution for script-based tools" makes Codex resolve script launchers such as npx , pnpm and yarn through the Windows PATHEXT list, so a recent Codex may need no wrapper at all. If you still get the error on a current build, use the same shape in ~/.codex/config.toml : ~/.codex/config.toml %USERPROFILE%.codex\config.toml on Windows mcp servers.memory command = "cmd" args = "/c", "npx", "-y", "@modelcontextprotocol/server-memory" Older Codex versions behaved differently. A 2025 issue on Codex 0.23 2555 reports cmd /c timing out with "request timed out", and another 3385 describes using the full path to npx.cmd together with a larger startup timeout sec . Those are user reports against old releases, so try updating before using them. Full config details are in how to add an MCP server to Codex https://www.pluginstackai.com/guides/add-mcp-server-to-codex-config-toml/ . Open a new Command Prompt and run where node and where npx . If either prints nothing, install Node.js. If they work in your terminal but not in the client, the client was started before Node was on your PATH: quit it fully and reopen it, or sign out and back in. Run the full command yourself, for example cmd /c npx -y @modelcontextprotocol/server-memory . A working MCP server starts and then waits silently for input press Ctrl+C to stop it . If it prints an error and returns to the prompt, fix that error first; the client is only reporting it. Official servers need Node 24 or newer from v2 onward see what changed in v2 https://www.pluginstackai.com/guides/mcp-reference-servers-v2-whats-changed/ . ${APPDATA} or npm folder errors Claude Desktop The MCP docs describe an ENOENT where the server log mentions ${APPDATA} in a path. The fix they give is to add the expanded value to the server's env , for example "APPDATA": "C:\\Users\\you\\AppData\\Roaming\\" , and to make sure npm is installed globally, so that %APPDATA%\npm exists npm install -g npm creates it . .cmd script at all The wrapper is for launchers that are .cmd or .bat scripts, such as npx , npm , pnpm and yarn . A real .exe such as node.exe does not need it. Use an absolute path for your own scripts, since a relative one resolves against whatever folder the client was started from. In JSON, a Windows path needs doubled backslashes, C:\\Users\\you\\projects , or forward slashes. A single backslash makes the file invalid or changes the path. In Codex's TOML file use single-quoted strings, 'C:\Users\you\projects' , which TOML treats literally. Still seeing "Connection closed"? That message covers many causes; work through Fix MCP error -32000 "Connection closed" https://www.pluginstackai.com/guides/fix-mcp-error-32000-connection-closed/ . The cause is specific to launching .cmd scripts from native Windows. Inside WSL you run Linux versions of the tools, where npx is a normal executable. The issue above notes that the same setup worked in WSL2. cmd /c for uvx or Python servers? Not for the same reason. npx , npm , pnpm and yarn are the .cmd launchers. A server started with uvx or python is a different command, so only wrap it if you see an equivalent error. Since the CVE-2024-27980 hardening, Node refuses to start a .cmd file without a shell, and the failure is EINVAL rather than ENOENT . Going through cmd /c avoids the problem. Commands and config above come from these official docs. Tools change often, so check them for the latest steps. PluginStack is independent and not affiliated with or endorsed by the companies mentioned. Spotted something out of date? Email pluginstackai@gmail.com mailto:pluginstackai@gmail.com . This guide was first published on PluginStack https://www.pluginstackai.com/guides/fix-spawn-npx-enoent-windows-mcp/ . Browse the PluginStack directory https://www.pluginstackai.com/ for more hand-checked MCP servers, plugins and setup guides.