{"slug": "fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix", "title": "Fix spawn npx ENOENT for MCP servers on Windows (the cmd /c fix)", "summary": "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.", "body_md": "Checked against the official docs: Oct 27, 2026\n\nYou 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.\n\n`\"command\": \"npx\"` to `\"command\": \"cmd\"`.`\"/c\"` and `\"npx\"` at the start of `args`, before the rest of the arguments.\n*Only the command and the first two args change*\n\n```\n// before: fails on Windows in some clients\n{\n  \"command\": \"npx\",\n  \"args\": [\"-y\", \"@modelcontextprotocol/server-memory\"]\n}\n\n// after\n{\n  \"command\": \"cmd\",\n  \"args\": [\"/c\", \"npx\", \"-y\", \"@modelcontextprotocol/server-memory\"]\n}\n```\n\nNot 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.\n\n`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).\n\nYou 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.\n\nThe 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.\n\nEvery 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.\n\nWith 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 `--`:\n\n*Run in PowerShell or Command Prompt*\n\n```\nclaude mcp add memory -- cmd /c npx -y @modelcontextprotocol/server-memory\n```\n\nTo 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:\n\n*Bash or Git Bash quoting. In PowerShell, escape the inner quotes or put the JSON in a .mcp.json file instead*\n\n```\nclaude mcp add-json memory '{\"type\":\"stdio\",\"command\":\"cmd\",\"args\":[\"/c\",\"npx\",\"-y\",\"@modelcontextprotocol/server-memory\"]}'\n```\n\nIn 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`.\n\nA 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.\n\nOpen the config from **Settings**, then **Developer**, then **Edit Config**. The file is `%APPDATA%\\Claude\\claude_desktop_config.json` on Windows.\n\n*%APPDATA%\\Claude\\claude_desktop_config.json*\n\n```\n{\n  \"mcpServers\": {\n    \"memory\": {\n      \"command\": \"cmd\",\n      \"args\": [\"/c\", \"npx\", \"-y\", \"@modelcontextprotocol/server-memory\"]\n    }\n  }\n}\n```\n\nSave the file, then completely quit Claude Desktop and reopen it; the MCP docs say it must restart to load the new configuration.\n\nSame 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.\n\n*~/.cursor/mcp.json*\n\n```\n{\n  \"mcpServers\": {\n    \"memory\": {\n      \"command\": \"cmd\",\n      \"args\": [\"/c\", \"npx\", \"-y\", \"@modelcontextprotocol/server-memory\"]\n    }\n  }\n}\n```\n\nVS 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**.\n\n*.vscode/mcp.json*\n\n```\n{\n  \"servers\": {\n    \"memory\": {\n      \"type\": \"stdio\",\n      \"command\": \"cmd\",\n      \"args\": [\"/c\", \"npx\", \"-y\", \"@modelcontextprotocol/server-memory\"]\n    }\n  }\n}\n```\n\nUpdate 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`:\n\n*~/.codex/config.toml (%USERPROFILE%.codex\\config.toml on Windows)*\n\n```\n[mcp_servers.memory]\ncommand = \"cmd\"\nargs = [\"/c\", \"npx\", \"-y\", \"@modelcontextprotocol/server-memory\"]\n```\n\nOlder 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/).\n\nOpen 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.\n\nRun 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/)).\n\n`${APPDATA}` or npm folder errors (Claude Desktop)\nThe 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).\n\n`.cmd` script at all\nThe 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.\n\nIn 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.\n\nStill 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/).\n\nThe 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.\n\n`cmd /c` for `uvx` or Python servers?\nNot 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.\n\nSince 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.\n\nCommands and config above come from these official docs. Tools change often, so check them for the latest steps.\n\nPluginStack 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).\n\nThis 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.", "url": "https://wpnews.pro/news/fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix", "canonical_source": "https://dev.to/pluginstackai/fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix-5ec4", "published_at": "2026-11-20 19:09:01+00:00", "updated_at": "2026-11-20 19:13:58.002412+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["Claude Code", "Claude Desktop", "Node.js", "Model Context Protocol", "npx", "Anthropic"], "also_reported_by": [], "takeaway": "On Windows, MCP clients that spawn servers without a shell can't resolve `npx` to `npx.cmd` and fail with ENOENT or EINVAL, so set command to `cmd` and start args with `/c`, `npx`.", "recommendation": {"advice": "When a local npx-based MCP server fails to connect on Windows, wrap it as `cmd /c npx ...` in the client config, keeping each argument a separate string.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix", "markdown": "https://wpnews.pro/news/fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix.md", "text": "https://wpnews.pro/news/fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix.txt", "jsonld": "https://wpnews.pro/news/fix-spawn-npx-enoent-for-mcp-servers-on-windows-the-cmd-c-fix.jsonld"}}