[Feature Request] MCP Context Isolation - Assign MCPs to Forked Agent/Skill Contexts
Problem Statement
Currently, all enabled MCP servers load at session start, consuming significant context budget before any actual work begins.
Measured impact (from community reports):
| MCP Server | Approx. Token Cost | Source |
|------------|-------------------|--------|
| GitHub (27 tools) | ~18,000 | Issue #11364 |
| AWS MCP servers | ~18,300 | Issue #7172 |
| Cloudflare | ~15,000+ | Community reports |
| Sentry | ~14,000 | Community reports |
| Playwright (21 tools) | ~13,647 | Scott Spence |
| Supabase | ~12,000+ | Community reports |
| Average per tool | ~550-850 | Issue #11364 |
| 7 servers total | 67,300 (33.7%) | Issue #11364 |
Many MCPs may never be used in a given session, yet they permanently occupy context space.
Real-World Pain Point: The Modern Work Hub Dilemma
Modern knowledge workers manage numerous platforms simultaneously:
| Category | Platforms |
|----------|-----------|
| Code Hosting | GitHub, GitLab, Bitbucket |
| Project Management | Jira, Linear, Asana, Notion |
| Communication | Slack, Discord, Teams |
| CI/CD | Vercel, Netlify, AWS |
| Monitoring | Sentry, Datadog |
The Dilemma:
- Option A (Install All): 50,000+ tokens consumed at session start = 50% context gone
- Option B (Separate by Project): Defeats Claude Code's value as a unified command center
Neither option is acceptable. We need on-demand loading to unlock Claude Code's potential as a universal work orchestrator.
Key Distinction: Context Isolation, Not Lazy Loading
This proposal is fundamentally different from traditional lazy loading approaches.
| Approach | Main Context | Load Time | Complexity |
|----------|-------------|-----------|------------|
| Traditional Lazy Loading | Gets populated when MCP needed | Runtime dynamic | High (state management) |
| Our Proposal: Context Isolation | Always stays clean | At fork creation | Low (reuses context: fork) |
Traditional Lazy Loading:
Main Context ──[need MCP]──> Load MCP ──> Main Context (now occupied)
Our Proposal (Context Isolation):
Main Context (stays clean)
└── Fork Agent Context ──> Load MCPs ──> Isolated Context
└── Released when done
This approach:
- Keeps main context permanently clean (not temporarily)
- Reuses existing
context: forkinfrastructure (lower implementation cost) - No runtime dynamic loading complexity (load once at fork creation)
Observation
Claude Code 2.1.x introduced context: fork for skills, enabling isolated context for specialized operations. This architecture already supports:
- Spawning isolated sub-contexts
- Independent tool permissions per fork
- Clean context separation
Proposal: On-demand MCP Loading
Extend the fork architecture to support MCP assignment at the agent/skill level:
# Example: agents/database-specialist.md
---
name: database-specialist
description: Database operations expert
tools: [Read, Bash, Grep]
mcp: [postgres, redis] # Only loads when this agent runs
context: fork
---
# Example: skills/deploy/SKILL.md
---
description: Deploy to production
mcp: [vercel, github] # Only loads during /deploy
context: fork
---
Proposed Architecture
Main Session (Lean)
│
├── Base MCPs only: filesystem, memory
│ (minimal context footprint)
│
├── Task: database-specialist (forked)
│ └── Loads: postgres, redis (isolated)
│
└── Skill: /deploy (forked)
└── Loads: vercel, github (isolated)
Benefits
- Context Efficiency: Main context stays lean, only loading MCPs when needed
- Granular Permissions: Each agent/skill has its own MCP scope
- Progressive Security: Layered access control instead of all-or-nothing
- Scalability: As MCP ecosystem grows, selective loading becomes essential
Proposed Implementation: Two-Sided Configuration
The ideal solution combines both MCP-side and Agent/Skill-side configuration for maximum flexibility and backward compatibility:
MCP-Side: Lazy Loading Flag in settings.json
{
"mcpServers": {
"memory": { "command": "...", "lazy": false },
"github": { "command": "...", "lazy": true },
"postgres": { "command": "...", "lazy": true }
}
}
Agent/Skill-Side: Frontmatter Declaration
# agents/database-specialist.md
---
name: database-specialist
mcp:
required: [postgres]
optional: [redis]
context: fork
---
Loading Logic:
| MCP lazy Setting | Agent/Skill Declaration | Result |
|-------------------|------------------------|--------|
| false (or omitted) | - | ✅ Load at session start (current behavior) |
| true | Not declared | ❌ Don't load |
| true | mcp: [xxx] | ✅ Load when agent/skill runs |
Why this approach?
- Backward compatible: Omitting
lazymaintains current behavior - Gradual migration: Move heavy MCPs to
lazy: trueone at a time - Fine-grained control: Both infrastructure and application level settings
Challenges to Consider
| Challenge | Possible Solution |
|-----------|------------------|
| MCP startup latency | Warm pool or pre-connect |
| State after fork ends | Stateless design or session cache |
| Tool discovery | Lazy manifest (know tools exist, load on use) |
| Credential scoping | Env var inheritance with scope limits |
About Us: Claude World
This proposal comes from Claude World - a Claude Code developer community based in Taiwan.
- 200+ developers joined on Day 1 of our community launch
- We focus on Claude Code best practices, advanced patterns, and architectural improvements
- MCP efficiency and context management is one of our most discussed topics
- We're actively documenting MCP token costs, designing workarounds, and sharing learnings with the global community
We'd love to hear the team's thoughts on this direction!
Related
context: forkimplementation in 2.1.0- Context awareness features in 2.0.65+
- MCP ecosystem growth
- Issue #7336 (Lazy loading feature request)
- Issue #11364 (Lazy-load MCP tool definitions)
---
Full Write-up
For detailed analysis with architecture diagrams and implementation considerations:
Showing cached comments. Read the full discussion on GitHub ↗
10 Comments
+1, this definitely needs an effective solution for the current “full bundle loading” behavior of MCP. Otherwise, there is an awkward gap between AgentSkills and MCP right now. Ideally, the two could complement each other and reach a better balance.
One of the most straightforward and lowest-cost approaches I can think of is to allow Skill Scripts to communicate directly using the MCP protocol. This would make it possible to use MCP server tools from Claude Code without having to install MCP inside Claude Code itself.
A reference implementation can be found here:
https://github.com/cablate/mcp-progressive-agentskill
I also strongly agree with @gn00295120’s idea of more explicitly loading MCP only for certain agents, supporting proper context isolation.
Or providing switches to enable/disable specific MCP-connected sub-tools. This would allow exposing only the necessary information and avoid the waste caused by loading everything by default. These are all capabilities that the MCP client side can already support.
Hope Anthropic team can implement similar optimizations in Claude Code.
Update: Why MCP Matters - Centralized Authentication
Some might suggest: "Why not just abandon MCP and wrap API calls in Skills using bash/curl?"
The critical issue is authentication:
| Aspect | MCP | Skills + Scripts |
|--------|-----|------------------|
| Credential Management | Centralized in settings.json | Scattered across .env, scripts, env vars |
| Security | Environment isolation | Risk of exposure in logs/shell history |
| Token Refresh | Handled automatically | Manual implementation required |
| Error Handling | Standardized responses | Different per API |
MCP's value isn't just the tools—it's the centralized, secure credential management.
Context Isolation preserves this security benefit while solving the context consumption problem. This is why we need MCP Context Isolation, not MCP abandonment.
---
This update has also been added to the RFC and article.
+1, please implement this. We need to be able to have a clean default Claude instance at all times. Also, make it possible for it to have some MCPs loaded by default.
Problem solved.
@ivanjuras Great breakdown\! This aligns perfectly with the RFC proposal.
Three Components, Three Roles
| Component | Role | MCP Scope |
|-----------|------|-----------|
| MCP | Provides services (tools, credentials, API access) | - |
| Agents | Isolated brain with clean context | Domain-specific (github, postgres) |
| Skills | Defines workflow - how to process data | Task-specific (stripe, vercel) |
Architecture: Parallel Forked Contexts
Both Agents and Skills fork from Main Context with their own MCP scope. This enables:
Bonus: Skills Can Invoke Agents
Skills can also delegate to specific Agents via
agentfrontmatter:This creates a powerful composition: Skill defines WHAT to do, Agent executes HOW to do it - each with isolated MCP contexts.
+1 for per-level MCP scoping\!
+1, it would also be nice, optional, to define specific tools for a mcp. Often, I need just 1 or 2 for Agent/Skill.
Further questions: What are the arguments against including this in the RFC for commands as well?
+1 - was just just going to open a feature request.
Example - a security review agent does not need access to my google calendar or gmail mcp
This proposal covers context isolation well. Worth noting there's a complementary problem: security isolation. Even with per-agent MCP scoping, each MCP tool still runs with the full permissions of the host process. A
write_filetool and aread_filetool share the same filesystem access. A tool that needs network access grants that to every other tool in the same server.We built sandlock to address this. Its
McpSandboxenforces per-tool sandbox policies at the kernel level (Landlock + seccomp), deny-by-default:Each tool invocation runs in its own sandbox.
read_filecan't write.write_filecan't reach the network.fetch_apican only talk toapi.example.com. No root, no containers.For MCP servers discovered via
sandlock:*tool annotations, policies are extracted automatically:Context isolation (this proposal) and security isolation (sandlock) solve different layers of the same problem. The two could work together -- forked contexts for token efficiency, kernel sandboxing for least-privilege enforcement per tool.
Disclaimer: I'm the sandlock author.
Very good proposal! Maybe for MCP servers with lots of tools it would be helpful to be able to limit tools in the skill frontmatter as well? I have made a slightly overlapping proposal: https://github.com/anthropics/claude-code/issues/41068
I would prefer to have the concept of "profiles" that contains a set of skills, agents, and MCPs that can be loaded up before loading up claude .
Any progress on this topic ? This is a real nightmare.