Skip to main content

Claude Code: MCP server shows connection closed

Claude Code: MCP server shows "connection closed"

Symptom

At session start, Claude Code reports a local (stdio) MCP server as failed with CONNECTION_CLOSED, and its tools are missing for the whole session.

Likely cause

Servers launched with npx -y <package> run from a cached install in ~/.npm/_npx/<hash>/. If that cache is half-written or corrupted, the server crashes on launch before it can talk to Claude Code. It looks like an auth problem but is not.

How to check

Run the server's command by hand in a terminal, for example:

npx -y @gongrzhe/server-gmail-autoauth-mcp

A crash such as ERR_MODULE_NOT_FOUND ... ~/.npm/_npx/<hash>/node_modules/... confirms it.

Fix

  1. Delete the broken cache folder named in the error: rm -rf ~/.npm/_npx/<hash>
  2. Run the same npx -y <package> command once so it reinstalls cleanly.
  3. Restart Claude Code. MCP servers only connect at session start, so the running session will not pick up the fix.

Seen on

20 Oct 2026, Gmail MCP server (missing is-inside-container file inside the open package).