MCP tool search: load tool definitions only when the agent needs them
On this page
MCP tool search keeps most tool definitions out of the model’s context until it asks for them. The client marks tools as deferred, gives the model a search tool, and loads full definitions only for the tools that match. On the Claude API that is the tool search tool with defer_loading: true; Claude Code does it for MCP tools by default; OpenAI’s Responses API, Codex, Cursor and VS Code each have their own version. It fixes the cost of connecting many servers, at the price of an extra step and of tools the model misses when they are poorly described.
Checked as of November 2026 against Anthropic’s tool search tool docs, MCP connector docs, advanced tool use post, the Claude Code MCP docs, OpenAI’s tool search guide and Codex configuration reference, Cursor’s dynamic context discovery post, VS Code’s agent tools docs and the MCP tools specification (revision 2026-07-28).
Why many MCP servers hurt
An MCP client calls tools/list on each server and, without deferral, puts every name, description and input schema into the model’s context on every request. Anthropic’s advanced tool use post measured a five-server setup: 58 tools took about 55K tokens before the conversation started. GitHub’s 35 tools were about 26K of that and Slack’s 11 tools about 21K. Anthropic has seen definitions reach 134K tokens internally.
The cost is more than tokens:
- Selection gets worse. The tool search docs say Claude’s ability to pick the right tool “degrades once you exceed 30–50 available tools.”
- Clients refuse large lists. VS Code’s local agent fails with “Cannot have more than 128 tools per request.”
- Names collide. The specification scopes tool-name uniqueness to one server and tells aggregating clients to disambiguate, for example with a server prefix.
Context engineering covers the rest of the context budget.
How tool search works
Every implementation defers tools, lets the model search and loads the matches. They differ in what the model sees first.
| Implementation | Visible before search | How the model searches |
|---|---|---|
| Claude API tool search tool | The search tool and any non-deferred tools | Regex pattern or natural-language query, run by Anthropic |
| Claude Code | Tool names and server instructions | The built-in ToolSearch tool |
OpenAI Responses API tool_search | Name and description of each deferred namespace or MCP server; name and description of each deferred function | Hosted search, or your own code in client mode |
| Cursor | Tool names, with descriptions synced to a folder | The agent reads the folder when a task needs a tool |
The Claude API tool search tool
The tool search tool has two variants. tool_search_tool_regex_20251119 has Claude write Python re.search() patterns, matched case-insensitively, up to 200 characters. tool_search_tool_bm25_20251119 takes natural-language queries up to 500 characters. Both search tool names, descriptions, argument names and argument descriptions.
You still send every definition in tools. defer_loading controls what enters the context window, not what goes in the request:
{
"tools": [
{ "type": "tool_search_tool_bm25_20251119", "name": "tool_search_tool_bm25" },
{
"name": "github_create_issue",
"description": "Create a GitHub issue in a repository",
"input_schema": {
"type": "object",
"properties": {
"repo": { "type": "string" },
"title": { "type": "string" }
},
"required": ["repo", "title"]
},
"defer_loading": true
}
]
}
A search appears in the response as a server_tool_use block followed by a tool_search_tool_result holding tool_reference blocks. The API expands each reference into the full definition, Claude calls the tool with an ordinary tool_use, and discovered tools stay usable in later turns.
Limits and details from the docs:
- Up to 10,000 deferred tools per request; each search returns 5 by default, and Claude can set
limitup to 10,000. - At least one tool must be non-deferred, normally the search tool. Deferring everything returns a 400.
- Deferred tools stay out of the cached system-prompt prefix and are expanded inline, so discovering one doesn’t invalidate the cache. A deferred tool can’t carry
cache_control. - Search isn’t metered separately; loaded definitions count as input tokens.
- Supported on Claude Opus 4.5, Sonnet 4.5, Haiku 4.5 and later. Opus 4.1 and earlier don’t support it.
A custom search, for example over embeddings, can return tool_reference blocks from your own tool’s tool_result. In Anthropic’s November 2025 internal MCP evaluations, enabling tool search raised Opus 4 accuracy from 49% to 74% and Opus 4.5 from 79.5% to 88.1%.
With the MCP connector
When tools come from a remote server through the MCP connector (beta header mcp-client-2025-11-20), you set defer_loading on the mcp_toolset instead of on individual definitions. Per-tool configs override default_config, so you can defer a whole server and keep its most used tool loaded:
{
"mcp_servers": [
{ "type": "url", "url": "https://mcp.example.com/mcp", "name": "tracker", "authorization_token": "..." }
],
"tools": [
{ "type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex" },
{
"type": "mcp_toolset",
"mcp_server_name": "tracker",
"default_config": { "defer_loading": true },
"configs": { "search_issues": { "defer_loading": false } }
}
]
}
"enabled": false in the same place disables a tool. Anthropic’s guidance is to keep your three to five most used tools non-deferred.
Tool search in Claude Code
Claude Code’s MCP tool search is on by default. Only tool names and server instructions load at session start, and Claude uses its ToolSearch tool to load definitions when a task needs them.
Where the provider and model support it (the docs list exceptions, such as Microsoft Foundry hosted on Azure, which loads tools upfront), the ENABLE_TOOL_SEARCH environment variable controls it:
| Value | Behavior |
|---|---|
unset or true | MCP tools deferred and loaded on demand |
auto | Tools load upfront while their definitions total under 10% of the context window; at 10% or more, tool search turns on, and tools can stay deferred for the rest of the session |
auto:N | Same, with a custom percentage, for example auto:5 |
false | All MCP tools load upfront |
ENABLE_TOOL_SEARCH=auto:5 claude
A few related controls:
"alwaysLoad": trueon a server in.mcp.jsonloads that server’s tools upfront regardless of the setting. A server author can ask for the same per tool with"anthropic/alwaysLoad": truein the tool’s_meta.- Denying
ToolSearchinpermissions.denyloads MCP tools upfront instead. - Tool search runs on Claude Opus 4, Sonnet 4, Haiku 4.5 and later; on earlier models everything loads upfront. Setting
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETASkeeps it off. - An LLM gateway set with
ANTHROPIC_BASE_URLmust forward theanthropic-betaheader,defer_loadingfields andtool_referenceblocks.
Server instructions matter more with deferral, because Claude reads them before deciding to search. The docs ask server authors to state what tasks the tools handle and when to search for them. Claude Code cuts server instructions and upfront tool descriptions at 4,096 characters, and descriptions loaded through search at 16,384. Search matches only within the shorter limit, so put the searchable words first.
Deferred tools keep their mcp__<server>__<tool> names, so permission rules apply as before. /context labels deferred tools (deferred) or (loaded on-demand).
What other clients do
OpenAI Responses API. Add {"type": "tool_search"} and set defer_loading: true on functions, on functions inside a namespace, or on an MCP server tool definition. Only gpt-5.4 and later support it. Search is hosted, or in client mode your code answers each tool_search_call. OpenAI recommends deferring namespaces or MCP servers rather than single functions, since a deferred function still shows its name and description. In the Agents API, MCP tools are deferred automatically when the model supports it.
Codex. The configuration reference describes three surfaces a server’s tools can reach: direct (initial tools), deferred (tool search) and code_mode. mcp_servers.<id>.omit_tools_from removes a server’s tools from any of them, and disabled_tools blocks a tool outright. Codex also compacts any MCP input schema larger than tool_input_schema_max_bytes, 5,000 bytes by default.
Cursor. Cursor’s January 2026 post says it syncs MCP tool descriptions to a folder and starts the agent with only the tool names. In an A/B test on runs that called an MCP tool, this “reduced total agent tokens by 46.9%.”
VS Code. Besides deselecting tools to stay under 128, the experimental github.copilot.chat.virtualTools.threshold setting groups tools for on-demand discovery; 0 turns grouping off.
The server-side alternative: meta-tools
A server or gateway can do the search itself: expose a few tools such as search_tools, describe_tool and call_tool instead of hundreds. It works in any client, and the upfront cost stays flat as the catalog grows. The tradeoffs:
- More round trips. Search, describe and call take three model turns where a direct tool takes one.
- The model can’t use what it doesn’t search for. With direct tools, a well-named tool can catch the model’s attention; behind a search tool, a vague query misses it.
- Permission rules lose their grip. Client rules are keyed on tool names. A Claude Code rule for
mcp__catalog__call_toolcovers every tool behind it, settings-file rules can’t match on arguments, and an approval prompt namescall_toolwith the real tool hidden in its arguments. - Annotations and schemas get hidden. A client can’t read
readOnlyHintor validate input for a tool it only sees as an argument.
Client-side tool search avoids most of this because the real tool is still called by its real name. Two related approaches skip per-tool calls: programmatic tool calling lets Claude call tools from code so intermediate results stay out of context, and Code Mode gives the model one code-execution tool against a typed API.
Writing tools that search can find
Anthropic’s docs suggest prefixing names by service or resource (github_, slack_) so one search matches the group, using the words users would use, and naming the available tool categories in the system prompt. In practice:
- Lead the description with the verb and object: “Search issues by text, label or assignee” beats “A flexible tool for many tracker operations.”
- Use the words people type: if users say “ticket,” put it in the description of
create_issue. - Name arguments plainly; both Claude variants search them.
- Write server instructions that state when to search: “Use for bugs, issues and sprint planning in the Acme tracker.”
Tool use examples work with search: a deferred tool’s input_examples load along with its definition.
Measuring the token cost of your tool list
Save a server’s tools/list result, for example with the MCP Inspector CLI, convert it to Claude’s tool format and send it to the free token counting endpoint:
npx @modelcontextprotocol/inspector --cli https://mcp.example.com/mcp \
--transport http --method tools/list > tools.json
jq '{model: "claude-opus-5-5",
messages: [{role: "user", content: "hi"}],
tools: [.tools[] | {name: (.name | gsub("[^A-Za-z0-9_-]"; "_")),
description: (.description // ""), input_schema: .inputSchema}]}' \
tools.json > request.json
curl -s https://api.anthropic.com/v1/messages/count_tokens \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d @request.json | jq .input_tokens
The gsub maps characters MCP allows in names, such as dots, to underscores, since Claude’s tool names are stricter. If two names collide after mapping, such as files.list and files_list, rename one before sending; the API needs unique names. Run it again without tools and subtract. The endpoint rejects tool search and the MCP connector, so count plain definitions, against the model you use. In Claude Code, /context shows the current session.
When you don’t need tool search
Anthropic recommends standard tool calling when you have fewer than 10 tools, when every tool is used in every request, or when the definitions are small. The search step adds latency, and a tool needed in every conversation costs a search before its first use in each one. Keep a small, always-used set loaded, and remove tools the agent never uses: a tool that isn’t listed costs nothing. MCP vs CLI and MCP vs Agent Skills compare the context cost of those alternatives.
How this relates to Toolstile
Toolstile is a managed MCP gateway. Each connection’s tools appear as <namespace>__<upstream name>, for example linear__get_issue, with upstream descriptions and schemas unchanged, so client-side search matches the upstream text and the prefix groups each connection’s tools. Per-agent rules allow, block or require approval for each tool, and blocked tools aren’t listed, so blocking what an agent never needs shrinks its list before any client-side search runs. The built-in read-only tools search_catalog and get_catalog_entry search the connector catalog, reading nothing from connections, and get_my_access summarizes the agent’s configured access: each connection, whether a full-access rule applies (blocks still win) or which tools are granted, and which need approval; tools/list shows what is visible right now. Tool review hides new or changed tool definitions until someone accepts them, the gateway advertises tools.listChanged so clients can refresh, and every forwarded call is logged. The Claude Code setup guide covers connecting it, and the MCP allowlist guide covers client-side controls.