Blog / Agent-ready tools / MCP design
How to optimise your MCP tools by knowing how agents call them
If an agent cannot find your tool, the rest of your documentation cannot help. Once it finds the tool, every description, result and error helps shape what it does next.
The lesson: design your MCP around the user's job, from discovery to completion. Then test that journey in the environments your users actually run.
How Claude, Codex, Grok and OpenCode find your tools
The server exposed 99 tools. The following snapshots show what the inspected versions revealed to the model. They illustrate the mechanism; they are not universal costs or guarantees.
Claude Code 2.1.301
- Start: the model gets 113 tool names in a reminder (~1,258 tokens). No schemas.
- Model calls
ToolSearchwithselect:and three exact names. Three full definitions (~573 each) are added as real tools. - Model calls the tool directly. Results over 25,000 tokens are saved to a file instead.
Codex 0.161.0
- Start: only
execand friends (first request 15,383). Not one MCP tool name. - Model filters metadata with JS, for example
ALL_TOOLS.filter(t => /server/i.test(t.name + " " + t.description))(anonymized). Output is 56,619 tokens; Codex cuts it to 11,244. - Two narrower filters add 1,777 and 3,030.
- Model calls
await tools.mcp__server__tool(…)insideexec.
Grok Build 1.0.60
- Start: a 189-token reminder: which servers, how many tools. No names.
- Model runs
search_tool. Local BM25 returns the full schema of all 10 hits (4,957). - Three more searches to check alternatives (4,313 + 3,143 + 2,349).
- Model calls
use_tool({tool_name, tool_input}). Schemas stay as text in history.
OpenCode 1.18.34
- Start: all 99 definitions, 63,245 tokens, in the first request.
- The model picks a tool directly. Nothing to find.
- Every following request carries the same 63,245 again.
OpenCode 2.0.31
- Start: a "partial catalog" listing 16 of the 99 tools with one-line descriptions (881 tokens), plus a
search()function usable insideexecute. Whole first request: about 5,270 tokens. - Model runs
search({query, namespace})insideexecute. It gets back 10 or 15 hits with full signatures: 2,879 and 5,059 tokens in the follow-up captures. - Model calls the tool from code. Only what the code prints or returns reaches the model. A filtered answer was 188 tokens, although the code pulled 2.4 MB from the server.
- If the code returns a whole result, OpenCode keeps the first 51,200 bytes (14,098 tokens here) and saves the rest to a file.
We repeatedly tested production read-only jobs with Claude Code, Codex and OpenCode, and inspected tool-discovery behavior across those agents and Grok Build. The server had 99 tools and returned correct data. Agents could still miss the tools, misread a result or take a long recovery path.
Read more: whether a CLI beats an MCP server for the same jobs, 40 runs in Claude Code and Codex, is in MCP server or CLI for AI agents?
1. Match tool names to user intent and vocabulary
The user describes a job. The model turns that request into a tool choice or a search query. Your tool has to be discoverable through the words the model chooses.
In the versions we inspected, Claude Code initially saw tool names and selected definitions to load. Codex wrote code to filter tool metadata. Grok Build used BM25 keyword ranking. OpenCode 1.x loaded all definitions, while OpenCode 2 started with a partial catalog and searched for the rest.
Read more: what the same 99 tools cost in each app, from +0 to +107,541 tokens per request, is in how many MCP tools is too many?
The model may understand synonyms; the search it invokes may still require a literal or lexical match. If a user asks to send a bill, the model might search for bill, invoice or send. A name like ledger_dispatch makes that connection harder. A name like invoice_send, paired with a description that includes “bill,” gives it clearer paths.
Illustrative rewrite
Before ledger_dispatch “Dispatches the document to the configured recipient.” After invoice_send “Email an invoice (bill) to a customer. Requires an existing invoice ID.”
Start with the language in support questions, onboarding calls and actual user prompts. Include useful synonyms naturally. Avoid repeating unrelated keywords across every tool: that creates competing matches and makes selection harder.
Test paraphrases of the same job, including requests that do not mention your product. Inspect the search terms and candidate tools the agent actually saw. A missed discovery is evidence of a broken path; it is not automatically proof that renaming a tool will fix it.
Read more: how each app loads your tools, captured on the wire, is in how AI agents load MCP tools; how Codex searches them is in how Codex finds MCP tools.
2. Put essential meaning in the first line
An excellent description is useful only if the agent sees the relevant part. Before a tool is selected, a client may expose names alone, a short description snippet, or matching metadata. Full schemas may arrive later.
In our OpenCode 2.0.31 capture, the initial catalog included 16 of the 99 tools, with descriptions shortened to roughly 120 characters. Claude Code 2.1.301 initially exposed names rather than full descriptions. There is no universal “first N characters” limit across agents. Inspect the catalog and search results in each environment.
Make the opening stand on its own:
[User vocabulary + action]. [Essential prerequisite or constraint]. “Email an invoice (bill) to a customer. Requires an existing invoice ID.”
Put purpose and the constraint most likely to cause a wrong call before background detail. Keep longer examples and edge cases available after that opening. Do not spend the visible prefix on boilerplate such as “This tool provides functionality that allows…”
For a multi-step job, a discoverable get_instructions(job) tool can expose a compact playbook. But adding the tool alone does not make an agent call it. Its entry point must be visible in the channels that client actually loads.
3. Use every output to guide the next useful step
Tool output is part of prompt design. The model reads it before deciding what to do next. A response that only dumps data leaves the agent to reconstruct your workflow. A useful response explains what happened, what it means for the job and how to proceed.
Design the journey across successful calls, empty results, incomplete work and errors. Keep the guidance close to the data the agent will actually receive.
Success: provide a conditional continuation
{
"summary": "20 of 47 matching invoices returned",
"items": ["…compact records…"],
"next_cursor": "c_20",
"next_step": "If you need the remaining invoices, call invoice_list with cursor c_20."
}Failure: explain the cause and the repair
{
"error": "groupId does not identify an available group",
"next_step": "Call groups_list, choose the group matching the user's request, then retry with its ID.",
"retryable": true
}These are illustrative response bodies, not MCP protocol envelopes. Use your actual tool names and arguments. Mark tool execution failures appropriately, and put essential guidance in the representation your target client exposes to the model.
Be explicit about completion too: “The draft is saved; no email has been sent” communicates a different state from “The invoice was sent.” A next step should advance the user's goal, not manufacture extra work or authorize an action the user did not request.
Repeat critical workflow guidance where it is needed. If an agent can enter through several tools, each response can remind it of the relevant next step. The useful repetition is short and specific to the current state, rather than a full manual pasted into every result.
Tool annotations can also describe read-only, destructive and idempotent behavior. Treat them as hints to the client, not guarantees of confirmation or retry behavior. Describe the real operation accurately, and make necessary workflow constraints explicit in tool behavior and results.
Read more: how to make agents fetch your playbook before anything else, 24 of 24 runs in Claude Code and Codex on a mock server, is in make the agent read your playbook first.
4. Keep results small and measure what the model sees
A default list result from the production server measured 46,253 tokens in the captured response representation. Large outputs triggered refusals, truncation and extra recovery work. Returning less useful noise is usually easier than asking an agent to recover from an oversized result.
- Page by default, with a total and a cursor.
- Support useful filters and field selection.
- Put the answer summary and continuation information first.
- Leave verbose logs and records of the agent's own calls out unless requested.
Use roughly 5,000 tokens as a starting design budget, not a compatibility guarantee. Also check bytes and lines. A token count does not map to a fixed byte count, and different clients cap different representations.
What crosses the wire is not necessarily what reaches the model
A tool can return both text content and structuredContent. Seeing the same data in both fields does not prove that the model received or paid for both.
| Environment | Representation exposed to the model |
|---|---|
| Claude Code 2.1.301 | Structured content in the observed tool result. |
| OpenCode 1.18.34 | Text content in the observed tool result. |
| Codex 0.161 code mode | Whatever the script prints. Printing the raw object can expose both fields, subject to output truncation. |
The MCP specification recommends a serialized text representation alongside structured content for backward compatibility. Replacing that text with only a short summary can deprive a text-only client of the records it needs. Preserve compatibility and optimize the data shape, then measure the actual model-visible result.
Correction, 19 October: an earlier version treated duplicated wire fields as a general model-context cost and recommended removing the text copy. Our representation checks do not support that blanket advice. Wire size, model-visible tokens and billed usage must be reported separately.
Read more: every rule for results and errors, with measurements, is in tool results and errors for AI agents; the size fixes are in how to reduce MCP tool response size.
5. Maintain tests for real jobs and inspect every call
Tool-level checks tell you whether an endpoint accepts inputs and returns data. Your users need a job completed correctly. Maintain a suite of those jobs, with written expectations, and run it regularly and after changes to tools, models or agent apps.
- Define the job and its expectations. Record realistic prompts, alternative phrasings, expected answers or state changes, and constraints such as “draft only” or “do not spend credits.”
- Run the environments your users use. Record the agent version, model, settings, connection mode and relevant permissions. Verify that the tools reached the agent before interpreting a failure.
- Capture the whole journey. Inspect discovery queries, candidate tools, call arguments, returned results, errors, retries and the final answer. A correct answer can still hide avoidable calls or a fallback outside the intended workflow.
- Compare outcomes and efficiency. Score the written expectations. Track discovery success, wrong-tool calls, unnecessary steps, token usage and completion time. Review representative passing and failing traces to check the scorer itself.
- Change one thing, rerun and keep regressions. Try a name, opening description or response hint against the same jobs. Keep failures as regression cases. Repeat runs because agent behavior varies; evaluate changes across the suite rather than trusting one successful demonstration.
Consider a failed count question. Did the agent fail to discover the tool, choose the wrong filter, misread a state label, lose records through truncation, or report the answer incorrectly? Each cause calls for a different fix. A single pass/fail score will not tell you which one.
Read more: the whole method, step by step, is in how to test an MCP server with real AI agents.
Read more: the full metric set, with targets and a worked example, is in how to measure MCP server quality: the agent scorecard.
Find where agents fail. Test what fixes it.
Bring your MCP and the jobs your users need completed. Spirit Room simulates those jobs across selected models and agent apps, inspects the tool calls, and returns measured gaps and proposed fixes.
What actually failed in the recorded jobs?
Discovery failures: Codex sometimes reported no connection and tried browser or plugin discovery instead of reaching the server through the MCP tool path. The initial request did not name the server, and the required tool search did not lead to an MCP call. This establishes a discovery gap; it does not establish that every such miss was caused by a wrong keyword.
Answer failures after discovery: another failure involved a “To review” summary that combined qualified records with records still needing review. The agent treated that aggregate as the narrower category the user asked for, or concluded that the requested split was unavailable. Here the repair is consistent state names and explicit counts, rather than better discovery keywords.
Elsewhere in the captures, oversized results forced agents to filter and retry or read saved files. A malformed ID produced a 12,689-token validation response. An ambiguous status summary merged categories that the user wanted counted separately. These are different failure mechanisms, and they should remain separate in the analysis. The dedicated Codex truncation follow-up showed recovery through filtering and correct final answers, so those captures establish extra work rather than explaining its scored answer failures.
We also encountered setup failures: Grok Build did not start a project-configured server until the project was trusted; OpenCode 2's interactive and headless behavior differed. Those problems need a connection or harness fix, not a keyword rewrite.
Read more: all seven causes of wrong or missed tool calls we recorded, with counts and fixes, are in why AI agents call the wrong tool.
FAQ
How do I optimise MCP tools for AI agents?
Start from how each agent app shows your tools to the model: some show only names, some search, some send every definition. Then fix five things: names in the user's words, meaning in the first line of each description, outputs that point to the next step, small default results, and tests on real jobs.
Why do agents not find my MCP tools?
In apps that search for tools, the search can miss. In our recorded runs Codex sometimes reported no connection and tried the browser instead, even though the server listed its tools. Use the words your users say in names and first lines.
How do I know if my changes helped?
Run the same real jobs before and after, several times each, in the apps your users use, and compare pass/N with a range plus tokens per job.
Method and limits
The original research combined repeated production read-only jobs with direct server probes and request captures. Discovery captures also used a local stub serving the recorded production tool list; result-size probes and answer checks used the live server. OpenCode 2 had additional live interactive checks. We compared final answers with recorded ground truth and manually reviewed failures. Follow-up experiments used a local mock for controlled instruction changes. Coverage differed across agents; the results are not a ranking of models or agent products.
Request captures used a process-scoped proxy. Saved evidence was redacted to remove credentials. Token-size comparisons used the o200k_base tokenizer; provider-reported usage is labeled separately. A proxy can change client defaults, so settings and tool-loading behavior were checked rather than assumed.
The production findings come from one server, with different default models in different agents. The original capture date was 16 October 2026; the instructions-first follow-up was 18 October. Agent versions and configuration matter. Proposed response examples in this article are design examples, not measured before/after improvements.
Technical reference: configuration and output caps
Configuration changes the discovery path
- Claude Code: deferred loading exposed names first. Disabling tool search or removing
ToolSearchcaused eager loading in the tested setup. A custom model API endpoint also changed the default, so verify tool-search settings behind a gateway. - Codex: the initial model request in code mode did not name the server. Discovery depended on the model searching
ALL_TOOLS. A broad filter produced 56,619 tokens of metadata, which was truncated; narrower filters were easier to use. - Grok Build: the model chose a query for a local BM25 index. Search returned schemas as text in history. Confirm project trust and server startup before judging search quality.
- OpenCode 1: all 99 definitions accounted for 63,245 tokens per model request in the captured setup. Eager loading avoids the search step but carries that context repeatedly.
- OpenCode 2: the interactive catalog showed a subset with short descriptions and offered code-based search. The headless registry behavior differed in follow-up checks; its cause was not established.
Observed output caps
| Agent | Limit | What happens beyond it |
|---|---|---|
| Claude Code 2.1.301 | 25,000 tokens; separate text-size handling also applies | Saves oversized results to a file for recovery. |
| Codex 0.161.0 | About 10,000 tokens per exec output by default; adjustable per call | Keeps the start and end, omitting the middle. Code can filter before printing. |
| OpenCode 1.18.34 / 2.0.31 | 2,000 lines or 51,200 bytes | Shows a prefix and saves the full output to a file. |
| Grok Build 1.0.60 | 20,000 bytes, from source inspection | Shows a prefix and saves full output; this cap was not hit in our captured task. |
These limits apply at different points in the path from server response to model context. Check the actual client output, including summaries and wrappers, rather than comparing raw server JSON with a nominal token limit.
Find where agents fail. Test what fixes it.
Bring your MCP and the jobs your users need completed. Spirit Room simulates those jobs across selected models and agent apps, inspects the tool calls, and returns measured gaps and proposed fixes.
Sources
- Claude Code MCP documentation: tool search, server instructions and result handling.
- Codex code-mode runtime: tool metadata available through
ALL_TOOLS. - Grok Build tool index and MCP documentation: keyword search and tool invocation.
- OpenCode 2 MCP documentation: code mode and tool discovery.
- MCP tool specification: structured results, compatibility and tool annotations.
- Spirit Room production captures, two-marker representation probe and manual failure reviews, 16 October 2026; controlled instructions-first mock experiments, 18 October 2026.