In this categoryTroubleshooting ยท 27
- How to Fix an OpenAI 401 'Invalid API Key' ErrorStart
- How to Fix OpenAI 429 Rate Limit Errors With Backoff
- How to Fix Anthropic Claude API 401 Authentication Errors
- How to Fix Google Gemini 'API Key Not Valid' Errors
- How to Fix an API Key That Loads as Undefined
- How to Handle Anthropic 529 'Overloaded' Errors
- How to Fix Rate Limit Errors from an AI API
- How to Fix CORS Errors When Calling an AI API From the Browser
- How to Fix 'Model Not Found' and Deprecated Model Errors
- How to Rotate a Leaked API Key Without Downtime
- How to Fix SSL Certificate Errors When Calling AI APIs
- How to count tokens before sending a prompt to Claude
- How to Fix 'Context Length Exceeded' Token Limit Errors
- How to fix a context length exceeded error in the Claude API
- How to fix a Claude response that gets cut off mid-sentence
- How to reduce Claude hallucinations by grounding answers in your documents
- How to keep a long Claude conversation under the context limit
- How to stop Claude from calling tools when it should not
- How to handle a Claude Fable 5 refusal with a fallback model
- How to choose the right Claude model for cost and quality
- How to cut Claude API costs with prompt caching
- How to halve Claude costs for bulk jobs with the Batch API
- How to cap spend on a Claude agent with a task budget
- How to Debug an MCP Server That Will Not Connect
- How to Ask an Agent to Explain a Bug Before Fixing It
- How to Roll Back a Bad Deploy Quickly
- How to Fix Cursor Not Indexing Your Codebase
How to Debug an MCP Server That Will Not Connect
Work through the common reasons a Model Context Protocol server shows as failed and get it back to connected.
You added an MCP server, but the status reads failed instead of connected and its tools never appear. The cause is almost always one of a short list: a wrong command, a missing dependency, or a credential the server cannot read. This guide walks the checklist in order.
What you need
- An MCP server already added to your client
- The exact command or URL you used to add it
- About 10 minutes
Step 1: Read the real status
List your servers to see which one failed and capture the error line. The status, not a guess, tells you where to look.
Step 2: Run the server command by hand
Copy the exact command from your config and run it directly in a terminal. If it errors here, the client was never going to start it either. This isolates the problem from the agent.
# the same command your config runs
npx -y @modelcontextprotocol/server-postgres
# a missing binary or import error shows up immediately hereStep 3: Check the credential the server reads
Many servers expect a token or connection string in an environment variable. If it is unset or named wrong, the server starts and then exits. Confirm the variable the server actually reads.
Step 4: Re-add with the fix and re-list
Remove the broken entry, add it again with the corrected command and env, then list once more to confirm it reads connected.
claude mcp remove postgres
claude mcp add postgres \
--env DATABASE_URL=postgres://localhost:5432/app \
-- npx -y @modelcontextprotocol/server-postgresResult: the server reports connected and its tools show up again. The same three checks, command, dependency, credential, cover nearly every failure.
Watch related tutorials
19:27
23:41
14:22
1:42:18
28:14
41:09New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.