Skip to content

feat(mcp): compact input schema profile for size-capped providers (kimi-cli/Moonshot) - #1514

Merged
morluto merged 3 commits into
morluto:mainfrom
haythemsellami:feat/mcp-compact-input-schema-profile
Oct 10, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
haythemsellami:feat/mcp-compact-input-schema-profile

Conversation

@haythemsellami

Copy link
Copy Markdown
Contributor

Fixes #1484

Problem

Moonshot's function-calling API rejects a request while any single tool parameters schema exceeds its literal serialized size cap (community measurements bound it between ~13.7 KB accepted and ~15 KB rejected). Clients that forward every advertised tool on every request — kimi-cli today — fail every turn with 400 tools.function.parameters is not a valid moonshot flavored json schema ... schema exceeds maximum allowed size while REA is connected, even for unrelated prompts. On the default catalog, 44 of 139 advertised input schemas exceed that cap, the largest at ~87 KB.

Change

Add an opt-in advertised-input presentation selected by the server environment variable REA_MCP_INPUT_SCHEMA_PROFILE=compact (default full, parsed and validated like REA_MCP_MAX_RESPONSE_BYTES, read at startup). When active, each advertised input schema is rendered within a 13,312-byte budget — chosen to sit below the lowest observed accepted size:

  1. Shared presentation: nested annotation prose (descriptions, examples, defaults, titles) leaves the advertised form, and repeated annotation-free subschemas are shared through schema-local $defs/$ref, which the provider validates without expansion. Validation keywords, the root's input-group description, and literal const/enum data are untouched. The root's echoed examples are dropped with the other annotations.
  2. Reduced presentation (three structurally oversized tools: compare_web_captures, build_reconstruction_obligation_ledger, evaluate_reconstruction_coverage): property names, detected types, first-level guidance, and root required-field constraints, with nested validation detail elided and an explicit annotation that the advertisement is reduced.

Unchanged by design, per #723's boundaries: the canonical catalog and tool set, output schemas, tool descriptions and annotations, the registered canonical Zod parsers, and server-side canonical validation. The default full profile advertises byte-identical schemas to main. The compaction is applied at the EvidenceMcpServer registration seam and wraps any standard-schema registration, including plain non-Zod standard schemas such as inspect_web_network_capture's.

Measured on the live 139-tool catalog: advertised input bytes 522,914 → 183,615 (−65%), every tool ≤ 13,312 bytes.

Validation

  • New unit tests (src/contracts/compactInputSchema.test.ts): annotation stripping keeps validation keywords and literal data, reference sharing resolves and reuses existing definitions, no self-referential definitions, determinism, reduced-tier shape and budget.
  • New conformance tests for the profile setting parser (mirrors mcpResponseBudget).
  • New boundary tests (tests/boundary/mcp/compactInputSchemaMcp.test.ts): loopback discovery of the complete catalog under the compact profile — every input schema within budget, Ajv 2020-12 valid, every canonical example still accepted, output schemas and descriptions byte-identical to the full profile, a ratchet holding reduced presentations at ≤ 3, canonical rejection of reserved arguments the (permissive) advertisement accepts, and the plain-standard-schema registration path.
  • Full mcp-boundary lane: 325 passed (nativeDemangleMcp requires the host's real swift-demangle, unavailable in this sandbox and unrelated).
  • Typecheck, architecture guards, docs:check, and skill/catalog artifact regeneration pass. npm run lint carries the same pre-existing error on main (JavaScriptSemanticGraphBuilder.ts max-lines); this change adds no new lint errors.
  • Real-provider verification: through kimi-cli against the real Moonshot API, prompts succeed with the compact catalog attached where the default catalog fails every request with the 400 above. The three reduced tools were advertised and accepted; their usability for model-driven calls was not separately benchmarked.

Usage

{
  "mcpServers": {
    "rea": {
      "command": "npx",
      "args": ["-y", "rea-agents@latest", "mcp"],
      "env": { "REA_MCP_INPUT_SCHEMA_PROFILE": "compact" }
    }
  }
}

Open follow-ups outside this PR: reporting the active profile in binary_session identity, and a client-side graceful-degradation fix in kimi-cli (drop the oversized tool with a warning instead of failing every request) so one oversized server cannot brick the client.

Moonshot's function-calling API rejects a request while any single tool
parameters schema exceeds its literal serialized size cap, so clients
such as kimi-cli fail every request while the default catalog is
attached (#1484).

Add an opt-in REA_MCP_INPUT_SCHEMA_PROFILE=compact server presentation.
Each advertised input schema is rendered within a 13,312-byte budget,
measured to sit below the observed provider cap: annotation prose
(nested descriptions, examples, defaults, titles) is dropped, repeated
annotation-free subschemas are shared through schema-local $defs/$ref
references the provider validates without expansion, and the three
structurally oversized schemas are advertised in a documented reduced
form. The canonical catalog, tool set, output schemas, and server-side
canonical validation are unchanged; the default full profile is
byte-identical to today's advertisement.

Boundary tests pin every compact schema to the budget, keep them valid
JSON Schema that still accepts every canonical example, hold reduced
presentations at three or fewer, and verify canonical rejection still
guards a permissive advertisement. Verified against the real Moonshot
API through kimi-cli: prompts succeed with the compact catalog attached
where the default catalog fails every request with 400.
@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.

@morluto
morluto merged commit b6ad1f2 into morluto:main Oct 10, 2026
26 checks passed
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…mi-cli/Moonshot) (morluto#1514)

* feat(mcp): add compact input schema profile for size-capped providers

Moonshot's function-calling API rejects a request while any single tool
parameters schema exceeds its literal serialized size cap, so clients
such as kimi-cli fail every request while the default catalog is
attached (morluto#1484).

Add an opt-in REA_MCP_INPUT_SCHEMA_PROFILE=compact server presentation.
Each advertised input schema is rendered within a 13,312-byte budget,
measured to sit below the observed provider cap: annotation prose
(nested descriptions, examples, defaults, titles) is dropped, repeated
annotation-free subschemas are shared through schema-local $defs/$ref
references the provider validates without expansion, and the three
structurally oversized schemas are advertised in a documented reduced
form. The canonical catalog, tool set, output schemas, and server-side
canonical validation are unchanged; the default full profile is
byte-identical to today's advertisement.

Boundary tests pin every compact schema to the budget, keep them valid
JSON Schema that still accepts every canonical example, hold reduced
presentations at three or fewer, and verify canonical rejection still
guards a permissive advertisement. Verified against the real Moonshot
API through kimi-cli: prompts succeed with the compact catalog attached
where the default catalog fails every request with 400.

* fix(mcp): preserve compact schemas through Kimi conversion

---------

Co-authored-by: morluto <[email protected]>
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Welcome, @haythemsellami. Thanks for working through the Kimi CLI/Moonshot failure and testing the compact profile against the real API. The opt-in setting gives people hitting that schema limit a way to keep using REA.

@morluto morluto added enhancement New feature or request area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: mcp MCP server, transport, and tool registration label Nov 23, 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 area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Moonshot clients reject every request while REA is connected: advertised tool schemas exceed the per-schema size cap (kimi-cli unusable)

2 participants