Feature Request: Improve Claude Code Token Management with MCP Servers
Feature Request: Improve Claude Code Token Management with MCP Servers
Problem Statement
Claude Code's current MCP server architecture creates significant workflow friction and inefficient resource utilization. All configured MCP servers load their complete tool schemas into the context at session initialization, consuming tokens regardless of actual usage.
Specific Issues:
- Static token overhead: 18.3k tokens (9.2% of context) consumed by unused AWS MCP servers
- Configuration-time resource decisions in discovery-driven workflows
- Session restart required to modify MCP server availability
- Premature optimization pressure: choose between token efficiency or tool availability
Impact on Developer Workflow
Real development scenarios require dynamic tool access patterns that the current architecture cannot support:
- Mid-conversation discovery: Developer realizes they need AWS documentation while debugging, but MCP servers weren't loaded
- Context-dependent tooling: Different projects require different AWS services (Lambda vs CDK vs pricing analysis)
- Token budget management: 18k static overhead reduces effective context window by ~4-5k lines of code
- Workflow interruption: Restarting sessions to change MCP configuration breaks conversation continuity
Technical Root Cause
The system treats MCP servers as session-scoped heavyweight resources rather than on-demand lightweight services. Tool schema definitions are eagerly loaded rather than lazily initialized, violating efficient resource allocation principles.
Proposed Solutions
Primary: Runtime MCP Server Management
- Enable/disable servers within active sessions without configuration changes
- UI controls in
/mcpinterface for real-time server toggling - Tool schema loading/unloading on demand
- Preserve conversation context during server state changes
Secondary: Intelligent Tool Loading
- Lazy schema initialization: Load tool definitions only when first referenced
- Contextual server suggestions: Claude identifies and requests needed servers mid-conversation
- Automatic schema eviction: Unload unused tool definitions to reclaim tokens
- Token-aware prioritization: Prefer lightweight servers when context pressure exists
Tertiary: Enhanced Configuration Scoping
- Session profiles: Quick-switch between predefined MCP server combinations
- Project-based auto-configuration: Automatically load relevant servers based on project type detection
- Usage analytics: Track MCP server utilization to inform configuration optimization
Success Criteria
- Zero-restart server management: Developers can enable AWS documentation MCP server mid-conversation without session interruption
- Token efficiency: Unused servers consume zero context tokens
- Workflow preservation: MCP server changes maintain conversation history and context
- Predictable performance: Server loading/unloading operations complete within 2-3 seconds
Business Justification
This directly impacts developer productivity in Claude Code adoption:
- Reduced cognitive overhead: No need to predict entire toolchain requirements at session start
- Improved context utilization: Recover 9%+ of context window for actual code and conversation
- Enhanced user experience: Eliminate artificial workflow constraints that force suboptimal behavior
Current Environment
- Claude Code with global MCP server configuration
- AWS MCP servers: aws-core, aws-documentation, aws-cdk, aws-pricing
- Context usage: 89k/200k tokens with 18.3k MCP overhead
- Development focus: Serverless/Lambda with Terraform (not CDK)
Priority Classification
High Priority - This addresses a fundamental architectural constraint that forces users into inefficient resource allocation patterns, directly impacting the core value proposition of Claude Code as a development productivity tool.
12 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Hey, this is a fantastic and incredibly well-detailed feature request. You've perfectly articulated a major friction point in using MCP servers for complex, discovery-driven workflows. That static 18k+ token hit just for the possibility of needing a tool is a tough pill to swallow when context is so valuable.
While we wait for an official solution from the Claude Code team, exploring some of the existing configuration options might offer a potential workaround to mitigate the issue.
Potential Workaround 1: Project-Scoped MCP Configurations
One approach could be to utilize Project-Scoped MCP Configurations. Instead of managing all MCP servers at the user/global level, they can be defined per-project in a
.mcp.jsonfile at the root of a repository.The documentation on MCP mentions this capability:
This would allow you to only have relevant servers loaded for a given project, which could help separate, for instance, a Node.js project's tools from a Python project's tools, reducing the overhead in each.
Potential Workaround 2: Using the
--mcp-configflag for "Task Profiles"A second, perhaps more flexible, possibility involves using the
--mcp-configCLI flag. This flag lets you load MCP server definitions from a specified JSON file at launch, and can be combined with--strict-mcp-configto ignore all other configurations. This could effectively be used to create "task profiles."For instance, one could create a few different JSON files for common task types:
~/.claude/mcp_profiles/aws-lambda-debug.json(loads just aws-core, aws-documentation)~/.claude/mcp_profiles/aws-cdk-dev.json(loads aws-core, aws-cdk)~/.claude/mcp_profiles/aws-billing.json(loads aws-pricing)A session could then be started that is tailored to a specific task, loading only the necessary tools:
This still requires a restart to switch contexts, but it seems like a faster way to manage toolsets without the huge token overhead of a monolithic global configuration.
---
Again, these are just stopgaps. Your proposed solution of runtime MCP management via the
/mcpcommand is the ideal state. Being able to dynamically load/unload tool schemas mid-conversation without losing context would be a game-changer for token efficiency and workflow fluidity.+1 from me. Thanks for writing this up so clearly.
I've created a working implementation that addresses your token management concerns:
🔗 Repository: https://github.com/machjesusmoto/claude-lazy-loading
📝 Full discussion: #7336
Solves your specific issues:
Your AWS example:
The implementation shows 95% reduction is achievable (108k → 5k initial tokens). This would give you back that 9.2% of context immediately.
I approached this from a different angle, choose what MCP servers you want when you start the session. Since you can resume a session, I feel it's OK to quit a session, select the MCP server you want to load and resume the session.
https://github.com/gsong/ccmcp
@gsong - looks like a useful tool. I've ended up in a similar spot:
Would still like to see CC add some type of MCP server management as part of the default tooling - the deferred loading until we request using the server would be ideal, IMO.
Having people choose which MCPs they'll need throughout a session is not really scalable. When you manage MCPs in a centric way, have subagents use those dynamically and want developers to have the best experience this should be totally transparent. Currently, it also limits the number of MCPs one can configure without bloating the entire context window.
While i created a wrapper that people can config which MCPs they would like to load in a specific session, this is not good enough.
This also defeats many initiatives like using central MCP gateways for exposing different MCPs to different groups of developers / devops engineers / secops / etc.
Can we make MCPs lazy loaded per the tool they need in realtime?
@nCubed - Yeah, I've taken a similar workaround approach of enabling/disabling the MCP servers by script for servers I toggle often. I have a bunch that are versatile and used frequently enough that I keep them on, though.
@talf - I think a production-ready feature would be a hybrid of deferred loading and lazy loading. Both would leverage a registry, and servers would load when directly requested or the agent/subagent contextually determines and loads it automatically.
I'd like to emphasize several critical issues stemming from having MCP tools continuously active in Claude Code:
Active MCP servers inject all tool schemas into every session — even when not used. This leads to massive context pollution and wastage of thousands (sometimes tens of thousands) of tokens per conversation. For many workflows, especially those only rarely requiring MCP integration, this means a huge fraction of the token window is lost to tool definitions instead of core code or dialogue.
Context bloat degrades LLM performance:
Passive exposure of all tool APIs increases the attack surface. Any tool — even dangerous ones (filesystem access, shell commands) — is potentially available for misuse unless specifically filtered. This violates least privilege principles, making systems more vulnerable to prompt injection, misuse, and lateral privilege escalation.
Most conversations do not need MCP tools at all. Users are penalized with overhead and risks for a capability they didn't request. Activation should be explicit: the context and resources stay optimized unless an MCP action is invoked.
When tool orchestration is handled on-demand (lazy loading or orchestrator-driven activation), developers can scale up as needed without fear of breaking context or workflow. This design preserves context for code, reduces cognitive stress over token management, and greatly improves security transparency.
Proposal: MCP servers in Claude Code should be disabled by default, and only activated on-the-fly via a dedicated orchestrator when the user requests a capability. No token or security stress should exist unless an explicit MCP call is made. This would restore predictable resource allocation, high security, and the best developer experience for both coding and AI-assisted workflows.
It's worth noting that MCP Toggle functionality has been added in Claude Code 2.0.10:
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.