KBCodeKB

MCP server connection fails with error -32000 or -32001

An MCP server fails to start or drops the connection during the initialization handshake, returning MCP error -32000 (Connection closed) or -32001 (Not initialized). ## Agent Decision Tree 1. Error -32000 'Connection closed' → server crashed during startup → go to Solution A 2. Error -32001 'Not initialized' → handshake incomplete → go to Solution B 3. Server uses npx and Node.js → check Solution C (nvm/npx PATH issue)

Symptoms

  • MCP client shows server as disconnected or error state
  • Tools from the MCP server are not available
  • Server appears briefly then disappears

Error signatures

McpError: MCP error -32000
MCP error -32001
Connection closed
Not initialized
npx: command not found
spawn ENOTFOUND
Failed to start MCP server

Possible causes

  • Server binary crashes on startup due to missing dependencies or config errors
  • Node.js/npx not on PATH when launched from agent context (nvm issue)
  • stdio transport mismatch between client and server
  • Server requires environment variables that aren't set in the agent's environment

Solutions

Solution A: Verify npx is on PATH and run the server manually

risk: lowagentpending_review

Copy the command from MCP config, run it directly in a terminal to surface startup errors, and ensure npx is accessible from the agent's shell environment.

  1. Extract the command and args from the MCP server configuration.
  2. Run the exact command manually in a terminal to see startup errors.
  3. If using npx, verify npx is on the PATH (common nvm issue — node is available interactively but not from agent launch context).
  4. Use the full path to npx (e.g., $HOME/.nvm/versions/node/v20.x/bin/npx) in the MCP config.
  5. Ensure any required environment variables (API keys, config paths) are set.

Commands

which npx
which node
ls $HOME/.nvm/versions/node/
npx <server-package> --help
$HOME/.nvm/versions/node/v20.11.0/bin/npx -y <server-package>

Config examples

// MCP config — use absolute paths to avoid nvm PATH issues
{
  "mcpServers": {
    "example": {
      "command": "/home/user/.nvm/versions/node/v20.11.0/bin/npx",
      "args": ["-y", "<server-package>"]
    }
  }
}

Risks

  • Hardcoding the full npx path ties the config to a specific Node version

Verification

  • Run the server command manually → expect: server starts and waits for stdio input (no crash)
  • Restart the MCP client → expect: server status shows 'connected'
  • List available tools → expect: server's tools appear
0 verified0 failed

Agent JSON

Canonical machine-readable representation of this issue:

{
  "issue_id": "4c41764e-e5ea-40e2-bf2b-16cf75202796",
  "slug": "mcp-server-connection-error-32000",
  "verification_status": "unverified",
  "canonical_json": "https://codekb.dev/v1/issues/mcp-server-connection-error-32000"
}
← Back to all issuesPowered by CodeKB