Skip to content

fix(mcp): stop advertising complete Evidence in input examples - #1560

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/mcp-advertised-example-evidence
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/mcp-advertised-example-evidence

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

Users report that REA uses too much context. Hosts send every tool's name, description and inputSchema to the model with each request, so the advertised input catalog is a fixed cost on every turn.

Measured with the pinned SDK 2.3.1 client against the stdio server built from main (2ec93ba). All 139 tools; compact UTF-8 bytes:

Surface Before After
Input-facing catalog (name + description + inputSchema) 507,455 393,263 (−22.5%)
All advertised inputSchemas 450,463 336,271 (−25.3%)
Root examples in input schemas 129,457 ~13,000

Root examples made up 29% of the advertised input schemas. 17 tools had an example that embedded a complete producer Evidence record: compare_javascript_export_shapes (22 KB), compare_application_versions (21 KB), reconcile_javascript_runtime, correlate_static_and_runtime, compare_source_to_bundle, trace_application_feature, trace_javascript_semantics, compare_process_captures, find_changed_behavior and others. Together these were 116 KB. An agent never writes such an example by hand. It passes Evidence it already received, and the example shows nothing about choosing arguments that the schema and descriptions don't already state. It can also lead an agent to paste whole Evidence inline when a retained reference would work.

Change

The advertised projection (toolInputSchemaWithMetadata) now builds examples with a new helper, advertisedInputExamples (src/contracts/advertisedInputExamples.ts):

  • An embedded complete Evidence record is replaced by its exact {"kind":"retained-evidence","evidence_id":...} reference, but only when the canonical input schema accepts that form. This applies to the five JavaScript application workflows, which take evidenceInputSchema.
  • An example that can only carry inline Evidence is left out of the advertisement. Twelve tools end up with no advertised examples, and the examples keyword is omitted for them.
  • Duplicates are removed, so every advertised example is a distinct valid canonical input.

Unchanged: canonical contract.examples (still executed by boundary tests), canonical validation, the advertised validation keywords, property descriptions, output schemas, the tool inventory and the compact profile.

docs/mcp-contracts.md documents the rule.

Not in scope: per-result size and the duplication between text and structured content (#723), and the remaining validation structure of large input schemas such as compare_web_captures (52 KB).

Relates to #723, #1065, #1554. This reduces the static catalog cost #1554 hit, but on its own it may not clear that client's limit: the issue reports that omitting root examples alone still failed with gpt-4.1 metadata.

Verification

  • npm run check:changed and npm run check:fast pass
  • npm run docs:check passes
  • npm run test:focused -- tests/boundary/mcp/*.test.ts: 85 files passed, 2 skipped (330 tests)
  • New src/contracts/advertisedInputExamples.test.ts covers:
    • rewriting Evidence to retained references, including inside arrays, and removing duplicates;
    • omitting an example when only inline Evidence is accepted;
    • a check across the whole catalog that no advertised example embeds an Evidence record and every advertised example parses canonically.
  • toolSchemaValidity now asserts the advertised examples equal the projection, and still checks every canonical example against the advertised schema with Ajv.

No real Hopper/Ghidra/IDA verification was performed (they are not affected). No real host-client lanes (Copilot, Kimi) were run. Byte counts are wire measurements, not model token counts.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Hosts forward every tool's input schema to the model on each request.
Seventeen tools advertised a canonical example that embedded a complete
producer Evidence record, up to 22 KB each, accounting for 116 KB of the
450 KB of advertised input schemas.

Advertised examples now show an embedded Evidence record as its exact
retained-evidence reference when the canonical input accepts one, and
omit an example that can only carry inline Evidence. Canonical contract
examples, their executable tests, and validation are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji
kaoru0822-kitauji force-pushed the fix/mcp-advertised-example-evidence branch from b5471d2 to 1d9a95f Compare October 10, 2026 14:02
@kaoru0822-kitauji
kaoru0822-kitauji merged commit a53689c into main Oct 10, 2026
19 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/mcp-advertised-example-evidence branch October 10, 2026 14:10
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Independent verification of merged #1560 on current main 649661dc, compared with its actual prechange parent 2d426c92, in a separate branch/worktree:

  • Actual pinned SDK stdio discovery exposes all 139 tools. The compact input-facing projection (name, description, inputSchema) is 507,597 -> 393,223 bytes (-22.5%); all input schemas 450,463 -> 336,089 bytes; root example values 129,457 -> 15,265 bytes. The complete SDK catalog is 1,814,907 -> 1,700,533 bytes (-6.3%). These are distinct surfaces, not model tokens or billed-context estimates.
  • Complete catalogs are exactly equal after removing only root input examples. Canonical examples are exactly unchanged. Every canonical and advertised input example validates against the actual SDK-converted advertised schemas and canonical contracts. All advertised input dialects are draft 2020-12. Complete Evidence-bearing advertised examples fall from 19 to zero. The examples of 18 tools change, including ordinary duplicate removal.
  • Two actual 45-byte JavaScript files (values 42/43) pass compiled public CLI and SDK stdio MCP analysis. All five application workflows produce exactly equal complete outputs for inline and same-session retained Evidence, and every result equals the baseline. Text/structured content agrees, inputs/digests remain unchanged and subsequent pings succeed. Self-version comparison and references from a different actual stdio session are correctly rejected.
  • A further actual function-node semantic trace has one matched seed, status found, and equal complete inline/ref outputs. The initial literal-42 query legitimately has no matching literal node in this fixture; no stronger literal coverage is inferred. Export-shape comparison retains its explicit unknown cross-version pairing. Source-to-bundle comparison uses the supplied canonical historical graph fixture; this does not establish a real filesystem/source-importer workflow.
  • 16 exact tests pass without skips across advertised examples, SDK schema validity, retained Evidence/session expiry/malformed inputs, and inline composition. No additional production defect was found in this review. The completed worktree/build and unused generated test catalog were removed; branches and proof/failure receipts remain.

This does not establish native providers, live model API acceptance or real Copilot/Kimi host behavior. #1554 remains open pending actual supported smaller-model workflow proof; #723 retains the separate per-result/text-and-structured output work.

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…to#1560)

Hosts forward every tool's input schema to the model on each request.
Seventeen tools advertised a canonical example that embedded a complete
producer Evidence record, up to 22 KB each, accounting for 116 KB of the
450 KB of advertised input schemas.

Advertised examples now show an embedded Evidence record as its exact
retained-evidence reference when the canonical input accepts one, and
omit an example that can only carry inline Evidence. Canonical contract
examples, their executable tests, and validation are unchanged.
@morluto morluto added bug Something isn't working area: mcp MCP server, transport, and tool registration labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants