Skip to content

Subagents fail with 'prompt is too long' when user has many MCP servers (tool definitions exceed 200k) #37793

Description

@TweedBeetle

Problem

When a user has many MCP servers configured at the user level, subagents (Explore, Plan, general-purpose) fail immediately with prompt is too long: 209117 tokens > 200000 maximum before executing a single tool call. The TUI shows Done (0 tool uses · 0 tokens · 44s) with no error visible to the user.

Root Cause

Subagents inherit all MCP tool definitions from the parent session. Each tool definition includes a full JSON schema. With many MCP servers, the tool schemas alone exceed Sonnet's 200k context limit.

Reproduction

Setup: 34 MCP servers configured in ~/.claude.json (Bright Data, Discord, GitHub, Gmail, Playwright, Sentry, YouTube, etc.) totaling ~566 MCP tools.

Main session: Opus 4.6 (1M context) on Claude Max — works fine, 209k of tool schemas fits within 1M.

Subagent spawn: Any Agent call (Explore, Plan, general-purpose) → Sonnet 200k → immediate API error:

"error": "invalid_request"
"errorDetails": "prompt is too long: 209117 tokens > 200000 maximum"

The user prompt was ~156 tokens. The Explore system prompt is ~500 tokens. The remaining ~208,000 tokens are tool definitions.

Subagent JSONL evidence (from agent-a4ff9338a6a5a0f09.jsonl):

{
  "error": "invalid_request",
  "errorDetails": "400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"prompt is too long: 209117 tokens > 200000 maximum\"}}"
}

Version: Claude Code v2.1.81, macOS, Claude Max subscription.

Why This Isn't a Duplicate

Previous issues were auto-closed incorrectly:

The underlying problem — subagents receiving all MCP tool schemas regardless of relevance, causing context overflow — remains unfixed.

Proposed Solutions (any would work)

  1. Apply deferred/ToolSearch to subagents — The main session already uses deferred tools (tool names listed, schemas loaded on demand via ToolSearch). Subagents should get the same treatment.
  2. Filter tools by subagent type — Explore agents don't need Canva, Stripe, Discord, etc. Only pass tools relevant to the subagent's declared tool set.
  3. Inherit parent model — If the main session is Opus 1M, subagents should also get 1M context (or at least Sonnet 1M if available on the plan).
  4. Graceful degradation — If tool definitions exceed the subagent's context, prune least-relevant MCP tools rather than failing silently.

Workarounds

  • Pass model: "opus" explicitly on Agent calls (costs more quota)
  • Reduce MCP servers in ~/.claude.json (defeats the purpose of having them)
  • Move servers to project-level configs (tedious, easy to forget)

Impact

Any Claude Max user with 15+ MCP servers will hit this. The failure is completely silent in the TUI — users see "0 tool uses · 0 tokens" and have no idea why. This makes Explore, Plan, and general-purpose agents unusable for power users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions