Skip to content

improve(tool-search): show input signatures for MCP tools in search results - #196266

Merged
RomneyDa merged 6 commits into
mainfrom
openclaw/mcp-tool-search-input-hints
Nov 10, 2026
Merged

RomneyDa merged 6 commits into
mainfrom
openclaw/mcp-tool-search-input-hints

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #166133, #194877

Requested by @jalehman.

Work sessions

Linked for team reference; these sessions aren’t public.

What Problem This Solves

Tool Search returns input: "unknown" for every MCP tool, so agents call tool_describe before almost every MCP call. Each extra round trip re-sends the prompt. In the g-harness-evals analysis, OpenClaw on Opus averaged about 1.8 tool_describe calls per trial on top of about 3.8 tool_search calls.

User Impact

tool_search results (single and batch) now show a compact input signature for MCP tools, for example { channel: string; limit?: number /* integer, <= 500, > 0 */; ... }. An agent can call simple MCP tools directly from the search result. tool_describe still returns the full schema, and a schema that cannot be summarized still shows unknown or .... Client tools are unchanged.

Why This Change Was Made

  • compactToolSearchCatalogEntry renders MCP input schemas with the existing compactToolInputHint renderer. That renderer is already bounded: 300 characters, four nesting levels, 16 properties per object, property names over 128 characters dropped and other non-identifier names JSON-escaped, and short enums. It keeps only structure: names, types, required/optional, enums, and numeric bounds. Descriptions, defaults, and formats are dropped. tool_describe already returns the whole MCP schema, so withholding this summary did not protect anything.
  • Client tools keep input: "unknown". Code Mode builds its system-prompt tool index from these same compact entries and lists client tools there (MCP tools are excluded from that index). Rendering client hints would put caller-supplied schema text into the Code Mode system prompt, which currently has only the callable name. In directory mode, client tools are already direct with full schemas.
  • Remote schemas can carry very large literals. The renderer now rejects a string const/enum literal that exceeds the hint budget before JSON.stringify. Code Mode prompt construction and its wait-error path filter out MCP entries before compaction, so MCP hints are not rendered there. Those entries were already dropped by binding selection, so the Code Mode prompt does not change.
  • Ranking is unchanged: MCP and client parameter text is still never indexed. OpenClaw still does not validate MCP input or output against the remote schema. Two tests used a throwing Proxy to assert that MCP schemas are never traversed at all. They now assert the contracts that remain: MCP parameter text does not affect ranking, and OpenClaw does not reject MCP calls on schema grounds. The throwing-Proxy case is kept for client tools.
  • Model-facing tool descriptions and directory text were not changed. They already say to use tool_describe when input is not clear, which still applies to unknown/... hints. docs/tools/tool-search.md no longer says MCP inputs are deferred, and it documents the bounds and the client decision.
  • Overlap: fix(code-mode): publish canonical tool inputs #194877 (open) switches catalog parameters to the canonical presentation schema. These hints read entry.parameters, so they will follow that change automatically. Its helpers resolve which schema is used and do not apply to rendering. The two PRs touch different lines in tool-search-catalog.ts.
  • [Bug]: MCP tool_call wrapper coerces integer args to string, breaks MCP tools with integer params #166133 (MCP integer arguments arriving as strings) is not fixed here. Integer parameters now render as number /* integer ... */, and a new assertion checks that an integer argument reaches the MCP executor as a JSON number through dispatch_action.

Evidence

Before/after against the real g-harness-evals world MCP server (world/world-mcp, streamable HTTP with bearer auth). The path was: OpenClaw's session MCP runtime manager → materializeBundleMcpToolsForRun → applyToolSearchCatalog → tool_search execute. Sizes are the model-facing tool result text, including the untrusted-content wrapper. Before is the parent commit; after is 0596c231. The capture harness was a local, uncommitted Vitest file.

tool_search call Before After Change
{ query: "list channels" } (8 hits) 3,915 B 4,229 B +314 (+8.0%)
{ query: "read channel" } (6 hits) 2,919 B 3,143 B +224 (+7.7%)
batch of both (3 + 3 hits after budget truncation, before and after) 3,671 B 3,955 B +284, under the 4,000-char budget
before: world__read_channel   input: unknown
after:  world__read_channel   input: { channel: string; latest?: string; limit?: number /* integer, <= 500, > 0 */; oldest?: string; thread_ts?: string }
after:  world__list_channels  input: {}
after:  world__mail_list      input: { box?: "inbox" | "drafts"; id?: string; limit?: number /* integer, <= 200, > 0 */ }

