Add dynamic loading/unloading of MCP servers during active sessions
Problem Statement
Currently, MCP servers are loaded at session start and remain in the context window for the entire session, consuming tokens even when not
actively needed. This is particularly problematic for specialized tools like Linear that are heavily used during planning phases but rarely
needed during implementation.
Current behavior:
- Linear MCP server: ~14k tokens (7% of 200k context window)
- Loaded for entire session regardless of usage
- No way to dynamically enable/disable during session
## Use Case
Typical development workflow:
- Planning phase (5-15 minutes): Heavy Linear usage - create issues, update tickets, organize work
- Implementation phase (1-3 hours): Primarily coding - Linear context unused but consuming tokens
- Occasional planning (sporadic): Brief Linear usage for updates
Current workarounds are suboptimal:
- Session restarts lose conversation context
- Separate sessions fragment workflow
- Manual MCP add/remove requires CLI context switching
## Proposed Solution
Add dynamic MCP server management with session commands:
/mcp enable linear # Load MCP server mid-session
/mcp disable linear # Unload and free context tokens
/mcp list # Show active/available servers
/mcp status # Show token usage by server
Benefits:
- Preserve conversation context while managing resources
- Optimize context window usage for long development sessions
- Enable phase-based workflows (planning → implementation → review)
- Maintain security controls (approval prompts still apply)
## Implementation Considerations
- Context cleanup: Properly remove server tools/schema from context
- State management: Handle graceful enable/disable without breaking ongoing conversations
- Security: Maintain existing approval workflows for project-scoped servers
- UI feedback: Clear indication of active/inactive servers in status line
- Persistence: Remember user preferences per session
## Alternative Solutions Considered
- Improved scoping: More granular scope controls (feature-based, time-based)
- Lazy loading: Load servers on first use rather than session start
- Context compression: Compress unused MCP server definitions
## Related Issues
- #4986 (Dynamic Subagent Loading) - Shows interest in dynamic loading concepts
- #6632, #6616, #6621 - Context optimization concerns from users
## Impact
This feature would significantly improve context efficiency for users with multiple MCP servers, especially in long development sessions where
tool usage patterns change over time.
15 Comments
Let me illustrate this:
<img width="2220" height="586" alt="Image" src="https://github.com/user-attachments/assets/84cfd4f5-6cbf-4e5f-bd06-acbb950d5e69" />
Would be very nice to be able to add an mcp during the session, and even by the agent itself.
This is a fantastic feature request. I run into the exact same problem, especially with heavy-duty MCP servers that are essential for one part of my workflow but just take up valuable context for the rest. Your breakdown of the "planning vs. implementation" phases is spot on.
While we wait for a feature like this, I wanted to share a couple of workarounds I've found based on the current documentation, and also offer an explanation for the behavior you're seeing in your screenshot.
Explaining the Screenshot:
claude mcp addvs./mcpBased on the official documentation on MCP, the command
claude mcp addis run from your shell (outside of an active Claude Code session). It modifies the configuration files that Claude Code reads when it starts up.It looks like you ran
claude mcp add...in your terminal, and it correctly modified your local configuration file. However, your existing Claude Code session was already running and won't see that change until you restart it. When you then ran the slash command/mcpinside the session, it reported "No MCP servers configured" because it was still operating on the configuration it had when it was launched.This is the very problem you're highlighting: configuration is static for the life of the session.
Workaround 1: Using Project Scopes
The most direct way to manage this now is by using project-scoped MCP servers.
``
bash
`# Run this from your shell in the project root
claude mcp add linear --scope project --transport sse https://mcp.linear.app/sse
.mcp.json` file in your project directory.This will create a
mv .mcp.json .mcp.json.bakclaude --continueto resume your conversation.The new session will load without the Linear MCP server, freeing up those ~14k tokens. It's not as elegant as your proposed
/mcp disable, but it lets you keep your conversation history.Workaround 2: Specialized Sub-Agents
A potentially more powerful (but also more complex) workaround is to use Sub-Agents.
You could create a dedicated "planning" sub-agent that is the only thing with access to the Linear MCP server.
.claude/agents/planner.md:```markdown
---
name: planner
description: A sub-agent for planning, creating, and updating tickets in Linear.
tools: mcp__linear__create_issue, mcp__linear__update_issue, Read, WebSearch
---
You are a project management assistant. Your primary job is to interact with our Linear project board. When asked to plan work, create tickets, or update status, you must use the provided Linear tools.
```
plannersub-agent available. During your planning phase, you can invoke it:``
``> use the planner to create a new ticket for the auth refactor
The
plannersub-agent runs in its own context window, which gets populated with the Linear MCP tool definitions. Your main conversation context remains clean. During the "implementation" phase, you simply wouldn't invoke theplannersub-agent, and its context cost would never be incurred.---
Again, these are just stopgaps. Your proposal for
/mcp enableand/mcp disablewould be a massive quality-of-life improvement for anyone juggling multiple complex tools. +1 for this feature.+1 on this request ..
The way I work is to group a set of mcp server (tools) in a given group .. and enable and disable groups of them (i do that using a script). What I noticed in my workflow is that the MCP server's I use are not specific to the project I am working, but on what task I am working on.
So if I am in research mode, I use a given set of tools
So if I am in debug mode, I use a given set of tools
So if I am in testing mode, I use a given set of tools
etc ..
It use the same technique for subagents .. I don't have them all enabled (or available) at the same time .. but I select a "team" based on what I am doing .. As in real life, there is no point to have a project manager around during a brainstorming meeting, or have a front end dev present when you are working in SQL backend stuff.
I've implemented a proof-of-concept for intelligent lazy loading that goes beyond manual enable/disable:
🔗 Repository: https://github.com/machjesusmoto/claude-lazy-loading
📝 Full discussion: #7336
Key improvements over manual loading:
Example for your Linear use case:
This achieves what you're asking for - phase-appropriate tool loading without manual intervention.
Need this as well
This issue should be closed, as it has been resolved with the release of Claude Code 2.0.10:
@lukemmtt but can we have mcps started disabled and then enable them if needed?
@BenNewman100 100%, you can view and toggle them in realtime without restarting the session
yeah, but can you start a new session with them disabled? so they don't try to connect until you need them? that is my current problem
@BenNewman100
That's exactly how it behaves for me; mcp enablement statuses persist across sessions. If you're not seeing that, I recommended filing a bug report
I've just found this thread and appreciate the functionality is now available.
It would be a great enhancement for claude itself to be able to dynamically enable and disable them as needed.
"Please post my PR to slack"
"I see you want me to post your PR to slack...I'll need to enable the slack mcp first"
"...enabling slack mcp...posting to slack"
export ENABLE_EXPERIMENTAL_MCP_CLI=truewas doing it for me.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.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.