MCP Tool Search `auto:N` setting measures 0 chars at decision time, loading all tools despite threshold

Resolved 💬 4 comments Opened Jan 20, 2026 by genesiscz Closed Feb 28, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The ENABLE_TOOL_SEARCH=auto:5 setting (which should defer MCP tools when they exceed 5% of context) silently fails because it measures 0 characters of tool definitions at decision time, even though 11 MCP servers have already connected with their tools.

Configuration:

"env": {
  "ENABLE_TOOL_SEARCH": "auto:5"
}

Expected behavior: MCP tools should be deferred and searched on-demand when they exceed 5% of context (25,000 chars threshold).

Actual behavior: All 150+ MCP tools are loaded into context because the tool character count reads "0 chars" at measurement time.

Technical Details

Debug log evidence (from ~/.claude/debug/<session-id>.txt):

2026-01-20T04:11:39.305Z [DEBUG] MCP server "plugin:context7:context7": Starting connection...
2026-01-20T04:11:39.307Z [DEBUG] MCP server "brave-search": Starting connection...
2026-01-20T04:11:39.309Z [DEBUG] MCP server "context7-mcp": Starting connection...
... (all 11 MCP servers connect successfully)
2026-01-20T04:11:53.897Z [DEBUG] MCP server "playwright-test": Connection established...
2026-01-20T04:11:53.900Z [DEBUG] Auto tool search disabled: 0 chars (threshold: 25000, 5% of context)

Root cause: The tool character count is measured before the MCP tools are fully enumerated, resulting in a false "0 chars" reading. The timing shows all MCP servers connected between 04:11:39 and 04:11:53, but the measurement at 04:11:53.900 still shows 0 chars.

MCP Servers Loaded

11 MCP servers successfully connected in this session:

| Server | Type | Tools |
|--------|------|-------|
| brave-search | User-configured | 2 |
| context7-mcp | User-configured | 2 |
| plugin:context7:context7 | Official plugin | 2 |
| jina | User-configured | 6 |
| plugin:github:github | Official plugin | ~50 |
| github | User-configured | ~25 |
| browsermcp | User-configured | ~15 |
| puppeteer | User-configured | 7 |
| playwright | User-configured | ~30 |
| sequential-thinking | User-configured | 1 |
| playwright-test | Project-level | ~40 |

Total: ~180 tools loaded into context despite auto:5 threshold.

Impact

Severity: Medium

  • Significantly increases token usage per request (tools consume context)
  • Defeats the purpose of the auto:N optimization feature
  • Users who configure auto:5 expecting reduced context usage get no benefit
  • May cause context overflow issues with large conversations

Suggested Fix

The tool character count measurement should happen after all MCP servers have reported their tools, not before. Possible approaches:

  1. Wait for MCP enumeration: Delay the auto:N decision until all connected MCP servers have returned their tool lists
  2. Lazy evaluation: Defer the decision and re-evaluate when first tool call is made
  3. Post-connection recalculation: After all MCPs connect, recalculate and potentially defer tools that were initially loaded

What Should Happen?

With ENABLE_TOOL_SEARCH=auto:5:

  • Tool definitions should be counted after MCP servers report their tools
  • If tools exceed 5% of context (25,000 chars), they should be deferred
  • Claude should use tool search to discover relevant tools on-demand
  • Debug log should show actual character count, not "0 chars"

Error Messages/Logs

# Key debug log entries showing the issue:

2026-01-20T04:11:46.073Z [DEBUG] MCP server "plugin:context7:context7": Connection established with capabilities: {"hasTools":true,...}
2026-01-20T04:11:46.451Z [DEBUG] MCP server "browsermcp": Connection established with capabilities: {"hasTools":true,...}
2026-01-20T04:11:46.632Z [DEBUG] MCP server "puppeteer": Connection established with capabilities: {"hasTools":true,...}
2026-01-20T04:11:53.239Z [DEBUG] MCP server "playwright": Connection established with capabilities: {"hasTools":true,...}
2026-01-20T04:11:53.333Z [DEBUG] MCP server "sequential-thinking": Connection established with capabilities: {"hasTools":true,...}
2026-01-20T04:11:53.404Z [DEBUG] MCP server "github": Connection established with capabilities: {"hasTools":true,...}
2026-01-20T04:11:53.897Z [DEBUG] MCP server "playwright-test": Connection established with capabilities: {"hasTools":true,...}

# Decision made immediately after, but shows 0 chars:
2026-01-20T04:11:53.900Z [DEBUG] Auto tool search disabled: 0 chars (threshold: 25000, 5% of context)

# Later in the session, still shows the same issue:
2026-01-20T04:12:16.306Z [DEBUG] Auto tool search disabled: 18509 chars (threshold: 25000, 5% of context)

Note: The later measurement shows 18509 chars (still under 25000 threshold), but this doesn't account for all MCP tools. The measurement appears to be incomplete or timing-dependent.

Steps to Reproduce

  1. Configure multiple MCP servers (5+ servers with total tools > 5% of context)
  2. Set ENABLE_TOOL_SEARCH=auto:5 in settings.json:

``json
"env": {
"ENABLE_TOOL_SEARCH": "auto:5"
}
``

  1. Start a new Claude Code session
  2. Check debug log: ~/.claude/debug/<session-id>.txt
  3. Search for "Auto tool search": grep "Auto tool search" ~/.claude/debug/<session-id>.txt
  4. Observe: "0 chars" or unexpectedly low character count despite many tools loaded

Verification:

# Count MCP tools in system prompt (should be >> 25000 chars if many MCPs)
# But debug shows "0 chars" at decision time

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.12 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

Related observation: There's also a potential issue with duplicate MCP servers - both context7-mcp (user config) and plugin:context7:context7 (official plugin) load, as do both github and plugin:github:github. This doubles tool definitions unnecessarily. A warning for duplicate MCP tool namespaces might be helpful.

View original on GitHub ↗

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