Skip to main content

How to Fix MCP Server Connection Errors

Short answer

When an MCP server won't connect, the AI app usually logs the reason. Open that app's MCP log first, find the error, and match it to the sections below. The common causes are a command the app can't find, a config file that isn't valid JSON or TOML, output on stdout that corrupts the connection, and a server that rejects your sign-in. MCP error -32000: Connection closed means the connection to the server ended. For a local server, the real error is in its stderr. For Claude Desktop on macOS, the config lives at ~/Library/Application Support/Claude/claude_desktop_config.json.

Tested withMCP spec 2026-07-28Python SDK (mcp) 2.3.0, Python 3.10 or laterMCP Inspector 2.11.0, Node.js 22.19 or laterTypeScript SDK v1 (@modelcontextprotocol/sdk) 1.32.2Checked 2 Nov 2026

Start here​

Match what you see to the first place to look.

What you seeStart with
The server isn't in the app's list at allThe config file: its location and whether it parses
The log says spawn <command> ENOENTThe command path
spawn npx ENOENT on Windows onlyThe cmd /c wrapper
Codex says program not foundThe command path, then your Codex version
MCP error -32000: Connection closedRun the command yourself and read stderr
The server starts, then drops straight awayAnything printed to stdout
There was an error reading or parsing claude_desktop_config.jsonThe config file's JSON, and whether a remote url is in it
claude.ai says Couldn't reach the MCP serverPublic DNS, firewall rules, and OAuth discovery
VS Code says Send a message firstStart a chat before you start the server
The log says ModuleNotFoundErrorThe Python environment the server runs in
The server asks you to sign in, or you get a 401Sign-in and the token
The server connects but the model never calls its toolsTool count and descriptions

Where the config and logs live​

Each app keeps its server list and its log in a different place. The table covers the apps this guide's fixes apply to.

AppConfigWhere to look for errors
Claude DesktopmacOS: ~/Library/Application Support/Claude/claude_desktop_config.json. Windows: %APPDATA%\Claude\claude_desktop_config.jsonmacOS: ~/Library/Logs/Claude. Windows: %APPDATA%\Claude\logs. mcp.log covers connections, and mcp-server-SERVERNAME.log holds each server's stderr
CursorGlobal: ~/.cursor/mcp.json. Project: .cursor/mcp.jsonOpen the Output panel (Cmd+Shift+U) and select "MCP Logs"
VS CodeProject: .vscode/mcp.json. User: run "MCP: Open User Configuration"Command Palette, "MCP: List Servers", select the server, then "Show Output"
Claude CodeProject: .mcp.json in the project root. User: ~/.claude.jsonRun claude mcp list, or claude mcp get <name> to see the Issue: line. In a session, /mcp shows status
Codex~/.codex/config.toml, or .codex/config.toml in a trusted projectRun codex mcp list. Type /mcp in the composer to see connected servers

Claude Desktop only reads its config when it starts. Edit the file, then quit the app completely and reopen it. Closing the window isn't enough.

To watch the Claude Desktop log while you restart, run this in a terminal:

tail -n 20 -F ~/Library/Logs/Claude/mcp*.log

On Windows, run type "%APPDATA%\Claude\logs\mcp*.log" in Command Prompt.

Anything a local (stdio) server writes to stderr goes into its per-server log. If that log is empty, the server may never have started.

Check your runtime versions first​

Many failures are an old runtime, not a bug in the server. These are the minimums from each package's own metadata:

ToolMinimum
MCP Inspector (@modelcontextprotocol/inspector 2.11.0)Node.js 22.19.0
TypeScript server SDK (@modelcontextprotocol/server 2.3.1)Node.js 20
Python SDK (mcp 2.3.0)Python 3.10

Check your versions with node --version and python3 --version. The app may use a different Node or Python from your terminal, so the path to the command in your config matters too (see the next section).

Error messages and fixes​

spawn <command> ENOENT​

Node.js prints this when it can't find the program named in your config. The name after spawn is the command value. On my test machine, a command that doesn't exist gave this:

spawn uvx-not-installed ENOENT

The app couldn't find the executable with that name. A server started by an app gets only a limited set of environment variables, so a command that works in your terminal may not resolve there. Use the full path to the command. Get it with which uv or which node on macOS and Linux, or where uv on Windows, and put that path in command:

claude_desktop_config.json
{
"mcpServers": {
"bookmarks": {
"command": "/ABSOLUTE/PATH/TO/uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/bookmarks",
"run",
"bookmarks.py"
]
}
}
}

The MCP docs make the same point: when a client launches a stdio server, the working directory may be undefined, so use absolute paths in command and args.

On Windows, the Claude docs also describe an ENOENT error that mentions ${APPDATA} in a path. The fix there is to add the expanded value to the server's env key, such as "APPDATA": "C:\\Users\\username\\AppData\\Roaming\\".

The command value must be one program on its own. A value like "command": "npx -y some-server" fails, because the app looks for a program whose whole name is that string. Put the program in command and each word after it as a separate item in args.

spawn npx ENOENT on Windows​

On Windows, npx, npm, pnpm and yarn are .cmd scripts, not .exe programs. The Node.js docs say .bat and .cmd files can't run on their own without a terminal, so an app that starts the server directly can't find npx even when it works in PowerShell. The fix is to start cmd.exe and let it run npx:

claude_desktop_config.json
{
"mcpServers": {
"filesystem": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-filesystem",
"C:\\Users\\username\\Desktop"
]
}
}
}

/c tells cmd to run the rest of the line and exit. Backslashes in JSON paths must be doubled, as in C:\\Users\\username. The same wrapper works in Cursor's mcp.json. It's also the workaround for Claude Code plugins that ship "command": "npx" and fail on Windows with Failed to connect.

program not found (Codex)​

Codex starts servers without a shell, so on Windows a bare npx used to fail with MCP client for <name> failed to start: program not found. Current Codex releases look up .cmd scripts through PATH and PATHEXT, so update Codex first. On a current version, this message means the command really isn't on the PATH that Codex passes to the server.

Run where.exe npx in the terminal you start Codex from. If it prints nothing, Node.js isn't installed or isn't on that PATH. Open a new terminal after installing Node.js, since an open window keeps its old PATH. You can also skip the lookup and give the full path. Single quotes make a TOML literal string, so the backslashes need no escaping:

config.toml
[mcp_servers.filesystem]
command = 'C:\Program Files\nodejs\npx.cmd'
args = ["-y", "@modelcontextprotocol/server-filesystem", 'C:\Users\username\Desktop']

MCP error -32000: Connection closed​

This is the most common MCP error, and it doesn't say what went wrong. -32000 is the TypeScript SDK's ConnectionClosed code: the connection to the server ended while the app was still waiting for a reply. With a local server, the process exited or its output stopped being valid MCP messages. The app is only reporting what happened. The cause is usually in the server's stderr.

We got the same result from MCP Inspector two ways: from a server that exits as soon as it starts, and from one that prints Server starting to stdout:

{"error":{"code":"error","message":"Connection closed"}}

Work through these in order:

  1. Run the exact command and args from your config in a terminal. A healthy stdio server prints nothing to stdout and waits for input. Press Ctrl+C to stop it. If it prints a stack trace or exits, fix that first. A missing package, a wrong Node or Python version, or a missing API key all show up here.
  2. Read the server's own log. In Claude Desktop that's mcp-server-SERVERNAME.log, which holds the server's stderr. The general mcp.log often only says the connection closed.
  3. Look for output on stdout. A single print() or console.log() breaks the connection. See The server connects, then disconnects straight away.
  4. Check the environment. The app gives the server a limited set of environment variables. Anything the server needs, such as a token, goes in the server's env block.
  5. For a remote server, check whether a proxy or load balancer closes long-running requests. Raise its idle timeout.

