Optional / Lazy Loading of MCP Servers
Open 💬 7 comments Opened Aug 15, 2025 by sanand0
What feature would you like to see?
Some MCP servers take several seconds to start. If there’s an error, Codex waits 60s before timing out.
This makes the CLI startup _feel_ slow (though I can start typing immediately). That's a little distracting when we're not using those MCPs in that session.
Could MCPs be:
- Loaded on demand when first invoked in a conversation?
- Loaded explicitly via a command-line option (e.g.
--with-mcp=playwright,github) - Loaded explicitly in-session slash command (e.g.
/mcp load playwright).
That'd keep startup fast _and_ let us use MCPs when needed.
Are you interested in implementing this feature?
Yes, I'd love to!
Additional information
It's great that Codex is lightweight - interface _and_ feature-wise. I'd love to keep it that way. Happy to understand alternative approaches.
7 Comments
see also https://github.com/anthropics/claude-code/issues/11364
This should be shipped soooooon...
I implemented optional / lazy loading of MCP servers in my fork, xCodex (
xcodex), and shipped it in v0.3.5.xCodex: https://github.com/Eriz1818/xCodex
Release notes: https://github.com/Eriz1818/xCodex/blob/main/docs/xcodex/releases/0.3.5.md
Docs: https://github.com/Eriz1818/xCodex/blob/main/docs/xcodex/lazy-mcp-loading.md
What it adds:
/mcp load <name>(plus/mcpstatus +/mcp retry ...)xcodex --mcp-startup-mode lazy(or eager/manual)This keeps startup fast for sessions that don’t use MCP, while still making it easy to opt-in when you do. AND saving on context!
Hitting the same issue on Windows with Codex CLI 0.116.0.
In my case I have multiple stdio MCP servers enabled in config at the same time, including
context7,chrome-devtools, and image tooling launched vianpx.The current workarounds are only partial:
enabled = falsedisables the server entirelystartup_timeout_seconly reduces how long startup waitsFor local CLI usage, this feels like the wrong default. Paying startup cost for unused MCP servers on every run makes Codex feel slower even in sessions where I only need plain coding help.
What would help:
--with-mcp=context7,chrome-devtoolsrequired = trueservers at startupThis is more of a local CLI UX issue than just a timeout tuning issue.
+1 here. I'm running multiple codex instances, often 8-10 at a time, all of them running all mcp servers all the time for no reason, I have +10 chromium instances running because of chrome-devtools-mcp alone...
Adding a current Codex CLI data point from
codex-cli 0.133.0.This is still a real UX issue for rarely used MCP servers. In my setup, browser-control and browser-screen-click MCPs are only needed occasionally, but Codex tries to initialize them during session startup. When one is unhealthy, startup prints warnings like:
The same applies to remote MCPs such as Atlassian: even if the current prompt does not need Jira/Confluence, the session still pays the startup/auth/network cost and can show unrelated MCP failures.
I checked the
rust-v0.133.0source to make sure this is not just configuration I missed:config/src/mcp_types.rs:McpServerConfighasenabled,required,startup_timeout_sec/ms, tool filters, auth fields, etc., but no server-level lazy/manual startup mode.core/src/session/session.rs: session setup callsMcpConnectionManager::new(...)for the effective MCP server set.codex-mcp/src/connection_manager.rs:McpConnectionManager::newiterates everyserver.enabled()and starts anAsyncManagedClientfor each.codex-mcp/src/rmcp_client.rs: startup performs MCPinitializeandtools/listbefore the server's tools are considered ready.tool_search_always_defer_mcp_toolsonly defers model-facing tool exposure behindtool_search; it does not defer server process/network startup.The behavior I would expect is a server-level mode, for example:
Possible semantics:
eager: current behavior.lazy: do not start the MCP server during session startup; start it on first tool/resource/template call, or whentool_searchselects one of its tools.manual: never auto-start; only start via something like/mcp load <server>or a CLI allowlist.required = truecan keep eager/blocking behavior, or at least fail the session if the required server cannot be started before first use.For
tool_search, it would be useful if Codex could search known tool metadata without requiring live server startup on every session. That could come from a cached priortools/list, plugin-provided/static tool metadata, or a placeholder entry that triggers server initialization when selected.Current workarounds (
enabled = false, profiles, lowerstartup_timeout_sec) are coarse. They either remove the tools entirely or require restarting/reprofiling Codex for a tool that might be needed once in a long-running session.This is so insane that there's no option to only start an MCP server when it's needed.
If I leave Codex running unchecked I have to go and manually kill literally _hundreds_ of
node,uvandpythonprocesses that are taking up non inconsequential amounts of CPU and ram. Codex is instantiating these for every single sub agent even when they are only used maybe 1 out of 100 sessions. So I either have to constantly go in and out of config to enable/disable when I need each or just let them run and start up every time. Very frustrating.