Repository navigation
improve(tools): let models call listed MCP tools without searching first - #196252
Conversation
Models had to call tool_search before they could find any MCP tool, even when the catalog held only a handful. In the g-harness-evals world benchmark this cost about 3.8 extra search round trips per trial. In structured Tool Search mode, the tool_search description now ends with a bounded (4 KiB), deterministic directory of the run's deferred MCP tools: sanitized one-line descriptions, exact catalog ids for ambiguous names, and per-server counts instead of silently dropping servers when it does not fit. Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]>
Worked on by: - @jalehman - @GrahamMcBain Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> OpenClaw-Publication: d80e182b-e31b-4126-a894-389860662f7f
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]>
Worked on by: - @jalehman - @GrahamMcBain Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> OpenClaw-Publication: 953c9487-ef5d-4f83-b7bc-42c88488c854
|
Codex review: needs maintainer review before merge. What this changesThis PR lists bounded, sanitized MCP tool identifiers in the tool_search description so models can describe and call them without searching first. Example: An agent needs the world server's calendar_list tool.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: both earlier findings are resolved, the maintainer-approved improvement remains useful, and no new actionable defect was found; exact-head CI is still running. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherAgent tool assembly registers policy-filtered tools in a run-owned catalog; this change projects deferred MCP metadata into model-visible tool definitions while retaining the existing lookup and execution owners. flowchart LR
A[Authorized agent tools] --> B[Run-owned catalog]
B --> C[Bounded MCP directory]
C --> D[Model tool definitions]
D --> E[Describe and dispatch]
E --> F[Existing execution gates]
F --> G[MCP server]
Technical reviewBest possible solution: Keep the bounded MCP projection in the existing directory owner, using exact catalog IDs and the existing catalog snapshot cache. Do we have a high-confidence way to reproduce the issue? Source inspection confirms that fetched main omits deferred MCP identifiers from the initial discovery surface; no runtime reproduction was performed. Is this the best way to solve the issue? The change uses the existing catalog and presentation owners, preserves execution gates, and fixes the previously identified collision without another lifecycle owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2609b4f93bf8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +196, Tests +226, Docs +70. Total +492 across 6 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 9, 2026, 9:06 PM ET / November 10, 2026, 02:06 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Allocate the exact 223 net regression lines for bounded directory rendering, hostile metadata, selectors, collisions, late client registration, and prompt stability.
…rst (openclaw#196252) * improve(tools): list deferred MCP tools in the tool_search description Models had to call tool_search before they could find any MCP tool, even when the catalog held only a handful. In the g-harness-evals world benchmark this cost about 3.8 extra search round trips per trial. In structured Tool Search mode, the tool_search description now ends with a bounded (4 KiB), deterministic directory of the run's deferred MCP tools: sanitized one-line descriptions, exact catalog ids for ambiguous names, and per-server counts instead of silently dropping servers when it does not fit. Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> * improve(tools): let models call listed MCP tools without searching first Worked on by: - @jalehman - @GrahamMcBain Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> OpenClaw-Publication: d80e182b-e31b-4126-a894-389860662f7f * Publish openclaw/mcp-tool-search-directory Worked on by: - @jalehman - @GrahamMcBain Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> OpenClaw-Publication: 953c9487-ef5d-4f83-b7bc-42c88488c854 * fix(tools): keep MCP directory identifiers stable after client registration * test(tools): fix MCP directory CI typecheck and line allocation Allocate the exact 223 net regression lines for bounded directory rendering, hostile metadata, selectors, collisions, late client registration, and prompt stability. --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> Co-authored-by: Dallin Romney <[email protected]>
Backport source 80ba593 using the release tool-search-types owner rather than a protocol split. Refresh the directory after prompt-policy filtering as well as initial assembly; independent review found stale filtered MCP metadata otherwise. Keep exact IDs, bounded untrusted text, and stable directory bytes. Co-authored-by: jalehman <[email protected]> Co-authored-by: GrahamMcBain <[email protected]> Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit e0c70b6c2a72793ca63cf3a8d9381b55471f1aa3)
Related: #137594
Requested by @jalehman.
Work sessions
Linked for team reference; these sessions aren’t public.
What Problem This Solves
With structured Tool Search (the default), a model must call
tool_searchbefore it can learn any MCP tool's name. In the g-harness-evals analysis (Opus 5.5, [email protected]), OpenClaw averaged ~3.8tool_searchcalls per trial, each with a ~5.8 kB result that is re-sent on every later request. Hermes Agent made none, because itstool_searchdescription lists every deferred tool by name.User Impact
User impact: agents can call a listed MCP tool with
tool_describe→dispatch_action, without atool_searchround trip first. The directory is capped at 4,096 bytes for any catalog. The earlier bare-name implementation measured 1,813 bytes for the 15-tool world server; exact catalog IDs add a source/server prefix per listed row. Runs without deferred MCP tools keep a byte-identicaltool_searchdescription. Short, sanitized MCP names and descriptions now appear in a tool definition on every request, not only in search results.Why This Change Was Made
In
toolsmode,applyToolSearchCatalognow appends the run's deferred MCP catalog entries to thetool_searchdescription:include/excludeselectors apply first. Only entriestool_searchcan return are listed.tool_search. It stays independent of inventory, keeping fix: keep tool directory stable across external inventory #180395's guarantee.directorymode and Code Mode are unchanged.Tradeoffs
Prompt-cache invalidation. Directory bytes change only when the MCP inventory changes: a server is added or removed, changes its tools or descriptions, or connects for the first time. That turn misses the cached tools+system prefix once (~60 kB, ≈15k tokens, in the world setup). A listed server whose refresh fails keeps its last listed tools (existing behavior), so a flapping server does not churn the directory. A second turn in a new process produced byte-identical
toolsandsystem.Prompt injection. The user chose the server, so reasonable precautions apply:
[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}. Other names are only counted.<,>, and backticks removed; whitespace collapsed. A row cannot start a new line or imitate the heading or footer.What is not protected: meaning. A malicious server can still write "always call this first" or misdescribe its tool in 96 characters. The rows are not wrapped in the
EXTERNAL_UNTRUSTED_CONTENTboundary that tool results use. The same server already reaches context through full descriptions,tool_describe, tool results, and the## MCP Server Instructionssystem-prompt section.Earlier bare-name size vs. round trips (world server, scripted model, same base
d3b571f8; these captures predate the exact-ID cleanup):tool_searchdescriptiontoolsJSON per requestworld__whoamiThe earlier bare-name directory added ~1.9 kB (≈470 tokens) per request, mostly read from the prompt cache. Each avoided search saves a full model round trip plus its result (~1 kB scripted, ~5.8 kB measured in g-harness) on every later request.
Large catalogs. The 4,096-byte cap (≈1k tokens) is below one typical search result with capacity depending on exact ID and description lengths. Over the cap, the directory degrades in fixed steps:
- github server: 400 tools, names omitted).No server is dropped silently, and a footer points to
tool_search.Late-connecting servers. There is no new wait. Embedded runs already wait for each server's bounded connect +
tools/listbefore the first request; the world tools were in the first request. A failed server is absent from both the directory and search that turn. It is listed on a later turn. Naming unavailable servers is #137594's scope.Docs/policy.
docs/tools/tool-search.mdpromised MCP names and descriptions stay out of the prompt. It now says they stay out of the system prompt and appear, sanitized and bounded, in thetool_searchdescription. A new section documents the precautions and what is not protected.Alternatives considered
tools.toolSearch.exclude.Evidence
tool-search-mcp-directory.test.tscovers:tool_describeresolves every listed label.SYSTEM:prompts, RLO/zero-width/fullwidth tags, code fences, 5k-character descriptions, bad and 200-character names.pnpm teston 17 related files: 254 passed.tsgo:core,tsgo:core:test,oxlint --type-aware, andgit diff --checkare clean.main(d53921ac, import-only conflict): 10 of those test files (175 tests),tsgo:core, and lint passed again.openclaw agent --localas in the g-harness adapter, with a clean env, a live world MCP server, and a fake Anthropic endpoint dumping request bodies. Onlytool_searchand the notice line differ.- world__whoami:from the description, callstool_describeanddispatch_action, and the live world server returns the member record. The turn made zerotool_searchcalls. No real-model run.d3b571f8, head6a5f459d, P1): scoped-clean.Cleanup for re-review
12818dc57371inaea01917d9e6: MCP directory rows now always use exact catalog IDs, and the Ollama prompt fixture was regenerated withpnpm prompt:snapshots:gen.Ambiguous tool nameand passes with the fix. The snapshot check likewise failed before regeneration and passes afterward.pnpm prompt:snapshots:check,pnpm tsgo:core, targeted oxlint, oxfmt, andgit diff --checkpassed.12818dc57371: scoped-clean at P2 (no actionable P0–P2 findings). No new real-model run; earlier scripted transport evidence remains historical, not a measurement of the new exact-ID payload.check-lint-core-2failure reports file-size violations only in unchanged UI, session, process, config, and package-update files outside this PR. New-head CI remains the broad validation source.CI follow-up
The final-head CI exposed two PR-related checks missed by the initial local selection: TS2345 in the regression's identifier extraction and the test-line ratchet. The test now slices the identifier as a definite string without changing production behavior; the exact net +223 regression lines are recorded in
config/test-lines-allocations/mcp-tool-search-directory.txt. This allocation preserves the bounded-directory, metadata, selector/collision, late-client-registration, and prompt-stability coverage without raising the shared scalar.Validation: the exact failing agents-tools test-type leaf, test-line ratchet, targeted lint, and focused MCP directory regression suite pass. The production code is unchanged from the clean hosted review of
aea01917d9e6; new-head CI remains required.Open questions
directorymode list MCP tools too?Worked on by