The Codex Changelog
All Episodes
Local MCP Connection Sharing in Codex 0.166.0

Local MCP Connection Sharing in Codex 0.166.0

0:00|0:00

Codex 0.166.0 introduces experimental connection sharing for local stdio MCP servers to eliminate duplicate processes, reduce memory bloat, and isolate request timeouts across chats. We explore how to configure the feature flag, navigate potential initialization panics with legacy servers, and review smaller fixes like the network-only doctor flag.


Chapter 1

Sharing stdio MCP connections across chats

James Turner

Thanks to Jellypod for helping make this daily show a reality. Let's get into it. If you run local MCP servers with Codex, you've probably noticed that every new chat or subagent thread can spin up its own copy of each stdio helper. Codex 0.166.0 starts to change that, and follow up work is landing in the 0.167.0 alpha previews.

James Turner

Here's the change. Three pull requests matter. Number 57210 adds opt in protocol discovery for local stdio MCP servers. Number 57211 shares eligible local stdio MCP connections across chats. And number 57196 isolates MCP inputs and timeouts for callers that share a connection. The sharing is gated behind an experimental feature flag called mcp_connection_sharing, and the discovery piece is a probe using a method called server/discover.

James Turner

This builds on things we've covered before. A few episodes back, in the 0.164.0 episode on enterprise MCP sign in, the story was about how Codex authenticates to MCP servers. Then 0.166.0 shipped the standalone exec server and resume fixes. This is the next layer of the same infrastructure story: not just how Codex connects to an MCP server, but how many connections it makes to the same local process.

James Turner

Why does it matter? Think about what a stdio MCP server actually is. Codex launches it as a child process and talks to it over standard input and output. That's a one to one relationship. So if you have a heavy helper, say a SQLite analyzer, a language server wrapper, or a custom tool daemon, and you open three chats, or one chat that fans out into subagents, you can end up with three copies of that helper. Each one holds its own memory, its own caches, its own CPU appetite. The pattern we've been seeing is CPU and memory bloat whenever people run threads concurrently.

James Turner

Connection sharing aims to fix that. A single local helper process can serve multiple client sessions at once. And that's where pull request 57196 comes in. Sharing a process is only safe if callers can't step on each other. So that change isolates the inputs, the request and response lifecycles, and the timeouts between callers. If one chat's tool call hangs and times out, it shouldn't poison the connection for the others. That's the design goal, and it's worth testing against your own servers rather than assuming.

Chapter 2

Turning it on, and what can break

James Turner

Now, how do you try it? The flag is experimental, so treat it that way. In your Codex configuration, you set mcp_connection_sharing equal to true. Alongside that, there's a newer protocol setting named mcp_2026_07_28, which turns on the modern discovery handshake. Eligible servers negotiate sharing through that handshake. Codex sends the server/discover probe, and a server that understands it can report its compatibility and capability boundaries. A server that doesn't opt in should simply stay unshared.

James Turner

A practical workflow: pick one server you can afford to break. Turn the flag on in a scratch profile. Open two threads that both call that server, then look at your process list. If sharing is working, you should see one helper process, not two. Then deliberately trigger a slow tool call in one thread and confirm the other thread stays responsive. That second test is the one that tells you whether isolation holds for your helper.

James Turner

Now the caveats, and there are real ones. GitHub issue 57480 reports that enabling mcp_connection_sharing can break required legacy stdio servers that don't support modern discovery. Here's the failure. Codex sends the server/discover probe. A well behaved legacy server would answer with a standard JSON RPC method not found error, and Codex would fall back. But some unmarked legacy helpers answer with an empty result, just curly braces. According to the issue, Codex then panics with a message saying it expected an initialized result but received an empty result object. Initialization fails, and thread/start never succeeds. So a required server can stop you from starting a thread at all.

James Turner

There's a second gotcha. Say you decide to pin a server to an older protocol using the CODEX_MCP_PROTOCOL_VERSION environment variable, set to the June 2025 version string. If mcp_2026_07_28 is active at the same time, you get a hard startup failure. The message says the protocol version is unsupported and that Codex expected the 2026 07 28 version. Those two settings conflict, so pick one.

James Turner

So the guidance is simple. Don't flip this on globally if you depend on legacy helpers. Keep those helpers private, meaning not part of a shared configuration, or make sure your server answers unknown methods with a proper method not found error instead of an empty object. If you maintain an MCP server yourself, that second fix is about three lines, and it's worth doing now.

James Turner

A few smaller things from 0.166.0 worth a mention. First, codex doctor now takes a network only flag. It runs focused diagnostics on configuration, connectivity, proxies, endpoints, and WebSocket behavior, without the slower local environment and filesystem checks. If you're behind a corporate proxy and something's flaky, that's your first command.

James Turner

Second, a macOS fix. The standalone binary update cleanup now handles installations that are currently in use, and paths that contain non ASCII characters. If an update left stale files on your Mac before, that's likely the reason.

James Turner

Third, Markdown now renders consistently in async questions, choices, answers, and transcript replies. Small, but it removes some visual noise when Codex asks you something mid task.

James Turner

And one distribution note. The PyPI packages are still lagging at 0.163.0, while npm and the direct curl installers have 0.166.0, with early 0.167.0 alpha tags also live. If you installed through pip and wonder why none of this shows up, that's why. Switch install channels before you test any of this.

James Turner

The takeaway: connection sharing is a promising fix for duplicate stdio processes, but it's experimental and issue 57480 is open. Try it on a disposable setup, verify your legacy servers, and watch the 0.167.0 alphas for fixes. That's the Codex Changelog for today.