Sub-agents inherit all MCP tools causing 'Prompt is too long' errors
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
- Configure 5+ MCP servers (e.g., PostHog, Notion, Stripe, Supabase, Vercel, Gmail, Google Calendar, etc.)
- Launch a conversation — works fine in the main context
- Spawn a sub-agent (e.g., built-in
Explore, or a custom agent withtools: Read, Glob, Grep, Bash) - 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: noneormcps: [posthog, stripe]) - Project-level MCP overrides: allow
.claude/.mcp.jsonper 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 restrictedtools:field
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