Add mcp search tool, lazy mcp load, reduce mcp tool occupying a lot of context
What feature would you like to see?
When MCP tool descriptions exceed 10% of the context window, they are automatically deferred and discovered via the MCPSearch tool instead of being loaded upfront. This reduces context usage for users with many MCP tools configured.
References:
- high level description: https://x.com/i/status/2011523109871108570
- tool search specification: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool
- original Claude Code issue: https://github.com/anthropics/claude-code/issues/7336
Related issues:
- https://github.com/openai/codex/issues/2335
Additional information
No response
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:
- Global + per-server MCP “startup_mode”: eager (default) | lazy | manual
- lazy: don’t start servers at session start; start on first tool/resource use
- manual: never auto-start; load explicitly
- In-session command:
/mcp load <name>(plus/mcpstatus +/mcp retry ...) - CLI one-run override:
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!
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:
* Global + per-server MCP “startup_mode”: eager (default) | lazy | manual * lazy: don’t start servers at session start; start on first tool/resource use * manual: never auto-start; load explicitly * In-session command: `/mcp load <name>` (plus `/mcp` status + `/mcp retry ...`) * CLI one-run override: `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!
wow nice. Would you be able to do a PR for the official codex repo? Seems very useful :)
This is very much needed
While waiting for native lazy loading support, you can at least identify which MCP servers are the worst offenders using mcp-checkup:
npx mcp-checkup
It analyzes your setup, measures token cost per server/tool, and grades them A-F. Users with many MCP servers often discover 2-3 servers account for 80% of context overhead — disabling just those gives you most of the benefit of lazy loading without client-side changes.
Zero config, just npx and go.
+1
Lazy MCP loading probably needs four states, not only eager versus lazy: configured, manifest-known, started, and invoked.
Tool search can operate over manifest-known servers without paying startup cost, then start a server only when a selected tool needs execution. The metric to watch is also two numbers: manifest tokens loaded into the prompt and first-use latency after tool selection. That prevents the fix from trading context overhead for opaque stalls on the first real MCP call.
Generated with ax.
tool_search avoids eagerly loading every MCP tool.
@saidelike hey — I'm researching recurring problems caused by large MCP/tool setups and found your proposal.
Several months later, is MCP context usage still a meaningful problem in your actual workflow?
Also, do you currently do anything manually to decide which tools get loaded, or have newer Codex versions mostly solved this for you?