How do I reduce MCP server context usage in Claude Code without loading all servers at startup?
Claude Code loads every configured MCP server, tool, and agent at session start, which can consume over half the context window before any work begins. Users want to load MCP servers only when needed. Is there a built-in way to do this, or a workaround?
Originally asked on GitHub: https://github.com/anthropics/claude-code/issues/7336
5 answers
Status: partially addressed. Native automatic lazy loading was not implemented in this thread. The feature request remained a proposal, but Claude Code 2.0.10 added a runtime toggle for MCP servers, which covers much of the need.
What the thread reports:
- Claude Code 2.0.10 changelog: "Enable/disable MCP servers by @mentioning, or in /mcp". You can enable or disable a server at runtime without restarting the session, either by mentioning it in your prompt or through the /mcp command.
- Before this, a workaround was a script that added or removed entries in the Claude config files, but it required restarting Claude Code after each change.
- A commenter proposed a different approach: keep the main agent free of MCP servers and give specialized sub-agents their own MCP server references, so only a condensed summary returns to the main context. This is a design suggestion, not a confirmed built-in feature.
General advice: remove MCP servers you rarely use from your config, and enable others only for the task that needs them. Note that MCP servers can access external accounts, so keep API tokens scoped to the minimum permissions required.
Did this work for you?What a GitHub user tried on GitHub (Outcome unclear)
Reporter built a proof-of-concept registry in ~/.claude/optimization/ with a lazy-loader.py and generate-index.py that loads a small index and enables tools on keyword match. It was a simulation and did not change Claude Code's actual loading behavior.
Source: https://github.com/anthropics/claude-code/issues/7336 (opens external site)
Did this work for you?What @lukemmtt tried on GitHub (Worked)
Commenter used a custom script that adds or removes MCP entries from the Claude config files, keeping the full configs in a separate JSON file. Claude Code must be restarted after each change for it to take effect.
Source: https://github.com/anthropics/claude-code/issues/7336#issuecomment-3275817392 (opens external site)
Did this work for you?What @lukemmtt tried on GitHub (Worked)
Commenter noted that Claude Code 2.0.10 added the ability to enable or disable MCP servers by @mentioning them or via /mcp, which they found nearly as valuable as dynamic loading.
Source: https://github.com/anthropics/claude-code/issues/7336#issuecomment-3391599598 (opens external site)
Did this work for you?What @EugenEistrach tried on GitHub (Outcome unclear)
Commenter proposed keeping the main agent without MCP servers and giving specialized research sub-agents their own MCP servers (GitHub, Linear, Context7), returning only condensed summaries to the main session.
Source: https://github.com/anthropics/claude-code/issues/7336#issuecomment-3395241274 (opens external site)
Did this work for you?