14 of the 15 world tools get complete signatures. request_approval renders { action: string; authorization: string; channel?: unknown; details?: { ... } }, so it still needs tool_describe. For these tools, a tool_describe result is 778–2,513 B, plus one more model request that re-sends the prompt. The reduction in describe calls was not measured: no scripted or real-model run was done. Building dist for a full openclaw agent --local run is refused on this shared host by the managed-Gateway runtime-artifact publication guard. The capture above exercises the production MCP runtime and Tool Search modules directly.

Tests

  • New tool-search.discovery.test.ts case through the real tool_search/tool_describe/dispatch_action tools:
    • an MCP schema with nested objects, arrays, enums, and integer bounds (exact signature);
    • a hostile schema: newline-bearing and 200-character names, 12-level nesting, a 5,000-value enum, a 100,000-character const, and 1,000 extra properties. It stays at or under 300 chars, renders on one line, drops the long name, collapses depth, and ends in ...;
    • a missing schema renders unknown;
    • tool_describe still returns the full schema;
    • an integer argument reaches the executor as a number;
    • a batch of MCP candidates stays within MAX_TOOL_SEARCH_BATCH_RESPONSE_CHARS with truncated: true, and remaining candidates keep their full hint.
  • Red on base: the new case fails on origin/main (expected 'unknown'). The huge-const assertion fails without the literal bound.
  • 66 affected test files pass: tool-search*, code-mode*, tool-schema-hints, attempt-client-tools, attempt.tool-search-run-plan, agent-tools.prefix-stability, system-prompt-report. One perf file is skipped by design.
  • Cost: the three changed test files with --maxWorkers=1 take 46.6 s wall, nearly all of it Vitest worker preparation. Test bodies take 1–15 ms each.
  • tsgo core and core-test shards, oxlint and oxfmt on changed files, markdownlint on the doc, git diff --check, and the test-line ratchet all pass. The ratchet uses allocation config/test-lines-allocations/mcp-tool-search-input-hints.txt (+114 net lines: 121 MCP boundary-case lines minus seven obsolete host-denial waiting-path lines).
  • Two pnpm check:changed failures are inherited from origin/main in files this PR does not touch: the dead-export scan (src/daemon/launchd.ts, src/plugins/provider-runtime.ts, and others) and one core lint error in ui/src/e2e/sidebar-rail-alignment.e2e.test.ts (no-shadow).
  • Local autoreview (Codex, P0–P2): the first pass flagged unbounded literal serialization, which is fixed here. The second pass was clean.

CI repair: Integrated the existing main lint and test-budget repairs. The new main failure-settlement behavior from #196435 exposed a stale host-denial test: reproduced on pinned main 21f17afce911 (20 pass, one fails), then corrected the expectation without weakening late mutation completion, exactly-once execution, lifecycle drain, or no-spawn assertions. All 21 host-denial tests pass, plus targeted lint/format. The small test-only diff received an independent review with no findings. The pinned-base test-line ratchet passes with zero slack. The earlier 104 focused MCP and prefix-stability tests also passed.

Gaps: no isolated-Gateway or real-model run, and no measured change in describe-call count.

Worked on by

roboclaw-bot and others added 2 commits November 9, 2026 21:24
…esults

tool_search rendered input "unknown" for every MCP tool, so models called
tool_describe before almost every MCP call. Render the same bounded,
structure-only signature used for OpenClaw tools from the MCP input schema.
Client tools keep "unknown" because Code Mode lists them in its system prompt
from the same compact entries.

Remote schemas can carry huge literals, so string literals longer than the
hint budget are rejected before serialization. Code Mode prompt construction
skips MCP entries before compaction; it never listed them.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
…esults

Worked on by:
- @jalehman
- @GrahamMcBain

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
OpenClaw-Publication: a0929bba-b988-4c27-b67d-606a685a1e6e
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 9, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds bounded MCP input signatures to Tool Search results while preserving client-schema deferral.

