#13302

[Design] MCP/CLI schema compaction, Evidence wire projection, and pagination contract roadmap

Openmorlutoopened 4d ago

Before submitting

  • I searched the open and closed issues and pull requests for a related discussion (#13275, #1065).
  • I understand the contribution scope must be reviewed before integration; open questions are welcome here.
  • This discussion does not include credentials, private samples, or sensitive target data.

Decision needed

Follow-up to #13275 based on live tools/list schema measurements across all 263 REA tools. Should REA adopt four contract-level improvements to cut agent prompt overhead, prevent oversized inline dumps, and stop 23 Evidence-consuming tools from collapsing into uninformative reduced schemas:

  1. Wrap evidenceSchema inside evidenceInputSchema (src/domain/evidenceReference.ts:32-34) with presentCompleteObservation (matching browserScenarioDiffValues.ts / webCaptureDiffSchemas.ts),
  2. Switch high-volume search/inventory/trace tools from detail: "complete" default (src/contracts/analysisDetail.ts:8) to detail: "summary" and/or expose offset/limit/view paging,
  3. Eliminate the reduceToShallowProperties description paradox & Depth-10 full-schema collapse (avoid re-emitting stripped property prose on reduced inputs and reduce only over-depth sub-branches instead of the whole root schema), and
  4. Compact high-byte advertised schema surfaces (update_analysis_settings, inline view unions, repeated detail prose, output=compact envelope repetition) and make canonical advertisedInputExamples / output $id digests lazy or opt-in (src/contracts/toolSchemaMetadata.ts)?

Context and evidence

Live tools/list Byte Measurements (dist/, Node v24.22.1, 263 tools)

(Exact UTF-8 JSON bytes; no tokenizer proxy claimed as exact LLM token counts.)

  • full catalog / output=off (default): 352,285 B total (description: 141,120 B / 40.1%, inputSchema: 159,178 B / 45.2%, annotations: 23,532 B / 6.7%, title+name: 11,612 B, JSON framing: 16,843 B).
  • full catalog / output=compact: 671,130 B total (outputSchema: 314,637 B / 46.9%; 234 of 263 outputs reduced).
  • hot-cold catalog / output=off: 7,549 B total across 5 initial tools (open_binary, binary_session, get_evidence_bundle, close_binary, discover_tools).
  • Pre-compaction canonical schemas: input schemas total 1,500,420 B → compacted to 159,178 B (230 inline, 33 reduced); output schemas total 5,048,287 B (12,985 $defs).

Concrete Contract Defects Found

  1. Missing presentCompleteObservation on evidenceInputSchema (src/domain/evidenceReference.ts:32-34):
    • Every tool taking evidenceInputSchema inlines ~20.7 KiB of full evidenceSchema per Evidence parameter, overflowing the 13 KiB per-tool budget on 23 tools (inspect_analysis_view, trace_application_feature, trace_javascript_semantics, compare_process_captures, compare_wasm_interfaces, import_managed_reconstruction, etc.).
    • compactAdvertisedInputSchema then falls back to reduceToShallowProperties, erasing enums, literal types, and non-Evidence parameter structure AND erasing the {"kind":"retained-evidence","evidence_id":"ev_..."} variant itself.
  2. High-volume tools defaulting to detail: "complete" (src/contracts/analysisDetail.ts:8) or lacking paging:
    • Of 31 detail-capable tools, 28 default to "complete" (only analyze_function and inspect_il2cpp_metadata default to "summary"), causing default calls on list_strings, search_strings, list_procedures, search_procedures, list_names, get_call_graph, trace_feature, inspect_binary_layout, inspect_managed_members, etc. to attempt complete inline serialization.
    • Additional list/search/trace tools (search_android_classes, trace_android_references, get_objc_classes, analyze_swift_types, list_frida_processes, list_adb_*, procedure_assembly) expose neither detail nor offset/limit/view.
  3. reduceToShallowProperties description paradox & Depth-10 cliff:
    • The 230 inline tools strip per-property description fields (except detail), whereas the 33 reduced tools fall back using the unstripped schema and emit 12,576 B of property descriptions (making analyze_web_bundle at 4,755 B reduced the #2 largest advertised input schema).
    • 6 tools well under the 13 KiB cap (analyze_web_bundle, analyze_javascript_application, start_build_computer, verify_reconstruction, check_build_task, export_build_environment) collapse purely because nesting depth exceeds COMPACT_SCHEMA_MAX_DEPTH = 10.
  4. Top wire-size drivers & unused eager canonical work:
    • update_analysis_settings alone is 10,146 B inline (18–33 per-setting branches vs one canonical schema + compact wire union { setting: enum[...], action: "set"|"reset", value? }).
    • 10 inline view unions account for 20,674 B (13.0% of all inputSchema bytes); 37 retained detail descriptions repeat 9,231 B (27 copies of analysisDetailSchema's 234-byte text).
    • output=compact repeats OUTPUT_REDUCED_ANNOTATION 233x (~31.7 KiB) and "$schema" 262x (~15.2 KiB), plus ~220 copies of the 19-field Evidence root properties (~1.3 KiB each).
    • toolInputSchemaWithMetadata (src/contracts/toolSchemaMetadata.ts:151) computes 319 advertisedInputExamples (~35.7 KiB) on every contract even though compactInputSchema strips examples, and toolOutputSchemaWithMetadata (line 216) digests 5.05 MB of canonical output schema for $id even when output=off or output=compact drops $id.
    • search_guidance / read_guidance_section wrap live output in { result: ... } while canonical outputSchema is a root oneOf, causing a minor live-vs-catalog output=compact discrepancy.
    • Follow-up build/CLI items from #13275: pre-generating dist/mcp-catalog-compact-outputs.json so REA_MCP_OUTPUT_SCHEMA_PROFILE=compact stays deferred at startup, and per-command splitting of binaryDiagnosticsCommands.ts.

Expected interaction with targets

  • No target interaction (documentation or usability only)

Boundary details (optional)

  • Canonical Zod schemas remain the single runtime validation owner for inputs and outputs; advertised schema changes must preserve validateAdvertisedSchema dialect guarantees (advertisedInputDialectViolations) and keep canonical error recovery actionable when inputs fail full server-side constraints.
  • Changing default detail from "complete" to "summary" is a user-visible MCP/CLI contract change requiring maintainer alignment (and updating callers/tests/docs that assume complete inline output when detail is omitted).

Options and tradeoffs

  • Option A (presentCompleteObservation on evidenceInputSchema): Keeps non-Evidence parameter schemas & enums intact across the 23 affected tools and exposes retained-evidence cleanly, at the cost of modestly increasing full inputSchema bytes (~350 B reduced → ~1.5–8 KiB inline) while adding 0 B in hot-cold.
  • Option B (detail: "summary" default + offset/limit on high-volume native/Android/Frida tools): Prevents accidental multi-megabyte default replies and extra inspect_analysis_view round-trips, requiring a coordinated contract/test transition.
  • Option C (Subtree-only depth pruning + consistent annotation stripping in reduceToShallowProperties): Keeps root/sibling fields intact on the 6 depth->10 tools and removes the 12.6 KiB reduced description paradox.

Verification available so far

  • I have a prototype or observed results

Success criteria and open questions

  • Should evidenceInputSchema adopt presentCompleteObservation so 23 Evidence-consuming tools stop collapsing into reduced stubs?
  • Which high-volume search/list tools should standardize on detail: "summary" default and/or direct offset/limit pagination?
  • Should update_analysis_settings and repeated inline view unions keep strict validation server-side while advertising a single flattened union on the MCP wire?

References

  • Related issues: #13275, #1065
  • src/domain/evidenceReference.ts:32-34
  • src/contracts/analysisDetail.ts:5-36
  • src/contracts/compactInputSchema.ts:37, 75-106
  • src/contracts/compactJsonSchema.ts:175-178
  • src/contracts/toolSchemaMetadata.ts:100-223

Activity

0

No activity yet.