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
The tool search tool is currently in public beta. Include the appropriate beta header for your provider:
tool_reference blocks from your own search implementation.
How tool search works
There are two tool search variants:- Regex (
tool_search_tool_regex_20251119): Claude constructs regex patterns to search for tools - BM25 (
tool_search_tool_bm25_20251119): Claude uses natural language queries to search for tools
- You include a tool search tool (e.g.,
tool_search_tool_regex_20251119ortool_search_tool_bm25_20251119) in your tools list - You provide all tool definitions with
defer_loading: truefor tools that shouldn’t be loaded immediately - Claude sees only the tool search tool and any non-deferred tools initially
- When Claude needs additional tools, it searches using a tool search tool
- The API returns 3-5 most relevant
tool_referenceblocks - These references are automatically expanded into full tool definitions
- Claude selects from the discovered tools and invokes them
Quick start
Here’s a simple example with deferred tools:Tool definition
The tool search tool has two variants:JSON
JSON
BM25 variant query format: Natural languageWhen using
tool_search_tool_bm25_20251119, Claude uses natural language queries to search for tools.Deferred tool loading
Mark tools for on-demand loading by addingdefer_loading: true:
JSON
- Tools without
defer_loadingare loaded into context immediately - Tools with
defer_loading: trueare only loaded when Claude discovers them via search - The tool search tool itself should never have
defer_loading: true - Keep your 3-5 most frequently used tools as non-deferred for optimal performance
regex and bm25) search tool names, descriptions, argument names, and argument descriptions.
Response format
When Claude uses the tool search tool, the response includes new block types:JSON
Understanding the response
server_tool_use: Indicates Claude is invoking the tool search tooltool_search_tool_result: Contains the search results with a nestedtool_search_tool_search_resultobjecttool_references: Array oftool_referenceobjects pointing to discovered toolstool_use: Claude invoking the discovered tool
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.
MCP integration
The tool search tool works with MCP servers. Add the"mcp-client-2025-11-20" beta header to your API request, and then use mcp_toolset with default_config to defer loading MCP tools:
default_config.defer_loading: Set default for all tools from the MCP serverconfigs: Override defaults for specific tools by name- Combine multiple MCP servers with tool search for massive tool libraries
Custom tool search implementation
You can implement your own tool search logic (e.g., using embeddings or semantic search) by returningtool_reference blocks from a custom tool:
JSON
tools parameter with defer_loading: true. This approach lets you use more sophisticated search algorithms while maintaining compatibility with the tool search system.
For a complete example using embeddings, see our tool search with embeddings cookbook.
Error handling
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.
HTTP errors (400 status)
These errors prevent the request from being processed: All tools deferred:Tool result errors (200 status)
Errors during tool execution return a 200 response with error information in the body:JSON
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 unavailable
Common mistakes
defer_loading: true on ALL tools including the search toolFix: Remove defer_loading from the tool search tool:tool_reference points to a tool not in your tools arrayFix: Ensure every tool that could be discovered has a complete definition:- Check tool name and description—Claude searches BOTH fields
- Test your pattern:
import re; re.search(r"your_pattern", "tool_name") - Remember searches are case-sensitive by default (use
(?i)for case-insensitive) - Claude uses broad patterns like
".*weather.*"not exact matches
Prompt caching
Tool search works with prompt caching. Addcache_control breakpoints to optimize multi-turn conversations:
Streaming
With streaming enabled, you’ll receive tool search events as part of the stream:Batch requests
You 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.Limits and best practices
Limits
- Maximum tools: 10,000 tools in your catalog
- Search results: Returns 3-5 most relevant tools per search
- Pattern length: Maximum 200 characters for regex patterns
- Model support: Sonnet 4.0+, Opus 4.0+ only (no Haiku)
When to use tool search
Good use cases:- 10+ tools available in your system
- Tool definitions consuming >10K tokens
- Experiencing tool selection accuracy issues with large tool sets
- Building MCP-powered systems with multiple servers (200+ tools)
- Tool library growing over time
- Less than 10 tools total
- All tools are frequently used in every request
- Very small tool definitions (<100 tokens total)
Optimization tips
- Keep 3-5 most frequently used tools as non-deferred
- Write clear, descriptive tool names and descriptions
- Use semantic keywords in descriptions that match how users describe tasks
- Add a system prompt section describing available tool categories: “You can search for tools to interact with Slack, GitHub, and Jira”
- Monitor which tools Claude discovers to refine descriptions
Usage
Tool search tool usage is tracked in the response usage object:JSON