Example: An agent searches for world__read_channel.

  • Before: The result shows input: unknown.
  • After: The result includes channel: string and limit?: number with integer bounds.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with no actionable code finding; supplied behavioral evidence remains a production-module harness rather than a shipped-entry-point run.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored bot PR is outside the ordinary contributor proof gate; its public terminal excerpt reports real HTTP MCP schemas passing through materialization, catalog registration, and search, with the expected signatures after the change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Agents must load full MCP descriptions even when a short input signature would supply enough information to call the tool.
Reason: Maintainer authorship establishes direction, and the small implementation offers useful discovery information without claiming measured model-turn savings.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed improvement addresses a discovery limitation still present on main, and review found no concrete introduced defect.

Priority: P2
Reviewed head: eb01b0996b314db8bdbd1aaf10f37c15777ee6d8

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied capture exercises production MCP and search modules, but no shipped CLI/Gateway or real-model scenario is provided.
Agent review details

How this fits together

The run-scoped tool catalog receives MCP schemas and supplies compact search results, full descriptions, and execution metadata to structured Tool Search and Code Mode.

flowchart LR
  A[MCP server schemas] --> B[Run scoped catalog]
  B --> C[Bounded input renderer]
  C --> D[Tool Search results]
  B --> E[Full tool description]
  D --> F[Agent tool call]
  F --> G[Existing execution owner]
Loading

Technical review

Best possible solution:

Use the existing bounded renderer for MCP discovery while retaining full descriptions, client deferral, and existing execution ownership.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically returns unknown for MCP input hints; the supplied before/after capture corroborates that behavior, and this review executed no target code.

Is this the best way to solve the issue?

The patch is a focused extension of the existing catalog renderer, with no competing renderer, new state, or configuration surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7554b069a703.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +14, Tests +121, Docs +12, Other +2. Total +149 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 24 10 +14
Tests 3 156 35 +121
Docs 1 23 11 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 10 205 56 +149

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +24/-10 lines; tests +156/-35 lines Small production growth reuses the renderer; test growth covers remote-schema bounds, ranking isolation, execution ownership, and batch budgeting.

Labels

Label changes:

  • add P2: This improves MCP discovery efficiency without an established urgent runtime regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This improves MCP discovery efficiency without an established urgent runtime regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 9, 2026, 4:42 PM ET / 21:42 UTC.

RomneyDa and others added 4 commits November 9, 2026 20:51
#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for #196385 and correct #196416 from 33 to its actual 36 test lines. #196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main #196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.

(cherry picked from commit 644ff7d)
@RomneyDa
RomneyDa merged commit eb8c48f into main Nov 10, 2026
121 of 122 checks passed
@RomneyDa
RomneyDa deleted the openclaw/mcp-tool-search-input-hints branch November 10, 2026 06:03
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…esults (openclaw#196266)

* improve(tool-search): show input signatures for MCP tools in search results

tool_search rendered input "unknown" for every MCP tool, so models called
tool_describe before almost every MCP call. Render the same bounded,
structure-only signature used for OpenClaw tools from the MCP input schema.
Client tools keep "unknown" because Code Mode lists them in its system prompt
from the same compact entries.

Remote schemas can carry huge literals, so string literals longer than the
hint budget are rejected before serialization. Code Mode prompt construction
skips MCP entries before compaction; it never listed them.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>

* improve(tool-search): show input signatures for MCP tools in search results

Worked on by:
- @jalehman
- @GrahamMcBain

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
OpenClaw-Publication: a0929bba-b988-4c27-b67d-606a685a1e6e

* fix(test): restore the main test-line budget after warm reload changes (openclaw#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for openclaw#196385 and correct openclaw#196416 from 33 to its actual 36 test lines. openclaw#196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main openclaw#196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.

(cherry picked from commit b67d29e)

* test(agents): align host-denial proof with immediate failure settlement

---------

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]>
Co-authored-by: Peter Steinberger <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
Backport source eb8c48f.
Preserve release type ownership and skip MCP schemas before compaction
in both Code Mode prompt construction and expired-run recovery.

Exclude unrelated host-denial test changes from the source squash.
Allocate the retained input-hint tests and extra precompaction regression.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit dcc7c4cd5e8237bf14c36d5273f386038b5fe40c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants