2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Code の MCP トークン使用量を削減する - Tool search tool の活用

Posted at

はじめに

MCP のツール定義は,
多くのトークンを消費しコンテキストを圧迫してしまうことがあります.

コンテキストをより効率的に使用するため,
今回は Claude Code で Tool search tool を使う方法を試してみます.

The tool search tool enables Claude to work with hundreds or thousands of tools by dynamically discovering and loading them on-demand. Instead of loading all tool definitions into the context window upfront, Claude searches your tool catalog—including tool names, descriptions, argument names, and argument descriptions—and loads only the tools it needs.

This approach solves two critical challenges as tool libraries scale:

  • Context efficiency: Tool definitions can consume massive portions of your context window (50 tools ≈ 10-20K tokens), leaving less room for actual work
  • Tool selection accuracy: Claude's ability to correctly select tools degrades significantly with more than 30-50 conventionally-available tools

前提

  • Claude Code v2.0.76 を使用
  • MCP サーバとして以下の2つを登録
    • chrome-devtools
    • codex

スクリーンショット 2026-01-07 18.25.01.png

Tool search tool 無効(デフォルト)

MCP tools だけで 19.8k tokens (9.9%) を消費しており,
MCP のツール定義がコンテキストを大きく占有していることがわかります.

スクリーンショット 2026-01-07 18.26.01.png

Tool search tool 有効化

以下のように環境変数を指定して claude を起動するだけです.

$ ENABLE_TOOL_SEARCH=true claude

MCP tools が loaded on-demand となり,
MCP のツール定義が初期コンテキストに含まれていないことが確認できます.
その結果, Free space は 117k → 136k に増加しました.

スクリーンショット 2026-01-07 18.28.47.png

ツール使用後のコンテキストを確認

Tool search tool を有効化した状態で,
chrome-devtools を実際に使用した場合の挙動を確認します.

スクリーンショット 2026-01-07 18.54.30.png

スクリーンショット 2026-01-07 18.55.11.png

スクリーンショット 2026-01-07 18.56.40.png

当初は mcp__chrome-devtools__* すべて読み込まれると想定していましたが,
実際には指示に対して必要なツールのみが読み込まれました.

まとめ

  • Tool search tool を有効化することで, MCP ツール定義による初期コンテキスト消費を大幅に削減できる
  • ツール使用時も, 必要最小限のツールだけが読み込まれる
  • 多数の MCP ツールを登録している環境では特に有効な設定といえる
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?