Lesson 36.4 · 4 of 5 · 5 min read · Reviewed 24 Nov 2026
Debugging an MCP server that won't connect
By the end, you can
- Debug an MCP server that won't connect.
- Work through command, environment, output and auth in order.
When a server won’t connect, work through the layers in order.
1. Look at the status
In Claude CodeClaude Code: Anthropic’s agentic coding tool that works in your terminal, IDE and CI, reading and editing code and running commands., /mcp lists servers with their state and any error. claude mcp list does the same from the command line.
2. Run it yourself
Copy the server’s command and args and run them in a terminal. Startup errors such as a missing package, a bad path or a missing variable show up straight away.
3. Check the environment
Is every ${VAR} in the config set in the environment Claude Code runs in? A variable set in one terminal tab may not be set in another, or in your editor.
4. Check the output channel
For stdiostdio transport: Running an MCP server as a local process that talks to the client over standard input and output. servers, anything printed to stdout that isn’t protocol data breaks the connection. Move logs to stderr.
5. Check auth
Remote servers may need you to sign in again. Expired OAuthOAuth: A standard for granting an application limited access to a user’s account on another service without sharing their password. tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id. and revoked API keys are common culprits.
6. Use an inspector
The MCPModel Context Protocol (MCP): An open protocol that standardises how AI applications connect to tools, data and prompts through servers. Inspector, an open-source testing tool, lets you connect to a server directly and call its tools by hand. It shows whether the problem is in the server or in the client setup.
Key points
- Check the server's status first (/mcp in Claude Code) and read the error.
- Run the server command yourself in a terminal to see startup errors.
- Common causes: wrong command or path, missing environment variables, logs on stdout, and expired auth.
Debug a broken MCP server in layers
Break a working local MCP server in three common ways and find each fault with /mcp, a terminal and the MCP Inspector.
You will have: A short debugging log: for each fault, the symptom you saw, the layer it was in, and the fix.
Steps
- Start from a working stdio server in .mcp.json and confirm /mcp shows it connected.
- Fault 1: misspell the command or a path in args. Read the error in /mcp, then run the exact command in a terminal to see the real message.
- Fault 2: reference ${DEMO_TOKEN} without setting it. Note the error, then export it in your shell profile and restart the host.
- Fault 3: add a print of a greeting to stdout at start-up. Watch the connection fail, then move it to stderr.
- Run npx @modelcontextprotocol/inspector with the server command, list its tools and call one by hand.
- Write one line per fault in your log: symptom, layer, fix.
Done when
- Each of the three faults was reproduced and fixed.
- The Inspector lists the server's tools and a call succeeds.
- The log names the layer for each fault: command, environment or output channel.
Docs: Connect Claude Code to tools via MCP (Claude Code docs) · MCP Inspector (GitHub)