The error, verbatim
Jump to the fix ↓⚠ 2 warnings · f2 to view
# after F2:
MCP client for `demo` failed to start: MCP startup failed: handshaking with MCP server failed: connection closed: initialize response: connection closed: initialize response
MCP startup incomplete (failed: demo)
The fix that worked
The reason is in the first warning. In codex exec, turn warnings on:
RUST_LOG=warn codex exec "say hi"Not it? Every cause, tested ↓Tested on
- Codex CLI
- 0.171.0
- MCP TypeScript SDK / Node
- 1.32.2 / 24.22.3
- OS
- GitHub Actions ubuntu-latest (TUI and exec) and windows-latest (exec), November 22, 2026
Contents
In Codex CLI 0.171.0 a broken MCP server doesn’t stop the session and doesn’t print in the chat. The footer gains a count, ⚠ 2 warnings · f2 to view, and F2 opens the list: one warning per failed server, MCP client for `<name>` failed to start: ... with the reason, then MCP startup incomplete (failed: <name>), which only names the servers. The reason is the part after MCP startup failed:, and the same reason can come from different problems.
I broke one stdio server in six ways and read what Codex printed for each, in the TUI and in codex exec.
Which cause is yours
What the warning says (after MCP startup failed:, or the timeout line) |
What caused it in the test | What fixed it |
|---|---|---|
handshaking with MCP server failed: connection closed: initialize response |
the server threw on start; the server exited because its API key wasn’t set; npx -y of a package that doesn’t exist |
depends on the server’s own error (below); for the key, setting it in [mcp_servers.<name>.env] fixed it |
No such file or directory (os error 2) (Linux), program not found (Windows) |
command names a program that isn’t installed or isn’t on PATH |
not run: install it, or put its full path in command |
timed out after 30 seconds, with a hint to set startup_timeout_sec |
the server took 45 s to start | startup_timeout_sec = 60 for that server |
Three different problems gave the same connection closed: initialize response: it means the server process ended before it answered Codex’s first message. Codex doesn’t show why it ended.
“connection closed: initialize response”: the server exited
A crashing server, a server that quits because a key is missing, and npx failing to download a package all end the process before the MCP handshake, and Codex 0.171.0 printed the same line for all three:
MCP client for `demo` failed to start: MCP startup failed: handshaking with MCP server failed: connection closed: initialize response: connection closed: initialize response
MCP startup incomplete (failed: demo)
Take the command and args of that server from ~/.codex/config.toml and run them in your own terminal. A server that dies on start prints its own error there (the stack trace, the missing variable, npm’s 404). This step was not part of the run; it is how to see what Codex leaves out.
If the server needs a key, give it one in the server’s env table:
[mcp_servers.demo]
command = "node"
args = ["/path/to/server.mjs"]
[mcp_servers.demo.env]
DEMO_API_KEY = "your-key"Raising startup_timeout_sec is common advice for MCP startup errors, but only the timeout message asks for it. In these three cases the process had already exited, so there was nothing left to wait for.
“No such file or directory” or “program not found”: the command isn’t there
MCP client for `demo` failed to start: MCP startup failed: No such file or directory (os error 2)
That was Linux, with command = "nonexistent-command-xyz". On Windows the same config logged error=program not found in codex exec (the TUI was run on Linux only). Check the name in command, and that the program runs from a fresh terminal.
On Windows, command = "npx" was found: the missing-package case got as far as the handshake there, the same as on Linux, rather than program not found.
“timed out after 30 seconds”: the server is slow
A server that waited 45 seconds before connecting gave:
MCP client for `demo` timed out after 30 seconds. Add or adjust `startup_timeout_sec` in your config.toml:
[mcp_servers.demo]
startup_timeout_sec = XX
So the default was 30 seconds in 0.171.0. Older reports show the same message with 10 seconds (openai/codex#11851), so check the number in yours. Two seconds in, the status line read Starting MCP servers (1/2): demo.
Set a longer limit for that server only:
[mcp_servers.demo]
command = "node"
args = ["/path/to/server.mjs"]
startup_timeout_sec = 60A first npx -y download can be slow. In the run, npx -y @modelcontextprotocol/server-everything started within the default 30 seconds in the Linux TUI, though codex exec had already run it once, so the npx cache may have been warm.
A line on stdout didn’t break it
codex exec prints nothing about MCP by default
In codex exec without RUST_LOG, the crash, the missing key, the missing command and the npx 404 printed nothing about MCP (in the two earlier runs that day, 45050204495 and 45050665484, on Linux and Windows): its default log filter leaves out stdio startup failures. With RUST_LOG=warn they appear:
WARN codex_mcp::rmcp_client: MCP server startup failed server_name="demo" error=handshaking with MCP server failed: connection closed: initialize response: connection closed: initialize response
The error= part is the same reason the TUI shows after failed to start: MCP startup failed:, with program not found on Windows for the missing command.
For the Claude Code side of this problem, where the same broken servers give MCP error -32000: Connection closed, see Fix: MCP error -32000 Connection closed.
If Codex stops before any server starts, with Error loading config.toml (an MCP server with no command gives invalid transport), see Codex: Error loading config.toml, each message and its fix.
How this was tested
GitHub Actions, November 22, 2026: Codex CLI 0.171.0 from npm, Node 24.22.3, a minimal stdio server on the MCP TypeScript SDK 1.32.2, one server per config.toml. Codex ran with a throwaway CODEX_HOME and an invented OpenAI key, so every model call failed with 401 invalid_api_key; MCP servers start anyway, and that 401 is the one warning left in the cases that passed. On ubuntu-latest each case ran in the TUI (inside tmux, warnings read with F2) and in codex exec with RUST_LOG=warn; on windows-latest, codex exec only. In codex exec the 45-second server’s timeout wasn’t reached, because the run ended at the 401 first. HTTP (url =) servers and OAuth sign-in were not tested. The workflow, the scripts and the output are in nk-repro/codex-mcp-startup.
— N.K., end of entry No.111