Codex: handshaking with MCP server failed: connection closed: initialize response
Codex started, or connected to, an MCP server from config.toml (the full line reads 'MCP client for `<name>` failed to start: ...'), but the server closed the connection before answering the MCP initialize request. The exact message, why Codex prints it, and the fix.
Updated November 23, 2026
The message
handshaking with MCP server failed: connection closed: initialize response
What it means
Codex started, or connected to, an MCP server from config.toml (the full line reads ‘MCP client for <name> failed to start: …’), but the server closed the connection before answering the MCP initialize request. Typical reasons: the server’s command crashes or writes non-MCP output, a slow npx download outlasts the startup timeout, a remote server only offers the deprecated SSE transport while Codex supports streamable HTTP, or the URL or credentials are wrong.
Fix
- Run the server’s command from config.toml by hand (for example
npx -y @upstash/context7-mcp) and check it starts without errors. - For remote servers, use the streamable HTTP endpoint (often ending in /mcp) instead of an /sse URL.
- Give slow servers more time with
startup_timeout_secin that server’s [mcp_servers.<id>] table (the default is 10 seconds). - Restart Codex and check the server’s status again.
In an EnvHaven workspace
It can happen anywhere Codex runs; the fix above applies in a workspace too.
Where this comes from
From Codex’s documentation and issue tracker: