[Feature Request] MCP Context Isolation - Assign MCPs to Forked Agent/Skill Contexts

Status Fixed / completed
Maintainer reply None cached
Activity 11 comments · opened Jan 12, 2026 · closed Aug 17, 2026

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: fork infrastructure (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

  1. Context Efficiency: Main context stays lean, only loading MCPs when needed
  2. Granular Permissions: Each agent/skill has its own MCP scope
  3. Progressive Security: Layered access control instead of all-or-nothing
  4. 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 lazy maintains current behavior
  • Gradual migration: Move heavy MCPs to lazy: true one 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: fork implementation 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:

View original on GitHub ↗

10 Comments

cablate · 7 months ago

+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.

gn00295120 · 7 months ago

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.

ivanjuras · 7 months ago

+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.

  1. Make the default orchestration instance have its own MCPs activated.
  2. Make the individual skill have its own MCPs activated.
  3. Make the subagents have their own MCPs activated.

Problem solved.

gn00295120 · 7 months ago

@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

Main Context (Minimal - ~1,300 tokens)
├── Base MCPs: filesystem, memory
│
├── Agents (forked)              ← isolated context
│   ├── code-reviewer: + git
│   ├── database-specialist: + postgres
│   └── deploy-agent: + vercel, github
│
└── Skills (forked)              ← isolated context
    ├── /payment: + stripe
    ├── /db-migrate: + postgres
    └── /deploy: + vercel, github

Both Agents and Skills fork from Main Context with their own MCP scope. This enables:

  1. Context efficiency - Main context stays permanently clean
  2. Granular permissions - Each component loads only needed MCPs
  3. Security isolation - Credentials scoped to specific tasks
  4. Scalability - 20+ MCP servers without context pressure

Bonus: Skills Can Invoke Agents

Skills can also delegate to specific Agents via agent frontmatter:

---
name: deploy-workflow
agent: deploy-agent        # ← delegates to this agent
mcp: [vercel]
context: fork
---

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\!

SerkanSipahi · 7 months ago

+1, it would also be nice, optional, to define specific tools for a mcp. Often, I need just 1 or 2 for Agent/Skill.

# agents/database-specialist.md
---
name: database-specialist
mcp:
  required: [postgres]
    tools: [mcp__<server_name>__<tool_name>, mcp__<server_name>__<tool_name>, ...]
  optional: [redis]
context: fork
---

Further questions: What are the arguments against including this in the RFC for commands as well?

lcrostarosa · 6 months ago

+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

congwang-mk · 5 months ago

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_file tool and a read_file tool 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 McpSandbox enforces per-tool sandbox policies at the kernel level (Landlock + seccomp), deny-by-default:

from sandlock.mcp import McpSandbox

mcp = McpSandbox(workspace="/project")
mcp.add_tool("read_file", read_fn)  # read-only access, no network
mcp.add_tool("write_file", write_fn, capabilities={"fs_writable": ["/project"]})
mcp.add_tool("fetch_api", fetch_fn, capabilities={"net_allow_hosts": ["api.example.com"]})

Each tool invocation runs in its own sandbox. read_file can't write. write_file can't reach the network. fetch_api can only talk to api.example.com. No root, no containers.

For MCP servers discovered via sandlock:* tool annotations, policies are extracted automatically:

caps = capabilities_from_mcp_tool(tool)  # reads sandlock:* annotations
policy = policy_for_tool(workspace="/project", capabilities=caps)

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.

fabb · 5 months ago

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

lcrostarosa · 5 months ago

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 .

sebastien-savalle · 2 months ago

Any progress on this topic ? This is a real nightmare.

Showing cached comments. Read the full discussion on GitHub ↗