Sub-agents inherit all MCP tools causing 'Prompt is too long' errors

Resolved 💬 3 comments Opened Mar 26, 2026 by JeremyBB Closed Mar 30, 2026

Problem

When a user has multiple MCP servers configured (globally or via plugins), all MCP tools are injected into sub-agent prompts, even when the agent definition explicitly restricts its tools (e.g., tools: Read, Glob, Grep, Bash).

This causes Prompt is too long errors, making sub-agents unusable in environments with many MCPs connected.

Reproduction

  1. Configure 5+ MCP servers (e.g., PostHog, Notion, Stripe, Supabase, Vercel, Gmail, Google Calendar, etc.)
  2. Launch a conversation — works fine in the main context
  3. Spawn a sub-agent (e.g., built-in Explore, or a custom agent with tools: Read, Glob, Grep, Bash)
  4. Agent immediately fails with Prompt is too long / total_tokens: 0

Expected behavior

Sub-agents should only receive the tools declared in their definition. MCP tools should not be injected into agents that don't need them.

Current workaround

Use custom agents (defined in ~/.claude/agents/) with explicit tools: restrictions instead of built-in agent types like Explore. Custom agents with restricted tool lists seem to avoid the bloat in some cases, but not reliably.

Suggested solution

One or more of:

  • Respect agent tool restrictions: if an agent declares tools: Read, Glob, Grep, Bash, don't inject MCP tools
  • Lazy-load MCPs for sub-agents: only inject MCP tools when the agent actually needs them
  • Per-agent MCP scoping: allow agent definitions to opt-in/out of specific MCPs (e.g., mcps: none or mcps: [posthog, stripe])
  • Project-level MCP overrides: allow .claude/.mcp.json per project to disable global MCPs

Environment

  • Claude Code on Windows 11
  • ~15 MCP servers connected (mix of global, plugins, and Desktop-shared)
  • ~200+ total MCP tools loaded per session
  • Custom agents defined in ~/.claude/agents/ with restricted tools: field

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