claude-code - 💡(How to fix) Fix Per-agent and per-session MCP server toggles to control context budget [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52142Fetched 2026-04-23 07:35:32
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
1
Author
Timeline (top)
labeled ×5commented ×1cross-referenced ×1

Fix Action

Fix / Workaround

In my setup, ~232 MCP tools cost ~120-150k tokens of static overhead. When I dispatch a subagent on haiku (200k context), there's only 10-50k tokens left for actual work. The agent hits compact_boundary and produces hallucinated summaries instead of code.

Current workarounds

I run an orchestrator pattern where Opus coordinates and dispatches haiku/sonnet subagents. The orchestrator needs all MCP tools available for planning. The implementation subagents need only filesystem tools. The analytics agent needs only PostHog. Today I can't express this — it's either "all tools" or "only built-in tools."

Code Example

---
name: implementer
model: haiku
tools: Read, Grep, Glob, Bash, Edit, Write
excludeMcpServers: ["PostHog", "Gmail", "Slack", "Google Calendar"]
---

---

---
name: analytics-agent
model: sonnet
includeMcpServers: ["PostHog"]
---
RAW_BUFFERClick to expand / collapse

Problem

When a session has many MCP servers connected (PostHog, Gmail, Google Calendar, Slack, Google Drive, Firecrawl, etc.), the tool definitions consume a huge chunk of context — even with deferred loading, the tool names and descriptions are still present.

In my setup, ~232 MCP tools cost ~120-150k tokens of static overhead. When I dispatch a subagent on haiku (200k context), there's only 10-50k tokens left for actual work. The agent hits compact_boundary and produces hallucinated summaries instead of code.

Current workarounds

  1. Agent tools: allowlist — works but is all-or-nothing. Listing only built-in tools implicitly drops all MCP tools. There's no way to say "keep PostHog but drop Gmail and Slack."

  2. ENABLE_CLAUDEAI_MCP_SERVERS env var — single binary switch for all cloud connectors. Can't selectively enable one.

  3. Shell aliases that set/unset the env var before launching claude — clunky, requires restarting the session to change.

Proposed solution

1. Per-agent MCP server exclusion (agent frontmatter)

---
name: implementer
model: haiku
tools: Read, Grep, Glob, Bash, Edit, Write
excludeMcpServers: ["PostHog", "Gmail", "Slack", "Google Calendar"]
---

Or the inverse — an include list:

---
name: analytics-agent
model: sonnet
includeMcpServers: ["PostHog"]
---

This lets the orchestrating parent keep full MCP access while subagents only get what they need.

2. Per-session MCP server toggles (runtime)

A way to toggle individual MCP servers on/off without restarting the session. Could be:

  • /config switches: /config mcp.gmail enabled=false
  • A /mcp command: /mcp disable Gmail
  • Settings in settings.json that are hot-reloadable

Use case

I run an orchestrator pattern where Opus coordinates and dispatches haiku/sonnet subagents. The orchestrator needs all MCP tools available for planning. The implementation subagents need only filesystem tools. The analytics agent needs only PostHog. Today I can't express this — it's either "all tools" or "only built-in tools."

Granular MCP server toggles at both the agent and session level would let users control their context budget precisely, which is especially important for smaller-context models like haiku.

Environment

  • Claude Code CLI on Linux (WSL2)
  • ~232 MCP tools from 7 cloud connectors
  • 121 registered skills
  • Subagents on haiku (200k context) are most affected

extent analysis

TL;DR

Implementing per-agent MCP server exclusion or inclusion in agent frontmatter could help reduce the static overhead caused by numerous MCP tools.

Guidance

  • Consider adding an excludeMcpServers or includeMcpServers field to the agent frontmatter to selectively enable or disable MCP servers for each agent.
  • Evaluate the proposed solution of using per-session MCP server toggles, such as /config switches or a /mcp command, to dynamically control MCP server availability without restarting the session.
  • Assess the feasibility of implementing hot-reloadable settings in settings.json to control MCP server toggles.
  • Review the current workarounds, such as agent tools: allowlist and ENABLE_CLAUDEAI_MCP_SERVERS env var, to determine if they can be modified or extended to provide more granular control.

Example

---
name: implementer
model: haiku
tools: Read, Grep, Glob, Bash, Edit, Write
excludeMcpServers: ["PostHog", "Gmail", "Slack", "Google Calendar"]
---

This example demonstrates how to exclude specific MCP servers for an agent using the proposed excludeMcpServers field.

Notes

The proposed solution requires modifications to the agent frontmatter and potentially the session configuration. The effectiveness of this solution depends on the specific requirements and constraints of the Claude Code CLI and MCP tools.

Recommendation

Apply the proposed workaround of implementing per-agent MCP server exclusion or inclusion in agent frontmatter, as it provides a more granular control over MCP server availability and can help reduce the static overhead.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING