Was this page helpful?
ツール検索ツールは、Claudeが数百から数千のツールを動的に検出し、オンデマンドで読み込むことを可能にします。すべてのツール定義を事前にコンテキストウィンドウに読み込む代わりに、Claudeがツールカタログ(ツール名、説明、引数名、引数の説明を含む)を検索し、必要なツールのみを読み込みます。
このアプローチは、ツールライブラリが拡大する際の2つの重要な課題を解決します:
これはサーバーサイドツールとして提供されていますが、独自のクライアントサイドツール検索機能を実装することもできます。詳細はカスタムツール検索の実装をご覧ください。
この機能に関するフィードバックをフィードバックフォームからお寄せください。
サーバーサイドツール検索はゼロデータリテンション(ZDR)の対象外です。データは機能の標準保持ポリシーに従って保持されます。カスタムクライアントサイドツール検索の実装は標準のMessages APIを使用し、ZDRの対象となります。
Amazon Bedrockでは、サーバーサイドツール検索はinvoke API経由でのみ利用可能で、 converse APIでは利用できません。
独自の検索実装からtool_referenceブロックを返すことで、クライアントサイドツール検索を実装することもできます。
ツール検索には2つのバリアントがあります:
tool_search_tool_regex_20251119):Claudeが正規表現パターンを構築してツールを検索しますtool_search_tool_bm25_20251119):Claudeが自然言語クエリを使用してツールを検索しますツール検索ツールを有効にすると:
tool_search_tool_regex_20251119またはtool_search_tool_bm25_20251119)を含めますdefer_loading: trueを付けてすべてのツール定義を提供しますtool_referenceブロックを返しますこれにより、高いツール選択精度を維持しながら、コンテキストウィンドウを効率的に保ちます。
遅延ツールを使用した簡単な例を示します:
ツール検索ツールには2つのバリアントがあります:
{
"type": "tool_search_tool_regex_20251119",
"name": "tool_search_tool_regex"
}{
"type": "tool_search_tool_bm25_20251119",
"name": "tool_search_tool_bm25"
}Regexバリアントのクエリ形式:Python正規表現であり、自然言語ではありません
tool_search_tool_regex_20251119を使用する場合、ClaudeはPythonのre.search()構文を使用して正規表現パターンを構築します。自然言語クエリではありません。一般的なパターン:
"weather" - "weather"を含むツール名/説明にマッチ"get_.*_data" - get_user_data、get_weather_dataなどのツールにマッチ"database.*query|query.*database" - 柔軟性のためのORパターン"(?i)slack" - 大文字小文字を区別しない検索最大クエリ長:200文字
BM25バリアントのクエリ形式:自然言語
tool_search_tool_bm25_20251119を使用する場合、Claudeは自然言語クエリを使用してツールを検索します。
defer_loading: trueを追加して、オンデマンド読み込み用にツールをマークします:
{
"name": "get_weather",
"description": "Get current weather for a location",
"input_schema": {
"type": "object",
"properties": {
"location": { "type": "string" },
"unit": { "type": "string", "enum": ["celsius", "fahrenheit"] }
},
"required": ["location"]
},
"defer_loading": true
}重要なポイント:
defer_loadingのないツールはすぐにコンテキストに読み込まれますdefer_loading: trueのツールは、Claudeが検索で検出した場合にのみ読み込まれますdefer_loading: trueを設定しないでください両方のツール検索バリアント(regexとbm25)は、ツール名、説明、引数名、引数の説明を検索します。
Claudeがツール検索ツールを使用すると、レスポンスに新しいブロックタイプが含まれます:
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "I'll search for tools to help with the weather information."
},
{
"type": "server_tool_use",
"id": "srvtoolu_01ABC123",
"name": "tool_search_tool_regex",
"input": {
"query": "weather"
}
},
{
"type": "tool_search_tool_result",
"tool_use_id": "srvtoolu_01ABC123",
"content": {
"type": "tool_search_tool_search_result",
"tool_references": [{ "type": "tool_reference", "tool_name": "get_weather" }]
}
},
{
"type": "text",
"text": "I found a weather tool. Let me get the weather for San Francisco."
},
{
"type": "tool_use",
"id": "toolu_01XYZ789",
"name": "get_weather",
"input": { "location": "San Francisco", "unit": "fahrenheit" }
}
],
"stop_reason": "tool_use"
}server_tool_use: Claudeがツール検索ツールを呼び出していることを示しますtool_search_tool_result: ネストされたtool_search_tool_search_resultオブジェクトを含む検索結果ですtool_references: 検出されたツールを指すtool_referenceオブジェクトの配列ですtool_use: Claudeが検出されたツールを呼び出していますtool_referenceブロックは、Claudeに表示される前に自動的に完全なツール定義に展開されます。この展開を自分で処理する必要はありません。toolsパラメータに一致するすべてのツール定義を提供していれば、API内で自動的に行われます。
ツール検索ツールはMCPサーバーと連携します。APIリクエストに"mcp-client-2025-11-20"ベータヘッダーを追加し、mcp_toolsetとdefault_configを使用してMCPツールの読み込みを遅延させます:
MCP設定オプション:
default_config.defer_loading: MCPサーバーからのすべてのツールのデフォルトを設定configs: 名前で特定のツールのデフォルトをオーバーライドカスタムツールからtool_referenceブロックを返すことで、独自のツール検索ロジック(例:埋め込みやセマンティック検索を使用)を実装できます。Claudeがカスタム検索ツールを呼び出すと、コンテンツ配列にtool_referenceブロックを含む標準のtool_resultを返します:
{
"type": "tool_result",
"tool_use_id": "toolu_your_tool_id",
"content": [
{ "type": "tool_reference", "tool_name": "discovered_tool_name" }
]
}参照されるすべてのツールは、トップレベルのtoolsパラメータにdefer_loading: trueを付けた対応するツール定義が必要です。このアプローチにより、ツール検索システムとの互換性を維持しながら、より高度な検索アルゴリズムを使用できます。
レスポンス形式セクションに示されているtool_search_tool_result形式は、Anthropicの組み込みツール検索が内部的に使用するサーバーサイド形式です。カスタムクライアントサイド実装では、上記のようにtool_referenceコンテンツブロックを含む標準のtool_result形式を常に使用してください。
埋め込みを使用した完全な例については、埋め込みを使用したツール検索クックブックをご覧ください。
ツール検索ツールはツール使用の 例と互換性がありません。 ツール使用の例を提供する必要がある場合は、ツール検索なしの標準的なツール呼び出しを 使用してください。
これらのエラーはリクエストの処理を妨げます:
すべてのツールが遅延されている場合:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "All tools have defer_loading set. At least one tool must be non-deferred."
}
}ツール定義が見つからない場合:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Tool reference 'unknown_tool' has no corresponding tool definition"
}
}ツール実行中のエラーは、ボディにエラー情報を含む200レスポンスを返します:
{
"type": "tool_result",
"tool_use_id": "srvtoolu_01ABC123",
"content": {
"type": "tool_search_tool_result_error",
"error_code": "invalid_pattern"
}
}エラーコード:
too_many_requests: ツール検索操作のレート制限を超過invalid_pattern: 不正な正規表現パターンpattern_too_long: パターンが200文字の制限を超過unavailable: ツール検索サービスが一時的に利用不可ツール検索はプロンプトキャッシングと連携します。cache_controlブレークポイントを追加して、マルチターン会話を最適化します:
import anthropic
client = anthropic.Anthropic()
# ツール検索を使用した最初のリクエスト
messages = [{"role": "user", "content": "What's the weather in Seattle?"}]
response1 = client.messages.create(
model="claude-opus-4-6",
max_tokens=2048,
messages=messages,
tools=[
{"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"},
{
"name": "get_weather",
"description": "Get weather for a location",
"input_schema": {
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"],
},
"defer_loading": True,
},
],
)
# Claudeのレスポンスを会話に追加
messages.append({"role": "assistant", "content": response1.content})
# キャッシュブレークポイントを含む2番目のリクエスト
messages.append(
{
"role": "user",
"content": "What about New York?",
"cache_control": {"type": "ephemeral"},
}
)
response2 = client.messages.create(
model="claude-opus-4-6",
max_tokens=2048,
messages=messages,
tools=[
{"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"},
{
"name": "get_weather",
"description": "Get weather for a location",
"input_schema": {
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"],
},
"defer_loading": True,
},
],
)
print(f"Cache read tokens: {response2.usage.get('cache_read_input_tokens', 0)}")システムは会話履歴全体でtool_referenceブロックを自動的に展開するため、Claudeは再検索することなく、後続のターンで検出されたツールを再利用できます。
ストリーミングを有効にすると、ツール検索イベントがストリームの一部として受信されます:
event: content_block_start
data: {"type": "content_block_start", "index": 1, "content_block": {"type": "server_tool_use", "id": "srvtoolu_xyz789", "name": "tool_search_tool_regex"}}
// 検索クエリがストリーミングされる
event: content_block_delta
data: {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"query\":\"weather\"}"}}
// 検索実行中の一時停止
// 検索結果がストリーミングされる
event: content_block_start
data: {"type": "content_block_start", "index": 2, "content_block": {"type": "tool_search_tool_result", "tool_use_id": "srvtoolu_xyz789", "content": {"type": "tool_search_tool_search_result", "tool_references": [{"type": "tool_reference", "tool_name": "get_weather"}]}}}
// Claudeが検出されたツールで続行Messages Batches APIにツール検索ツールを含めることができます。Messages Batches APIを通じたツール検索操作は、通常のMessages APIリクエストと同じ価格設定です。
適したユースケース:
従来のツール呼び出しの方が適している場合:
ツール検索ツールの使用量はレスポンスのusageオブジェクトで追跡されます:
{
"usage": {
"input_tokens": 1024,
"output_tokens": 256,
"server_tool_use": {
"tool_search_requests": 2
}
}
}curl https://api.anthropic.com/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--data '{
"model": "claude-opus-4-6",
"max_tokens": 2048,
"messages": [
{
"role": "user",
"content": "What is the weather in San Francisco?"
}
],
"tools": [
{
"type": "tool_search_tool_regex_20251119",
"name": "tool_search_tool_regex"
},
{
"name": "get_weather",
"description": "Get the weather at a specific location",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string"},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
},
"defer_loading": true
},
{
"name": "search_files",
"description": "Search through files in the workspace",
"input_schema": {
"type": "object",
"properties": {
"query": {"type": "string"},
"file_types": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["query"]
},
"defer_loading": true
}
]
}'curl https://api.anthropic.com/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "anthropic-beta: mcp-client-2025-11-20" \
--header "content-type: application/json" \
--data '{
"model": "claude-opus-4-6",
"max_tokens": 2048,
"mcp_servers": [
{
"type": "url",
"name": "database-server",
"url": "https://mcp-db.example.com"
}
],
"tools": [
{
"type": "tool_search_tool_regex_20251119",
"name": "tool_search_tool_regex"
},
{
"type": "mcp_toolset",
"mcp_server_name": "database-server",
"default_config": {
"defer_loading": true
},
"configs": {
"search_events": {
"defer_loading": false
}
}
}
],
"messages": [
{
"role": "user",
"content": "What events are in my database?"
}
]
}'