Tool design and context efficiency (including the "many tools vs code" debate)
Tool design and context efficiency (including the "many tools vs code" debate)
About the video (optional, secondary source). The embedded video (YouTube 7ad_1mC-zCk) is a third-party explainer about code-execution agents. Treat it as a secondary source. The figures it discusses come from Anthropic's engineering posts listed under Sources, and the techniques it shows (Tool Search, Programmatic Tool Calling) are Claude API features, not part of the MCP protocol. This lesson does not rely on its timestamps.
Where you are
You can build servers, wrap an API with a few curated tools (L11) and secure them (L14). Now the question is cost and quality: every tool you expose takes space in the model's context and competes for the model's attention. This lesson also covers the open debate on whether agents should get many tools or fewer tools plus code. Earlier versions of the course taught that debate as a separate lesson.
What you will be able to do
- Explain why large tool catalogs cost tokens and hurt tool selection.
- Use the levers that are part of MCP (current spec) to keep a server lean.
- Tell those apart from host or API features such as Tool Search, Programmatic Tool Calling and code execution, and quote their figures with the right attribution.
- Weigh the "many tools vs fewer tools plus code" positions and pick an approach for a given case.
Why many tools hurt
Tool definitions (name, description and input schema) are usually placed in the model's context before any work begins. Raw intermediate results pile up too if the model chains call after call. Anthropic's "Advanced tool use" post gives one illustration: five MCP servers with 58 tools consumed about 55K tokens before a conversation started. Context is not only money: with many similar descriptions, the model picks the wrong tool more often.
Levers that are part of MCP (current, 2026-07-28)
These work with any compliant host, because they live in your server:
- Curate. Expose a few task-level tools, not one tool per endpoint. In L11, three tools covered the use case and the admin
DELETEstayed out. - Name and describe precisely. Tool names SHOULD be 1 to 128 characters from
A-Z a-z 0-9 _ - ., unique within the server. Put constraints in the schema (enums, ranges, patterns) instead of long prose. - Return structure. Declare an
outputSchemaand returnstructuredContent; for backward compatibility, also return the JSON as a text block. - Point, don't paste. Return a
resource_linkto large data instead of inlining it. - Paginate list results.
- Keep order deterministic. Servers SHOULD return
tools/listin a stable order so clients can cache it and prompt caches hit more often. - Cache hints.
tools/listresults carryttlMsandcacheScope, so clients can avoid re-fetching. - Scope by authorization.
tools/listMAY return only the tools the caller's granted scopes permit, which shrinks the catalog for low-privilege callers.
Roadmap (not shipped): "progressive discovery", where clients learn tools as they need them instead of ingesting the full catalog, is a priority area on the official roadmap (updated 2026-08-22). Do not present it as available.
Optional extension: "Skills over MCP" is an official extension for structured agent-workflow instructions. Like every extension, it is opt-in on both sides.
Techniques that belong to the host or API (host-specific)
These are real and effective, but you get them from the model platform or the agent harness, not from the MCP protocol:
| Technique | What it does | Figure and source |
|---|---|---|
Tool Search Tool with defer_loading: true (Claude Developer Platform, beta header advanced-tool-use-2025-11-20) | Loads tool definitions on demand; can defer a whole MCP server through an mcp_toolset setting | About 77K to about 8.7K tokens of tool context in Anthropic's example ("Advanced tool use", 2025-11-24) |
| Programmatic Tool Calling (same platform, same beta) | The model writes code that calls tools; intermediate results stay out of context | Average usage dropped from 43,588 to 27,297 tokens, a 37% reduction on complex research tasks (same post) |
| Code execution with MCP (an agent-harness pattern) | MCP tools are presented as code files; the agent loads only what it needs and moves data in code | 150,000 to 2,000 tokens (98.7%) for one Google Drive to Salesforce example ("Code execution with MCP", 2025-11-04) |
Two attribution traps to avoid:
- The 150K to 2K figure belongs to "Code execution with MCP". That post never uses the term "Programmatic Tool Calling".
- The 37% figure belongs to Programmatic Tool Calling. It is a different measurement on a different task.
Running model-written code needs a sandbox. The code-execution post says it "requires a secure execution environment with appropriate sandboxing", which adds operational overhead and security considerations that direct tool calls avoid.
The debate: many tools, or fewer tools plus code?
Position A: explicit tools. One tool per meaningful operation, each with a name and a schema. It is straightforward to build, easy to audit (you can read exactly what the agent may do) and deterministic to debug: when something fails, you know which call failed.
Position B: fewer tools plus code. Armin Ronacher's post titled "Your MCP Doesn't Need 30 Tools: It Needs Code" (2025-08-18) proposes MCP servers that expose a single tool accepting program code. Simon Willison's link post (2025-08-22), which highlights Geoffrey Huntley's article, states that adding the GitHub MCP server "defines 93 additional tools and swallows another 55,000" tokens. That figure dates from August 2025 and the server may have changed since, so measure today's version before quoting it. In "Skills vs Dynamic MCP Loadouts" (a blog post, 2025-12-13), Ronacher describes replacing his remaining MCP integrations with skills.
What changed since then: the platform features in the table above shipped in November 2025; 2026-07-28 added deterministic ordering and cache hints; "Skills over MCP" became an official extension; and progressive discovery became a roadmap priority. The debate has narrowed, but it is not settled.
The trade-off:
| Explicit tools | Fewer tools plus code | |
|---|---|---|
| Token cost | Grows with the catalog | Lower for multi-step data work |
| Auditability | Every action is a named call | Actions are inside generated code |
| Debugging | Per-call errors | Errors inside scripts |
| Security | Each tool scoped and validated | Needs a sandbox and egress limits |
| Works on any host | Yes | Depends on the host or harness |
A decision method
Rules of thumb, not measured thresholds:
- Start with a handful of explicit, task-level tools. Most servers never need more.
- Measure the size of your
tools/listand watch for wrong-tool choices in your host's traces. - If the catalog must grow, first use the MCP levers above: merge similar tools, tighten schemas, link instead of inlining, and scope tools by authorization.
- If your host offers deferred loading, enable it for big catalogs. That is a host setting, not a change to your server.
- Move to code execution only for multi-step, data-heavy flows, and only with a sandbox.
Worked example: the L11 server
The lab exposes search_items, get_item and reserve_stock. Each declares constraints in its schema (SKU pattern, quantity 1 to 10, category enum), an output model and annotations. If a product manager asks for "all twelve API endpoints as tools", the lean answer is to add one task-level tool (for example a low_stock_report) and keep admin operations out, rather than mirroring endpoints.
Practice: measure your tool budget
With the L11 lab running (./run.sh serve in one terminal), save this as tool_budget.py in lab-l11/ and run .venv/bin/python tool_budget.py twice:
import asyncio, json
from mcp import Client
async def main() -> None:
async with Client("http://127.0.0.1:8000/mcp") as client:
tools = (await client.list_tools()).tools
total = 0
for t in tools:
size = len(json.dumps(t.model_dump(by_alias=True, exclude_none=True)))
total += size
print(f"{t.name:15} {size:5} chars")
print(f"TOTAL {total} chars, {len(tools)} tools, order: {[t.name for t in tools]}")
asyncio.run(main())
Characters are only a rough proxy for tokens, but they are good enough to compare designs.
Check your result
- You see three tools. On the unmodified lab (2026-11-26):
search_items1401,get_item839,reserve_stock917,TOTAL 3157 chars. Small differences are fine if you edited descriptions. - The
order:list is identical on both runs. That is the deterministic ordering the spec asks for. - Extension: add the
low_stock_reporttool from L11's exercises and rerun. Note how many characters one more tool costs.
Check your understanding
-
Is
defer_loadingan MCP feature you set on your server? No. It is a Claude Developer Platform option (the Tool Search Tool, in beta). Your server can help any host through MCP levers such as a small catalog, tight schemas and deterministic order. Progressive discovery at the protocol level is still a roadmap item. -
A slide says "Programmatic Tool Calling cut tokens from 150,000 to 2,000." What is wrong? Wrong attribution. 150K to 2K (98.7%) comes from Anthropic's "Code execution with MCP" post, for one example workflow. Programmatic Tool Calling's published figure is 43,588 to 27,297 tokens (37%) on complex research tasks.
-
Your agent works in a regulated domain where every action must be auditable, with 8 distinct operations. Which approach? Explicit tools. The catalog is small, so token savings are minor, and named, schema-validated calls give the audit trail you need. Reconsider only if measurement shows a real problem.
Sources
- https://modelcontextprotocol.io/specification/2026-07-28/server/tools
- https://modelcontextprotocol.io/specification/2026-07-28/changelog
- https://modelcontextprotocol.io/specification/2026-07-28 (extensions list)
- https://modelcontextprotocol.io/development/roadmap
- https://www.anthropic.com/engineering/advanced-tool-use
- https://www.anthropic.com/engineering/code-execution-with-mcp
- https://lucumr.pocoo.org/2025/8/18/code-mcps/
- https://lucumr.pocoo.org/2025/12/13/skills-vs-mcp/
- https://simonwillison.net/2025/Aug/22/too-many-mcps/
