Model Context Protocol (MCP) relies on a clean, bi-directional JSON-RPC 2.0 transport running over standard input and output (stdio) or Server-Sent Events (SSE).
Because communication occurs through raw pipes, even a minor misconfiguration—such as a single debugging print statement or a missing environment variable—can cause the client to drop the connection immediately.
If you are staring at a red status circle, a Connection closed alert, or an Exit code 1 crash in Cursor, Claude Desktop, or Windsurf, this playbook will help you diagnose the root cause and resolve it in minutes.
flowchart TD
A["MCP Server Crash Detected"] --> B{"Is it Exit Code 1?"}
B -- "Yes" --> C["Check $PATH & Binary Names (npx vs npx.cmd)"]
B -- "No" --> D{"Is it 'Connection Closed'?"}
D -- "Yes" --> E["Check for stdout contamination (console.log)"]
D -- "No" --> F{"Is it JSON Parse Error?"}
F -- "Yes" --> G["Validate mcp.json with JSON linter"]
| Failure Symptom | Most Likely Root Cause | Immediate Fix |
|---|
| Exit Code 1 / Red Dot | Non-login shell cannot locate node, npx, or uvx | Use absolute executable path (/opt/homebrew/bin/npx) |
| Connection Closed | Server printed debug text to stdout instead of stderr | Route all logs to stderr or silence logging |
| spawn ENOENT | Relative binary name executed on Windows without .cmd | Specify npx.cmd on Windows platforms |
| EACCES / Permission Denied | File or SQLite database is locked or lacks read permissions | Run chmod +x or inspect database file ACLs |
| Client Fails on Boot | Trailing comma in mcp.json or unescaped backslashes | Validate JSON syntax with a linter |
In the Model Context Protocol specification, stdout is strictly reserved for JSON-RPC messages.
If a server script contains:
// BROKEN: This destroys the JSON-RPC framing!
console.log("Server initialized successfully on port 8080");
or in Python:
# BROKEN: Prints to stdout by default!
print("Connected to database")
The AI client (Cursor or Claude) attempts to parse "Server initialized successfully..." as a JSON-RPC message, fails with a parse error, and closes the connection immediately.
Redirect all logging strictly to stderr:
// CORRECT (Node.js):
console.error("Debug info: Server initialized");
# CORRECT (Python):
import sys
sys.stderr.write("Debug info: Connected to database
")
Desktop apps (Claude Desktop, Cursor) run as GUI window manager processes. They do not automatically execute ~/.zshrc or ~/.bashrc. As a result, tools like Node, NVM, and Cargo are omitted from $PATH.
Always use absolute paths for the command executable:
{
"mcpServers": {
"sqlite-tools": {
"command": "/Users/username/.cargo/bin/uvx",
"args": ["mcp-server-sqlite", "--db-path", "/absolute/path/data.db"]
}
}
}
On Windows, npx is not an executable binary—it is a shell script wrapper named npx.cmd.
Calling "command": "npx" in Windows Cursor or Claude can trigger an immediate spawn ENOENT crash.
Explicitly specify npx.cmd and escape backslashes on Windows:
{
"mcpServers": {
"github-tools": {
"command": "C:\\Program Files\\nodejs\\npx.cmd",
"args": ["-y", "@modelcontextprotocol/server-github"]
}
}
}
When interacting with local SQLite databases or file trees:
- Ensure the target file has write permissions:
chmod 644 /path/to/database.db.
- Ensure no other IDE process or database management tool holds an exclusive file lock on the SQLite database.
When an MCP server fails, the client logs the raw stderr output in hidden diagnostic logs:
- In Cursor:
- Open Cursor Settings $\rightarrow$ Features $\rightarrow$ MCP.
- Click the server name to expand the diagnostics panel.
- Inspect the live stderr console stream for uncaught exceptions.
- In Claude Desktop:
- macOS:
tail -n 100 -f ~/Library/Logs/Claude/mcp*.log
- Windows:
Get-Content -Path $env:APPDATA\Claude\logs\mcp*.log -Tail 100 -Wait
Debugging raw JSON-RPC pipes manually is tedious.
The open-source AIStoreHub CLI (pip install aistorehub) features built-in verification tools that test your MCP servers before injecting them into your editors:
# 1. Install CLI
pip install aistorehub
# 2. Test server handshake, arguments, and stderr health
aihub mcp test community/postgres-mcp
# 3. Safely install into Cursor, Claude, or Windsurf
aihub mcp install community/postgres-mcp --client cursor
Explore verified MCP servers, community tools, and autonomous agents in the AIStoreHub Registry.