Debug MCP server connection issues systematically: first test the server manually in your terminal, then use MCP Inspector to verify the protocol layer, check your host configuration for JSON syntax errors, and finally review server logs for startup failures. Most connection problems come from incorrect paths, missing environment variables, or JSON config typos.
Systematic Debugging of MCP Server Connections
When an MCP server fails to connect, the host typically shows a generic error or simply does not list the server's tools. Without a systematic approach, debugging can feel like guessing. This tutorial provides a step-by-step checklist that isolates the problem layer by layer: is the server binary accessible, does it start correctly, does the protocol handshake succeed, and is the host configuration valid?
Prerequisites
- An MCP server that is failing to connect to your host
- Terminal access on your machine
- Node.js 18+ installed (for MCP Inspector)
- Access to your MCP host's configuration file
Step-by-step guide
Test the server command manually in your terminal
Test the server command manually in your terminal
The first step is to verify that the server binary can actually run. Open your terminal and execute the exact command from your MCP host config. If the server uses npx, run the full npx command. If it uses node or uvx, run that. A working server will output JSON-RPC messages to stdout and wait for input. If you see an error instead, the problem is in the server itself — not the host connection. Common failures include command not found, missing dependencies, or missing environment variables.
1# Copy the exact command from your config and run it2# For npx-based servers:3npx -y @modelcontextprotocol/server-github45# For node-based servers:6node ./dist/index.js78# For Python servers:9uvx mcp-server-git --repository /path/to/repo1011# Set environment variables first if needed:12export API_KEY="your-key"13node ./dist/index.jsExpected result: The server starts and waits for input (you may see a JSON-RPC initialization message), or you see a clear error that points to the cause.
Validate your host configuration JSON
Validate your host configuration JSON
A single misplaced comma or missing quote in your config file will prevent all MCP servers from loading. Copy your entire configuration file content and paste it into a JSON validator (like jsonlint.com or your IDE's built-in JSON validation). Common JSON syntax errors include trailing commas after the last item in an object, missing closing braces, and unescaped backslashes in Windows file paths.
1# Validate JSON from the command line2# macOS/Linux:3cat ~/Library/Application\ Support/Claude/claude_desktop_config.json | python3 -m json.tool45# If it outputs formatted JSON → valid6# If it outputs an error → fix the syntax78# Common issues:9# WRONG: trailing comma10{ "env": { "KEY": "value", } }1112# RIGHT: no trailing comma13{ "env": { "KEY": "value" } }1415# WRONG: unescaped backslash (Windows paths)16{ "args": ["C:\Users\name\server"] }1718# RIGHT: escaped backslash19{ "args": ["C:\\Users\\name\\server"] }Expected result: The JSON validator confirms your config file is valid JSON, or shows you the exact line with the syntax error.
Use MCP Inspector to test the protocol layer
Use MCP Inspector to test the protocol layer
MCP Inspector is an official debugging tool that acts as an MCP client and connects to your server. It shows you the initialization handshake, lists available tools and resources, and lets you execute tool calls interactively. If the Inspector can connect but your host cannot, the problem is in the host configuration. If the Inspector also fails, the problem is in the server itself.
1# Install and run MCP Inspector2npx -y @modelcontextprotocol/inspector34# For stdio servers, it will prompt you for the command5# For HTTP servers, specify the URL:6npx -y @modelcontextprotocol/inspector --transport http --url http://localhost:3000/mcpExpected result: MCP Inspector connects to your server and displays available tools and resources, confirming the server is working at the protocol level.
Check MCP server logs for startup errors
Check MCP server logs for startup errors
MCP hosts capture server stderr output in log files. Claude Desktop on macOS writes logs to ~/Library/Logs/Claude/mcp*.log. On Windows, check %APPDATA%\Claude\logs\. Cursor shows MCP errors in the Output panel (select MCP from the dropdown). These logs often contain the exact error message that explains why the server failed to start.
1# Claude Desktop logs (macOS)2tail -n 50 -F ~/Library/Logs/Claude/mcp*.log34# Claude Desktop logs (Windows — in PowerShell)5Get-Content -Tail 50 -Wait "$env:APPDATA\Claude\logs\mcp.log"67# Cursor — check Output panel8# View → Output → select 'MCP' from dropdownExpected result: You see the server's stderr output including any error messages, stack traces, or configuration warnings.
Verify environment variables are reaching the server
Verify environment variables are reaching the server
If your server starts but fails because of missing API keys, the env block in your config may not be reaching the server process. Add a startup check to your server that logs which environment variables are set (without logging the actual values). This confirms whether the host is injecting the variables correctly. If you have exhausted these debugging steps and still cannot resolve the issue, the RapidDev team has experience debugging complex MCP configurations and can help identify the root cause.
1// Add to your server's entry point for debugging2const requiredVars = ["API_KEY", "DATABASE_URL"];3for (const varName of requiredVars) {4 const isSet = !!process.env[varName];5 console.error(` ${varName}: ${isSet ? "SET" : "MISSING"}`);6}78# Python equivalent9import os, sys10required_vars = ["API_KEY", "DATABASE_URL"]11for var in required_vars:12 is_set = var in os.environ13 print(f" {var}: {'SET' if is_set else 'MISSING'}", file=sys.stderr)Expected result: The server logs show which environment variables are set and which are missing, helping you identify configuration gaps.
Complete working example
1#!/bin/bash2# MCP Server Connection Debugging Checklist3# Run each step to isolate the problem45echo "=== Step 1: Check if server command exists ==="6which node7which npx8which uvx910echo ""11echo "=== Step 2: Validate config JSON ==="12CONFIG="$HOME/Library/Application Support/Claude/claude_desktop_config.json"13if [ -f "$CONFIG" ]; then14 python3 -m json.tool "$CONFIG" > /dev/null 2>&115 if [ $? -eq 0 ]; then16 echo "Config JSON: VALID"17 else18 echo "Config JSON: INVALID — fix syntax errors"19 python3 -m json.tool "$CONFIG"20 fi21else22 echo "Config file not found at: $CONFIG"23fi2425echo ""26echo "=== Step 3: Test server manually ==="27echo "Run your server command here, e.g.:"28echo " npx -y @modelcontextprotocol/server-github"29echo " node ./dist/index.js"30echo " uvx mcp-server-git --repository /path"3132echo ""33echo "=== Step 4: Check recent logs ==="34if ls ~/Library/Logs/Claude/mcp*.log 1> /dev/null 2>&1; then35 echo "Recent MCP log entries:"36 tail -n 20 ~/Library/Logs/Claude/mcp*.log37else38 echo "No MCP log files found"39fi4041echo ""42echo "=== Step 5: Run MCP Inspector ==="43echo "npx -y @modelcontextprotocol/inspector"Common mistakes when debugging MCP server connection issues
Why it's a problem: Skipping the manual terminal test and jumping straight to config changes
How to avoid: Always test the server command in your terminal first. If it does not work there, no host configuration will fix it.
Why it's a problem: Editing the config file while the MCP host is running and expecting changes to apply
How to avoid: After editing the config, restart Claude Desktop completely or reload Cursor's window.
Why it's a problem: Not checking for JSON syntax errors in the config file
How to avoid: Use python3 -m json.tool or an online validator to check the config before restarting.
Why it's a problem: Ignoring the MCP server logs
How to avoid: Server logs contain the actual error messages. Check ~/Library/Logs/Claude/mcp*.log on macOS before making random changes.
Best practices
- Follow the debugging checklist in order: command → config → protocol → logs
- Test server commands in terminal before adding them to host configs
- Validate JSON config files after every edit
- Use MCP Inspector as the definitive protocol-level test
- Add startup validation in your servers that logs which env vars are present
- Keep a tail -f on the log file while restarting the host to catch errors in real time
- Document working configurations so you can revert if something breaks
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
My MCP server is not connecting in [Claude Desktop / Cursor]. The server is [description]. Here is my config: [paste config]. I see this error in the logs: [paste error]. Help me debug the connection issue step by step.
Help me debug my MCP server connection issue. When I run [command] in my terminal, I see [error]. My config file is at [path]. Walk me through the debugging checklist.
Frequently asked questions
My server works in the terminal but not in Claude Desktop. Why?
GUI applications like Claude Desktop do not inherit your shell's PATH or environment variables. Use absolute paths for commands (e.g., /opt/homebrew/bin/npx instead of npx) and set all required environment variables in the config's env block.
How do I know if the problem is the server or the host?
Use MCP Inspector to test independently of the host. If Inspector connects and lists tools, the server is fine and the problem is in the host configuration. If Inspector also fails, the server itself has an issue.
Can I debug MCP servers with a regular debugger?
Yes, for Node.js servers use --inspect flag: node --inspect ./dist/index.js, then connect Chrome DevTools. For Python, use debugpy. Note that breakpoints will pause the MCP protocol, so the host may time out.
Why do all my MCP servers fail at once?
This almost always indicates a JSON syntax error in your config file. A single invalid character breaks the entire config, preventing all servers from loading. Validate the JSON first.
The server connects but no tools appear. What is wrong?
The server is running but either has no tools registered, or the tool registration happens after the initialization handshake. Check your server code to ensure tools are registered before the server starts listening. Also check if there is a tool limit in your host (Cursor has a ~40 tool limit).
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation