Skip to content

Analysis: MCP tool search for token cost reduction#815

Open
mistercrunch wants to merge 4 commits into
mainfrom
analyze-mcp-tool-search
Open

Analysis: MCP tool search for token cost reduction#815
mistercrunch wants to merge 4 commits into
mainfrom
analyze-mcp-tool-search

Conversation

@mistercrunch
Copy link
Copy Markdown
Member

Summary

  • Measured the token cost of Agor's 44 MCP tools: ~13,000 tokens per request (~$58.50/mo at Opus rates with 10K req/day)
  • Analyzed FastMCP's tool search pattern and the MCP protocol's notifications/tools/list_changed support
  • Evaluated 4 implementation options (custom search, SDK migration, framework migration, hybrid refactor)
  • Recommends Option D (hybrid refactor): extract tool registry + add search_tools for on-demand discovery
  • Expected result: 88-96% token reduction (~1,500 tokens vs 13,000), decoupled from tool count growth
  • Includes working prototype implementation for tool-search.ts

See MCP_TOOL_SEARCH_ANALYSIS.md for the full analysis.

Test plan

  • Review analysis accuracy (token estimates, cost projections)
  • Validate prototype search logic against real tool queries
  • Confirm notifications/tools/list_changed works with Claude Code in practice
  • Decide on alwaysVisible tool set

🤖 Generated with Claude Code

mistercrunch and others added 4 commits March 22, 2026 22:58
Analyzes the ~13K token overhead of Agor's 44 MCP tools sent with every
API call. Evaluates FastMCP's tool search pattern and recommends a hybrid
approach (Option D) that extracts tool definitions into a registry and
adds search_tools for on-demand discovery — yielding 88-96% token reduction
with minimal risk. Includes prototype implementation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds detailed comparison of official SDK, FastMCP (TS), and mcp-framework
for "plugin into existing server" use case. Only the official SDK cleanly
mounts into Express. Updates recommendation to Option D (phased): tool
search now, SDK migration later. Adds decision matrix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After deeper analysis of the SDK's RegisteredTool API (enable/disable/
remove/update/sendToolListChanged), the SDK migration IS the tool search
implementation. Discovered tools become first-class tools via enable() +
sendToolListChanged() — strictly better than FastMCP's call_tool proxy.

Decomposed into 4 phases:
1. SDK scaffolding + Express mount (0.5 day)
2. Migrate 44 tools to Zod schemas + annotations (2-3 days)
3. Add search_tools with enable/disable pattern (1 day)
4. Configuration + backwards compat (0.5 day)

Also adds FastMCP vs SDK comparison table, tool annotation decisions,
and new file structure (10 domain files replacing 4,300-line monolith).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Key discovery: Anthropic shipped tool_search_tool as a first-class API
feature. Claude Code already auto-enables it when MCP tools exceed 10K
tokens — meaning Agor sessions already benefit from ~85% token reduction
without any server-side changes.

Three layers of tool search now documented:
1. Claude Code client-side (automatic, already working)
2. Messages API defer_loading (for Agent SDK, not yet used)
3. MCP Server enable/disable (requires SDK migration)

Also adds references to SEP-1821 (dynamic tool discovery), SEP-1888
(progressive disclosure), and third-party approaches (Speakeasy, mcp2cli,
ToolHive, Redis).

SDK migration recommendation stands but for different reasons: architecture
cleanup, tool annotations, Zod validation, non-Claude agent support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant