When claude mcp list shows ✘ Failed to connect next to a server, Claude Code tried to start or reach that server and gave up. The docs are clear that this is about the server, not the command: "A failure status means Claude Code couldn't connect to that server, not that the list command failed." The useful part is what comes after the status. Claude Code appends a short detail, such as ENOENT, CONNECTION_CLOSED, ECONNREFUSED or a timeout, and that detail tells you which of a handful of causes you are looking at. This post maps each detail to its cause and fix.
Every case below was run with Claude Code 2.1.334 on Linux, against small Python servers built with the official MCP Python SDK (version 2.3.0), in a throwaway config directory set with CLAUDE_CONFIG_DIR. Paths in the output are shortened. Claude Code prints a dash between the status and the detail; it is shown here as a colon, and our terminal drew the status symbols as √ and × rather than the ✔ and ✘ in the docs.
Read the detail first
The docs describe where the detail shows up: "When a server's status is ✘ Failed to connect, claude mcp list appends the failure detail to that status line, and claude mcp get <name> shows it on an Issue: line. The detail is the HTTP status or error code, plus any error text the server returned."
Here is one claude mcp list run with five servers, each broken in a different way except the first:
good: ~/weather/.venv/bin/python ~/weather/server.py - √ Connected
typo: ~/weather/.venv/bin/pythn ~/weather/server.py - × Failed to connect: ENOENT: no such file or directory, posix_spawn '~/weather/.venv/bin/pythn'
nokey: ~/weather/.venv/bin/python ~/weather/server.py - × Failed to connect: CONNECTION_CLOSED: Connection closed
deadhttp: http://127.0.0.1:9/mcp (HTTP) - × Failed to connect: ECONNREFUSED: Unable to connect. Is the computer able to access the url?
slow: ~/weather/.venv/bin/python ~/weather/slow.py - × Failed to connect: MCP server "slow" connection timed out after 3000ms
claude mcp get shows the same thing in a block that also lists the scope, command, arguments and environment, which is often where the mistake is visible:
nokey:
Scope: Local config (private to you in this project)
Status: × Failed to connect
Issue: CONNECTION_CLOSED: Connection closed
Type: stdio
Command: ~/weather/.venv/bin/python
Args: ~/weather/server.py
Environment:
REQUIRE_KEY=1
Inside a session, /mcp shows the same information. The docs say its detail view "includes the same server-reported text in its Issue: row."
ENOENT: the command doesn't exist
ENOENT: no such file or directory, posix_spawn '...' means Claude Code could not find the program in command. In the test it was a typo (pythn), but the same detail appears for a virtual environment that was deleted or a tool that isn't installed. The detail names the exact path it tried, so compare it with what is on disk:
ls -l ~/weather/.venv/bin/python
which npx uvx node
Fix: correct the path, or use the absolute path that which prints. The debug guide's table says absolute paths are needed for local scripts, while "Executables on your PATH like npx or uvx work as-is." The Claude Desktop version of this problem, spawn npx ENOENT, is covered in MCP server not showing up in Claude Desktop.
CONNECTION_CLOSED: the server started, then exited
CONNECTION_CLOSED: Connection closed means the program ran but the process ended before the handshake finished. Claude Code does not show the server's own error message here. The test server exits on purpose when a key is missing:
import os, sys
from mcp.server import MCPServer
if os.environ.get("REQUIRE_KEY") and not os.environ.get("WEATHER_API_KEY"):
sys.exit("WEATHER_API_KEY is not set")
mcp = MCPServer("weather")
claude mcp list reported only CONNECTION_CLOSED. Running the same command by hand showed the reason at once:
REQUIRE_KEY=1 ~/weather/.venv/bin/python ~/weather/server.py < /dev/null
# WEATHER_API_KEY is not set
So copy the Command, Args and Environment from claude mcp get and run them yourself, from a different directory. For a server that only fails inside a session, the debug guide points to claude --debug=mcp and says to "read the server's stderr in the debug log at ~/.claude/debug/<session-id>.txt." The common reasons a stdio server exits at startup (a failed import, the wrong Python, a missing mcp.run()) are reproduced one by one in MCP error -32000: Connection closed.
Two causes are specific to how Claude Code launches servers.
Relative paths
A server added with its script as a relative path, server.py, connected when Claude Code ran in the project folder. The same server added at user scope and checked from another folder reported CONNECTION_CLOSED, because server.py didn't exist relative to where Claude Code was started. The debug guide says relative paths in command or args "resolve against the directory you launched Claude Code from rather than the location of .mcp.json."
Fix: use absolute paths. For a project .mcp.json that teammates share, the MCP docs say Claude Code sets CLAUDE_PROJECT_DIR in the server's environment, but since it is not in Claude Code's own environment, using it in command or args needs a default, such as ${CLAUDE_PROJECT_DIR:-.}.
Environment variables
Claude Code passes its own environment to stdio servers. With WEATHER_API_KEY exported in the shell, the nokey server above connected. The debug guide describes that environment as Claude Code's own "minus the variables it strips from subprocesses." Other MCP clients may pass less, so a server that works in Claude Code is not proof that its setup is complete.
It also means the server's setup depends on how you launched Claude Code. Two ways to lose a variable:
- You start Claude Code from an app launcher or a fresh terminal that never loaded the variable.
- Someone sets
CLAUDE_CODE_MCP_ALLOWLIST_ENV=1, which the environment variable reference says spawns stdio servers "with only a safe baseline environment plus the server's configuredenv, instead of inheriting your shell environment." With it set, the same server with the key in the shell went back toCONNECTION_CLOSED.
Fix: put what the server needs in its own env config. The debug guide recommends per-server env because it "doesn't depend on the launch environment or workspace trust." From the command line:
claude mcp add --env WEATHER_API_KEY=YOUR_KEY --transport stdio weather \
-- /home/me/weather/.venv/bin/python /home/me/weather/server.py
Keep --transport stdio (or another option) between --env and the name. When we put the name right after --env, the command failed with Invalid environment variable format: envfirst, environment variables should be added as: -e KEY1=value1 -e KEY2=value2. The docs explain that --env takes several pairs and reads the name as one more. Also keep -- before the server's command; the docs say "Everything after -- is passed to the server untouched."
The ${VAR} trap in .mcp.json
A shared .mcp.json usually references secrets as variables, which Claude Code expands with ${VAR} or ${VAR:-default}. When the variable is unset, the docs say the config still loads, Claude Code warns, and it "uses the unexpanded ${VAR} text as-is."
We tested that with this entry and WEATHER_API_KEY unset:
{
"mcpServers": {
"shared": {
"command": "/home/me/weather/.venv/bin/python",
"args": ["/home/me/weather/server.py"],
"env": { "REQUIRE_KEY": "1", "WEATHER_API_KEY": "${WEATHER_API_KEY}" }
}
}
}
claude mcp list printed a warning below the server list:
[Has warnings] Project config (shared via .mcp.json)
└ [Warning] [shared] mcpServers.shared: Missing environment variables: WEATHER_API_KEY
And the server showed Connected. Its startup check passed, because the variable held the literal string ${WEATHER_API_KEY}. A real server would connect fine and then fail on its first API call with an auth error. If a server connects but its tools fail with authentication errors, look for this warning before you look at the API.
Timed out: the server is slow to start
MCP server "slow" connection timed out after 3000ms came from a test server that sleeps eight seconds before starting, run with MCP_TIMEOUT=3000. With no MCP_TIMEOUT, the same server connected. The environment variable reference gives the default as 30000 milliseconds, or 30 seconds, for "MCP server startup."
Fix: time the command by hand (time before the command from claude mcp get, then Ctrl+C once it is waiting for input) to see how long startup really takes. If a launcher such as npx is the slow part, install the server and point command at the installed program. Otherwise raise the limit for the session with MCP_TIMEOUT=60000 claude. MCP_TIMEOUT is only about startup; tool calls have their own MCP_TOOL_TIMEOUT and per-server timeout setting.
HTTP servers: ECONNREFUSED and wrong paths
For a remote or local HTTP server, the detail says what the network said.
ECONNREFUSED: Unable to connect. Is the computer able to access the url?means nothing is listening at that host and port. Start the server, or check the port.- With a local server running at
http://127.0.0.1:8000/mcp, a config pointing at/sseinstead gaveMCP endpoint not found at http://127.0.0.1:8000. Check the URL in your MCP config.The fix is the exact endpoint path from the server's docs.
The docs note that Claude Code redacts credential-like text from this detail and "never includes the expanded server URL," which is why the message shows only the origin. A server that wants OAuth shows ! Needs authentication instead of a failure; sign in from /mcp.
Not a failure: Pending approval
A server in a project's .mcp.json that you haven't approved shows ⏸ Pending approval (run `claude` to approve), and Claude Code doesn't try to connect. That matched our test exactly. The docs say approvals committed to the repository's .claude/settings.json are ignored until you trust the folder, so a cloned repo "can't approve its own servers." Run claude in the folder and approve it. If you dismissed the prompt earlier, the debug guide says to run claude mcp reset-project-choices and restart Claude Code.
Two config mistakes keep a project server from appearing at all, per the same guide: putting the file under .claude/ instead of the repository root, and using a top-level servers key, as VS Code's mcp.json does, instead of mcpServers.
After the fix: reconnect
claude mcp list checks every server again each time you run it. A running session does not retry a failed stdio server on its own. The docs say a stdio server that fails its first connection is marked failed, and to start it again you "select Reconnect from the server's menu in /mcp." Since Claude Code 2.1.284, /mcp reconnect all retries every server that failed or needs authentication.
Checklist
- Run
claude mcp listand read the text afterFailed to connect. ENOENT: the command path is wrong or the program isn't installed.CONNECTION_CLOSED: run the command fromclaude mcp getby hand and read its error.- Use absolute paths for scripts and interpreters.
- Put API keys in the server's
env, not only in your shell. - Watch for
Missing environment variableswarnings on.mcp.jsonservers. - Timeouts: install the server instead of fetching it at launch, or raise
MCP_TIMEOUT. - HTTP: check the host, port and exact endpoint path.
- Approve project servers by running
claudein the folder. - Reconnect from
/mcpafter fixing.
FAQ
Why does claude mcp list say Failed to connect?
Claude Code tried to start or reach the server and couldn't. The text after the status gives the reason: an error code such as ENOENT or CONNECTION_CLOSED, a timeout, or the HTTP error. claude mcp get <name> shows it on an Issue: line.
How do I see an MCP server's error output in Claude Code?
Run the server's command yourself, copied from claude mcp get. For a failure inside a session, start Claude Code with claude --debug=mcp and read the server's stderr in ~/.claude/debug/<session-id>.txt.
Do Claude Code MCP servers get my shell's environment variables?
Stdio servers get Claude Code's own environment, minus variables it strips, unless CLAUDE_CODE_MCP_ALLOWLIST_ENV=1 is set. Don't rely on it: put required variables in the server's env config.
How do I increase the MCP startup timeout in Claude Code?
Set MCP_TIMEOUT in milliseconds when you start Claude Code, for example MCP_TIMEOUT=60000 claude. The default is 30 seconds.
Why does my .mcp.json server say Pending approval?
Project-scoped servers need a one-time approval. Run claude in the project and approve it, or run claude mcp reset-project-choices if you dismissed the prompt.
Sources
- Anthropic, Connect Claude Code to tools via MCP (docs: scopes,
claude mcp add,--envand--,${VAR}expansion, server status, failure detail, Pending approval, Reconnect,MCP_TIMEOUT,CLAUDE_PROJECT_DIR) - Anthropic, Debug your configuration (docs: Check MCP servers, relative paths, environment passed to stdio servers,
claude --debug=mcp,reset-project-choices,.mcp.jsonlocation and keys) - Anthropic, Environment variables (docs:
MCP_TIMEOUTdefault,MCP_TOOL_TIMEOUT,CLAUDE_CODE_MCP_ALLOWLIST_ENV) - Anthropic, Claude Code on npm (version 2.1.334 used for the tests)
- MCP Python SDK, mcp on PyPI (version 2.3.0,
MCPServerused for the test servers)