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 problems that compound quickly as tool libraries scale:
For background on the scaling challenges that tool search solves, see Advanced tool use. Tool search's on-demand loading is also an instance of the broader just-in-time retrieval principle described in Effective context engineering.
Although this is provided as a server-side tool, you can also implement your own client-side tool search functionality. See Custom tool search implementation for details.
Share feedback on this feature through the feedback form.
This feature qualifies for Zero Data Retention (ZDR) with limited technical retention. See the Data retention section for details on what is retained and why.
On Amazon Bedrock, server-side tool search is available only via the invoke API, not the converse API.
You can also implement client-side tool search by returning tool_reference blocks from your own search implementation.
There are two tool search variants:
tool_search_tool_regex_20251119): Claude constructs regex patterns to search for toolstool_search_tool_bm25_20251119): Claude uses natural language queries to search for toolsWhen you enable the tool search tool:
tool_search_tool_regex_20251119 or tool_search_tool_bm25_20251119) in your tools listdefer_loading: true for tools that shouldn't be loaded immediatelytool_reference blocksThis keeps your context window efficient while maintaining high tool selection accuracy.
Here's a simple example with deferred tools:
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
}
]
}'The tool search tool has two variants:
{
"type": "tool_search_tool_regex_20251119",
"name": "tool_search_tool_regex"
}{
"type": "tool_search_tool_bm25_20251119",
"name": "tool_search_tool_bm25"
}Regex variant query format: Python regex, NOT natural language
When using tool_search_tool_regex_20251119, Claude constructs regex patterns using Python's re.search() syntax, not natural language queries. Common patterns:
"weather" - matches tool names/descriptions containing "weather""get_.*_data" - matches tools like get_user_data, get_weather_data"database.*query|query.*database" - OR patterns for flexibility"(?i)slack" - case-insensitive searchMaximum query length: 200 characters
BM25 variant query format: Natural language
When using tool_search_tool_bm25_20251119, Claude uses natural language queries to search for tools.
Mark tools for on-demand loading by adding 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
}Key points:
defer_loading are loaded into context immediatelydefer_loading: true are only loaded when Claude discovers them via searchdefer_loading: trueBoth tool search variants (regex and bm25) search tool names, descriptions, argument names, and argument descriptions.
How deferral works internally: Deferred tools are not included in the system-prompt prefix. When the model discovers a deferred tool through tool search, the tool definition is appended inline as a tool_reference block in the conversation. The prefix is untouched, so prompt caching is preserved. The grammar for strict mode builds from the full toolset, so defer_loading and strict mode compose without grammar recompilation.
When Claude uses the tool search tool, the response includes new block types:
{
"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: Indicates Claude is invoking the tool search tooltool_search_tool_result: Contains the search results with a nested tool_search_tool_search_result objecttool_references: Array of tool_reference objects pointing to discovered toolstool_use: Claude invoking the discovered toolThe tool_reference blocks are automatically expanded into full tool definitions before being shown to Claude. You don't need to handle this expansion yourself. It happens automatically in the API as long as you provide all matching tool definitions in the tools parameter.
For configuring mcp_toolset with defer_loading, see MCP connector.
You can implement your own tool search logic (e.g., using embeddings or semantic search) by returning tool_reference blocks from a custom tool. When Claude calls your custom search tool, return a standard tool_result with tool_reference blocks in the content array:
{
"type": "tool_result",
"tool_use_id": "toolu_your_tool_id",
"content": [{ "type": "tool_reference", "tool_name": "discovered_tool_name" }]
}Every tool referenced must have a corresponding tool definition in the top-level tools parameter with defer_loading: true. This approach lets you use more sophisticated search algorithms while maintaining compatibility with the tool search system.
The tool_search_tool_result format shown in the Response format section is the server-side format used internally by Anthropic's built-in tool search. For custom client-side implementations, always use the standard tool_result format with tool_reference content blocks as shown above.
For a complete example using embeddings, see the tool search with embeddings cookbook.
The tool search tool is not compatible with tool use examples. If you need to provide examples of tool usage, use standard tool calling without tool search.
These errors prevent the request from being processed:
All tools deferred:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "All tools have defer_loading set. At least one tool must be non-deferred."
}
}Missing tool definition:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Tool reference 'unknown_tool' has no corresponding tool definition"
}
}Errors during tool execution return a 200 response with error information in the body:
{
"type": "tool_result",
"tool_use_id": "srvtoolu_01ABC123",
"content": {
"type": "tool_search_tool_result_error",
"error_code": "invalid_pattern"
}
}Error codes:
too_many_requests: Rate limit exceeded for tool search operationsinvalid_pattern: Malformed regex patternpattern_too_long: Pattern exceeds 200 character limitunavailable: Tool search service temporarily unavailableFor how defer_loading preserves prompt caching, see Tool use with prompt caching.
The system automatically expands tool_reference blocks throughout the entire conversation history, so Claude can reuse discovered tools in subsequent turns without re-searching.
With streaming enabled, you'll receive tool search events as part of the stream:
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"}}
// Search query streamed
event: content_block_delta
data: {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"query\":\"weather\"}"}}
// Pause while search executes
// Search results streamed
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 continues with discovered toolsYou can include the tool search tool in the Messages Batches API. Tool search operations through the Messages Batches API are priced the same as those in regular Messages API requests.
Server-side tool search (tool_search tool) indexes and stores tool catalog data (tool names, descriptions, and argument metadata) beyond the immediate API response; this catalog data is retained according to Anthropic's standard retention policy. Custom client-side tool search implementations that use the standard Messages API are fully ZDR-eligible.
For ZDR eligibility across all features, see API and data retention.
Good use cases:
When traditional tool calling might be better:
github_, slack_) so that search queries naturally surface the right tool groupTool search tool usage is tracked in the response usage object:
{
"usage": {
"input_tokens": 1024,
"output_tokens": 256,
"server_tool_use": {
"tool_search_requests": 2
}
}
}Full tool catalog with model compatibility and parameters.
Configure MCP toolsets with deferred loading.
Combine tool search with cached tool definitions.
Step-by-step guide for defining tools.
Was this page helpful?