Fix MCP Server spawn npx ENOENT and PATH Errors on macOS
Error: spawn npx ENOENT | Error: spawn uvx ENOENT | env: node: No such file or directory | MCP error -32000: Connection closed in Claude Desktop or Cursor MCP logs You paste a verified MCP server config using npx @playwright/mcp@latest or uvx mcp-for-blender into Claude Desktop or Cursor on macOS, and the server immediately shows a red disconnected indicator—even though the exact same command runs cleanly inside your macOS Terminal.
macOS GUI applications launched from Spotlight or the Dock inherit a bare launchd PATH (/usr/bin:/bin:/usr/sbin:/sbin) without reading ~/.zshrc, Homebrew shellenv, nvm, fnm, or Volta shims—so spawning bare npx/uvx throws ENOENT, and even an absolute npx path fails with "env: node: No such file or directory" unless env.PATH includes the Node binary directory.
Copy-Paste Verified Fix
#!/usr/bin/env bash
set -euo pipefail
echo "=== 1. Resolving real local Node / npx / uvx paths ==="
NODE_BIN="$(command -v node || true)"
NPX_BIN="$(command -v npx || true)"
UVX_BIN="$(command -v uvx || true)"
echo "node : ${NODE_BIN:-NOT FOUND} ($([ -n "$NODE_BIN" ] && "$NODE_BIN" -v || echo 'missing'))"
echo "npx : ${NPX_BIN:-NOT FOUND}"
echo "uvx : ${UVX_BIN:-NOT FOUND}"
if [[ -z "$NODE_BIN" || -z "$NPX_BIN" ]]; then
echo "ERROR: Install Node.js 20+ first (brew install node or volta install node@22)."
exit 1
fi
NODE_MAJOR="$("$NODE_BIN" -p 'process.versions.node.split(".")[0]')"
if [[ "$NODE_MAJOR" -lt 20 ]]; then
echo "WARNING: Node v${NODE_MAJOR} detected. Upgrade to Node 20+ for modern MCP servers."
fi
NODE_DIR="$(dirname "$NODE_BIN")"
UVX_DIR="$([ -n "$UVX_BIN" ] && dirname "$UVX_BIN" || echo '/opt/homebrew/bin')"
SAFE_PATH="${NODE_DIR}:${UVX_DIR}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
echo ""
echo "=== 2. Simulating stripped macOS launchd environment ==="
env -i HOME="$HOME" PATH="$SAFE_PATH" "$NPX_BIN" --version >/dev/null && \
echo "PASS: npx + node shebang booted cleanly under stripped launchd env!"
echo ""
echo "=== 3. Copy-paste hardened MCP server block (Claude Desktop / Cursor) ==="
cat <<JSON
{
"mcpServers": {
"playwright": {
"command": "${NPX_BIN}",
"args": ["-y", "@playwright/mcp@latest"],
"env": {
"PATH": "${SAFE_PATH}"
}
}
}
}
JSON
echo ""
echo "=== 4. Tail recent Claude Desktop MCP stderr logs (if present) ==="
ls -t "$HOME/Library/Logs/Claude"/mcp*.log 2>/dev/null | head -n 2 | while read -r logf; do
echo "--- $logf ---"
tail -n 10 "$logf"
done Before vs. After (Broken Pattern vs. Verified Fix)
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
// Fails in Claude Desktop / Cursor: spawn npx ENOENT (or env: node: No such file) {
"mcpServers": {
"playwright": {
"command": "/opt/homebrew/bin/npx",
"args": ["-y", "@playwright/mcp@latest"],
"env": {
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
}
}
}
} Why this works: Using the absolute npx binary eliminates launchd ENOENT, setting env.PATH guarantees the #!/usr/bin/env node shebang resolves to Node 20+, and adding -y suppresses interactive stdout prompts that break JSON-RPC stdio framing.
Why This Failure Happens in Real Pipelines
When you open Terminal.app, iTerm2, or a built-in terminal pane, zsh runs ~/.zprofile and ~/.zshrc—injecting /opt/homebrew/bin (Apple Silicon Homebrew), ~/.nvm/versions/node/v22.x.x/bin, ~/.volta/bin, or ~/.local/bin (Astral uv/uvx) into your interactive PATH. GUI applications like Claude Desktop, Cursor, and VS Code launched from Finder, Dock, or Spotlight are spawned directly by macOS launchd with a locked-down minimal PATH containing only /usr/bin:/bin:/usr/sbin:/sbin. Neither Node.js nor uvx lives in those four system directories.
A subtle secondary failure trips up engineers who only replace "command": "npx" with "command": "/opt/homebrew/bin/npx" (or an nvm path) and stop there. Because npx itself is a Node JavaScript script starting with #!/usr/bin/env node, macOS successfully finds npx and immediately invokes /usr/bin/env to look up node inside the child process’s PATH—which is STILL just /usr/bin:/bin:/usr/sbin:/sbin! The child exits 127 with "env: node: No such file or directory", which the MCP client reports generically as Connection closed (-32000).
Two additional stdio-transport traps frequently masquerade as PATH errors on macOS: running npx without the -y flag causes npm to print an interactive confirmation prompt onto stdout (corrupting the JSON-RPC 2.0 protocol stream), and pointing an nvm path at a default Node 16/18 alias crashes modern MCP servers that require Node 20+ native fetch and ESM APIs. Pinning both the absolute binary path AND an explicit env.PATH containing your Node 20+ bin directory plus /opt/homebrew/bin fixes every macOS GUI MCP host permanently.
Step-by-Step Resolution & Verification
- 01
Inspect real MCP stderr logs before guessing the failure
Open ~/Library/Logs/Claude/mcp-server-<name>.log (Claude Desktop) or View -> Output -> MCP Logs (Cursor) to distinguish spawn npx ENOENT from env: node: No such file or Node version crashes.
- 02
Resolve absolute paths and verify Node 20+ under a stripped environment
Run diagnose-mcp-path.sh to locate your active node, npx, and uvx directories (whether Apple Silicon Homebrew /opt/homebrew/bin, nvm, fnm, or Volta) and confirm env -i PATH=... launches cleanly.
- 03
Update mcp.json with absolute command, -y flag, and explicit env.PATH, then restart
Save the generated block into ~/Library/Application Support/Claude/claude_desktop_config.json or .cursor/mcp.json, completely quit (Cmd+Q) and reopen the app, and confirm a green Connected status.
env -i HOME="$HOME" PATH="$(dirname "$(which node)"):/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin" "$(which npx)" -y @playwright/mcp@latest --version 0.0.x (prints exact package version cleanly with zero ENOENT or "env: node: No such file" errors) How to Prevent This Error From Recurring
Prefer stable paths (Homebrew /opt/homebrew/bin or Volta ~/.volta/bin) over nvm version paths
nvm embeds literal version numbers like v22.14.0 inside paths, so upgrading Node breaks hardcoded MCP configs unless you update mcp.json or use stable symlinks.
Always pass -y to npx inside stdio MCP server args
Without -y, npx may prompt interactively to install an updated package on stdout, immediately corrupting the JSON-RPC handshake between client and server.
Never print shell banners from ~/.zshrc or wrap commands in noisy login shells
Wrapping MCP commands inside zsh -lc can leak oh-my-zsh, neofetch, or nvm stdout banners into the JSON-RPC pipe—explicit absolute paths plus env.PATH stay silent and deterministic.
Troubleshooting FAQs
- Why did fixing command to /opt/homebrew/bin/npx still fail with exit code 127?
- Because npx starts with #!/usr/bin/env node. Without an explicit env.PATH block containing the directory where the node binary lives, env searches only /usr/bin:/bin and fails with "env: node: No such file or directory".
- Does the exact same launchd PATH bug hit uvx for Blender MCP on macOS?
- Yes. Astral uv installs uvx into ~/.local/bin/uvx or /opt/homebrew/bin/uvx, neither of which is in macOS launchd’s default PATH. Pass the full path returned by which uvx along with env.PATH inside your blender-mcp config.
- How do I keep nvm users from breaking mcp.json every time they upgrade Node?
- Create a single stable symlink such as ln -sf "$(which node)" /usr/local/bin/node-mcp (or switch to Volta/Homebrew), or point Claude Code CLI (which inherits your interactive terminal PATH) directly at your active shell.
- Why does Claude Code CLI work when Claude Desktop and Cursor fail on the same Mac?
- Claude Code runs inside your interactive terminal session, which already executed ~/.zshrc and populated PATH with Homebrew, nvm, and uvx. GUI desktop apps skip ~/.zshrc completely.
- Why should I avoid calling bash -lc "npx ..." inside mcp.json?
- Interactive login shells often echo startup messages, nvm switch notices, or prompt themes to stdout. Because stdio MCP servers speak strict JSON-RPC over stdout, any stray non-JSON text immediately kills the connection.