# 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

```text
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

1. Run the server's command from config.toml by hand (for example `npx -y @upstash/context7-mcp`) and check it starts without errors.
2. For remote servers, use the streamable HTTP endpoint (often ending in /mcp) instead of an /sse URL.
3. Give slow servers more time with `startup_timeout_sec` in that server's [mcp_servers.<id>] table (the default is 10 seconds).
4. 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:

- [github.com/openai/codex/issues/6020](https://github.com/openai/codex/issues/6020)
- [github.com/openai/codex/issues/6020#issuecomment-3487746480](https://github.com/openai/codex/issues/6020#issuecomment-3487746480)
- [learn.chatgpt.com/docs/config-file/config-reference](https://learn.chatgpt.com/docs/config-file/config-reference)

## Keep reading

- [Codex](https://envhaven.com/agents/codex)
- [Is Codex down?](https://envhaven.com/status/codex)
- [Every agent error](https://envhaven.com/errors)

Source: https://envhaven.com/errors/codex/mcp-client-failed-to-start-handshake