If the error appears with spawn ... ENOENT just before it, the server never started. Go back to spawn <command> ENOENT.

Invalid JSON in the config file​

A trailing comma, a missing brace or a stray quote stops the file from loading, and the server never appears. Check the file before you restart the app:

python3 -m json.tool ~/Library/Application\ Support/Claude/claude_desktop_config.json

A file with a trailing comma after "command": "uv", produced this output:

Illegal trailing comma before end of object: line 4 column 22 (char 60)

Delete the comma, save the file, and run the check again. A file that parses prints the same JSON back. Cursor's mcp.json needs valid JSON too. Codex uses TOML, so check config.toml with python3 -c "import tomllib,sys;tomllib.load(open(sys.argv[1],'rb'))" config.toml instead.

There was an error reading or parsing claude_desktop_config.json​

Claude Desktop shows this when it opens and can't load its config. The text after the colon says why. Two kinds of message come up most often.

A JSON syntax error, such as Unexpected non-whitespace character after JSON or Expected property name or '}'. This usually means two JSON objects were pasted one after the other, or a new server was added outside the mcpServers object. The file must have one outer pair of braces, with every server inside mcpServers, separated by commas. Run the json.tool check above to find the line.

A "command" field marked "Required", like this:

There was an error reading or parsing claude_desktop_config.json: [{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"mcpServers",
"acme",
"command"
],
"message": "Required"
}]

The path names the server that failed. Every entry in claude_desktop_config.json needs a command, because this file only starts local servers. An entry with just a url and type: "http" fails here. Add remote servers in Claude as a custom connector instead: go to Customize, then Connectors, click "Add", hover over "Custom", select "Web", and paste the server's URL. Then remove the url entry from the config file.

ModuleNotFoundError: No module named 'mcp'​

The server started, but the Python that ran it doesn't have the mcp package. Running python3 -c "import mcp" in a clean environment gives this:

ModuleNotFoundError: No module named 'mcp'

The app may start your server with a different Python from the one where you ran uv add. Launch the server through uv, so it uses the project's own environment:

cursor-mcp.json
{
"mcpServers": {
"bookmarks": {
"command": "/ABSOLUTE/PATH/TO/uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/bookmarks",
"run",
"bookmarks.py"
],
"env": {
"BOOKMARKS_FILE": "/ABSOLUTE/PATH/TO/bookmarks.json"
}
}
}
}

The --directory flag tells uv which project to use, and run makes sure its dependencies are installed.

The server connects, then disconnects straight away​

On stdio, the server's standard output (stdout) carries the protocol messages, so anything else you print there gets in the way. The MCP debugging guide says local servers should not log to stdout, because it interferes with protocol operation. The app can then drop the connection, and the server looks like it died for no reason.

Find the stray output. In Python, look for print() calls, including inside libraries you import. In TypeScript, look for console.log(). Send diagnostic output to stderr instead. In Python, logging with its default handler writes to stderr, so configure it once at startup:

import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info("Server starting")

In Node, console.error() writes to stderr.

Unsupported protocol version (-32022)​

A client and a server that don't share a protocol revision can't talk. The server answers with the error code -32022, and its data field lists the versions it does support. To see which versions a server supports, the client sends a server/discover request. Compare that list with the version your client uses, then update whichever side is older. The Inspector helps here: --protocol-era legacy tests the older handshake and --protocol-era modern tests the 2026-07-28 revision.

Sign-in fails, or you get a 401​

A remote server returns HTTP 401 when a token is missing, invalid or expired. The spec requires the response to include a WWW-Authenticate header that points at the server's protected resource metadata. Claude Code shows this as a server that needs authentication, and you can sign in again from the app:

  • Claude Code: run /mcp, select the server, and choose Re-authenticate. To remove the stored sign-in first, choose "Clear authentication". From the shell, claude mcp login <name> runs the same sign-in flow.
  • Cursor: if the provider asks for a registered redirect URL, add https://www.cursor.com/agents/mcp/oauth/callback and http://localhost:8787/callback to its OAuth app. Cursor uses the first for web and Cursor Agents, and the second for the desktop app.
  • Codex: run codex mcp login <server-name> for a server that supports OAuth.

If you set a token by hand in headers, check the value itself. Claude Code warns about leading or trailing whitespace, which often comes from pasting a token with a newline on the end. In a remote server's url and headers, Claude Code also reads credential variables from your environment as empty, so a header like Bearer ${SOME_TOKEN} can reach the server with no token. Use the app's sign-in flow where the server supports it.

For OAuth connections that keep looping, see OAuth sign-in for MCP servers.

Insufficient scope (needs additional permissions)​

Signing in worked, but a tool call failed because the token lacks a permission. Claude Code reports this as a needs additional permissions message that names the scope the server wants. Add that scope to the server's pinned oauth.scopes, then run /mcp and authenticate again. Claude Code requests the pinned scopes, so signing in again without the new scope gives you a token that still lacks it.

Failed to connect or disconnected · open /mcp to reconnect​

Claude Code retries a failed first connection up to three times, then marks the server as failed. claude mcp list adds the failure detail to that line, and claude mcp get <name> shows it on an Issue: line. Open /mcp to reconnect one server, or run /mcp reconnect all in the interactive terminal (Claude Code v2.1.284 or later). Claude Code doesn't retry authentication errors or 404s, so fix the configuration first.

Pending approval (run claude to approve)​

Claude Code asks you to approve each project-scoped server in .mcp.json before it connects. Run claude in the project, accept the workspace trust dialog, then approve the server. A cloned repository can't approve its own servers. The approval has to come from the trust dialog on your machine. To reset your earlier choices, run claude mcp reset-project-choices.

Couldn't reach the MCP server (claude.ai and Claude Desktop connectors)​

Custom connectors connect from Anthropic's cloud, not from your computer. That holds in Claude Desktop too. So a server that works in Claude Code, MCP Inspector or curl on your machine can still fail here. Some versions of the message read "Couldn't connect to the server. Check that the URL points to a valid MCP server." Anthropic's troubleshooting page lists the causes in this order:

CauseHow to check
The hostname resolves to a private, carrier-grade NAT, loopback or link-local address, or has no IPv4 A record. Connectors are IPv4-onlyRun dig +short your-server.example.com from outside your network. Every address must be public
A CDN, WAF, bot rule or rate limiter blocks Anthropic's requestsLook for 403 or 429 responses in your edge logs that your app didn't send, and allowlist Anthropic's published IP range
OAuth discovery failsFrom a public network, curl -i the /.well-known/oauth-protected-resource path on your server. It should return 200 with JSON

If your server's access log shows no request at all during the Connect attempt, the hostname was rejected before any request was sent. A server on a VPN, a corporate network or your own laptop needs a public endpoint, such as a cloud host, a public reverse proxy or a tunnel.

When nothing on the list matches, copy the reference ID that starts with ofid_ from the error or the page URL. Report it with your server URL on the anthropics/claude-ai-mcp issue tracker. The ID expires, so report soon after the failure.

Authorization with the MCP server failed​

The sign-in started but didn't finish. A common cause is a server URL that redirects to a different host, such as example.com to www.example.com. Claude drops the Authorization header when it follows a redirect to another host, so the redirected request gets a 401. Run curl -sI on your MCP URL. If it returns a 3xx with a Location on another host, register that target URL instead.

The other causes are on the server's sign-in side: an issuer in the metadata that doesn't match the one signing tokens, a token audience that doesn't match the MCP server URL, no S256 PKCE support, or a /token endpoint that takes longer than 10 seconds to answer.

Cannot start an MCP server before the session runtime has been created. Send a message first. (VS Code)​

In VS Code with GitHub Copilot, clicking Start on a server fails with this when the active chat is a Copilot CLI session that has no messages yet. Send any message in the chat, then start or restart the server. If the server then exits straight away in that session type, check for ${input:...} values in the server's env. Copilot CLI sessions have been reported to pass them through unexpanded. Replace them with literal values as a workaround.

Warnings about whitespace or unset variables​

Claude Code warns when a config value has hidden leading or trailing whitespace, and names the field, for example headers.Authorization. It doesn't trim the value for you, so open the file and remove the space or newline.

It also warns when a ${VAR} reference names a variable that isn't set and has no default. It still loads the server, but with the text ${VAR} unexpanded. Set the variable, or give it a fallback in the form ${VAR:-default}.

Timeouts​

A server that takes too long to start or to answer gets cut off. The limits are set in config:

AppSettingDefaultWhat it controls
Codexstartup_timeout_sec10Seconds to wait for the server to start
Codextool_timeout_sec60Seconds for one tool call
Claude CodeMCP_TIMEOUT (environment variable, milliseconds)Startup timeout, for example MCP_TIMEOUT=10000 claude
Claude CodeMCP_TOOL_TIMEOUT (environment variable, milliseconds)About 28 hours if unsetHard limit for one tool call
Claude Codetimeout in the server's entry in .mcp.json (milliseconds)Hard limit for one tool call on that server, overriding MCP_TOOL_TIMEOUT

For Codex, these keys sit in the server's table in config.toml. This example file parses:

codex-config.toml
[mcp_servers.bookmarks]
command = "/ABSOLUTE/PATH/TO/uv"
args = ["--directory", "/ABSOLUTE/PATH/TO/bookmarks", "run", "bookmarks.py"]
startup_timeout_sec = 20
tool_timeout_sec = 60

[mcp_servers.bookmarks.env]
BOOKMARKS_FILE = "/ABSOLUTE/PATH/TO/bookmarks.json"

Raise the startup value if the server is slow to load its dependencies, and check the server for a hang if a tool call times out.

The model never calls the tool​

The server is connected, but the tool doesn't show up in the chat or the model picks another one. Claude Code loads MCP tools on demand by default, and /mcp shows how many tools each connected server exposes. It also flags a server that advertises tools but exposes none. In VS Code, run "MCP: Reset Cached Tools" after a server changes its tools.

If the server exposes a lot of tools, the model has more to choose between. How many tools is too many covers how to split or scope a server. The tool's name and description decide whether the model picks it. Tool names and descriptions covers writing them.

FAQ​

What does MCP error -32000 Connection closed mean?

The connection to the server ended while the app was waiting for a reply. With a local server, the process usually exited, failed to start, or printed something other than MCP messages to stdout. Run the command from your config in a terminal and read the server's stderr log to find the real error.

How do I fix spawn npx ENOENT on Windows?

On Windows, npx is a .cmd script that apps can't start directly. Set command to cmd and put /c and npx at the start of args, then fully quit and reopen the app.

Why doesn't my MCP server show up in Claude Desktop after I edit the config?

Claude Desktop reads its config only at startup. Check the file parses with python3 -m json.tool, then quit the app completely and open it again. If the server still doesn't appear, read the mcp.log file in the Claude logs folder for the reason.

Where do I find MCP logs in Cursor?

Open the Output panel with Cmd+Shift+U, then choose "MCP Logs" from the dropdown. It shows server startup, tool calls and error messages for each server.

Why does my server work in the terminal but fail in the app?

Apps start stdio servers with a limited set of environment variables, and the working directory may not be your project folder. Your shell settings don't always carry over. Use absolute paths in command and args, and set any variables the server needs in its env block.

Do I have to start a local MCP server myself?

No. When an app connects to a local (stdio) server, the app launches it as a child process. You only run the server yourself when you test it, for example with MCP Inspector.