← All Labs Lab 16 / 28 Many MCP tools behind tool_search
Lab 16 · Tools & UI · Proposed

Many MCP tools behind tool_search

With 60 bridged MCP tools marked deferred and pi-durable's tool_search installed, each turn's prompt carries far fewer tokens than with all 60 schemas offered, and the model still calls the right tools.

Proposed Needs: tool-calling Source: examples/16-mcp-tool-search

Not built yet. PROMPT.md is the prompt to build it from.

An agent connected to several MCP servers sends every tool schema on every turn. pi-durable can hold tools back (deferred) until the model finds them with tool_search. This lab measures what that saves and whether the model still picks the right tools, on one set of tasks run two ways:

ModeWhat the model is offered
directAll 60 bridged MCP tool schemas, every turn
tool-searchtool_search only; the 60 MCP tools are deferred until it loads them

The checks the build should end with: per-turn prompt tokens drop by a large margin in tool-search mode, and every task's answer is right with the expected tools called, in both modes. Offline it uses a scripted faux model; live it runs mycel: models only (D-28).

Known going in

  • The MCP bridge can't defer tools yet. bridgeMcpClientToExtension (packages/habitat/src/durable/extensions.ts) registers every model-visible tool as always offered. pi-durable's ToolRegistration has deferred?: true; the bridge needs an option to set it. That change is part of building this lab.
  • tool_search comes from @earendil-works/pi-durable/tool-search (createToolSearchExtension); packages/evaluation/src/coding/extensions.ts shows it installed.

Moved out

  • Codemode (one JS snippet chaining tool calls) was a third mode. It's a different question, chaining cost rather than schema cost, and it can be its own lab.

Prompt

Coding-Agent Prompt · Ready to Paste
Build `examples/16-mcp-tool-search/run.ts`: a lab that checks whether deferring bridged MCP tools behind pi-durable's `tool_search` cuts per-turn prompt tokens without the model picking wrong tools.

Read first: `packages/habitat/src/durable/extensions.ts` (`bridgeMcpClientToExtension`), `node_modules/@earendil-works/pi-durable/dist/tool-search/tool-search.d.ts` and the `deferred` field on `ToolRegistration` in `harness/types.d.ts`, `packages/evaluation/src/coding/extensions.ts` (how `createToolSearchExtension` is installed), and `packages/protocols/src/mcp/client/remote.ts`.

1. Add a `deferred` option to `bridgeMcpClientToExtension` that marks the bridged tools `deferred: true`, with a unit test.
2. In the lab, serve 60 synthetic tools (15 each in billing, calendar, issues, audit-logs, with realistic JSON Schemas and deterministic in-memory data) from a loopback MCP server, and connect them with RemoteMcpClient through the bridge into a DurableHabitat.
3. Define 4 tasks that each need 2–3 specific tools from at least 2 domains and have an exact answer a verifier checks.
4. Run every task in two modes: `direct` (all 60 tools offered) and `tool-search` (tools deferred, `tool_search` installed). Record per-turn prompt tokens, turns, tools called and pass/fail.
5. Offline (default and `--smoke`), script a faux model per mode. Print one PASS/FAIL line per check and exit 1 on any failure: tool-search-cuts-prompt (median per-turn prompt tokens in tool-search mode under half of direct mode); right-tools (every task in both modes calls exactly its expected tools and passes its verifier).
6. `--live --model mycel:<id>` runs the same tasks on a Mycel model (no direct vendor keys, D-28) and prints the same table.
7. Strict TypeScript, no `any`; close servers and the habitat in `finally`. README frontmatter (status built) and a FINDINGS.md with what building it taught us.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --live opt-in