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

Closed
opened 2026-10-17 21:11:59 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1514
Author: @haythemsellami
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/10/2026
Merged by: @morluto

Base: main ← Head: feat/mcp-compact-input-schema-profile


📝 Commits (3)

  • 06b12d8 feat(mcp): add compact input schema profile for size-capped providers
  • e7acfd2 fix(mcp): preserve compact schemas through Kimi conversion
  • cdfdbfb chore: merge main into compact schema profile

📊 Changes

15 files changed (+1190 additions, -18 deletions)

View changed files

📝 docs/mcp-contracts.md (+43 -0)
📝 src/config/environment.ts (+2 -0)
➕ src/config/mcpInputSchemaProfile.ts (+38 -0)
📝 src/config/parseConfig.ts (+3 -0)
📝 src/config/types.ts (+3 -0)
➕ src/contracts/compactInputSchema.test.ts (+314 -0)
➕ src/contracts/compactInputSchema.ts (+311 -0)
📝 src/contracts/inputSchemaPresentation.ts (+3 -3)
📝 src/contracts/toolSchemaMetadata.ts (+43 -0)
📝 src/server/EvidenceMcpServer.ts (+76 -0)
📝 src/server/createServer.ts (+24 -1)
➕ tests/boundary/mcp/compactInputSchemaMcp.test.ts (+281 -0)
📝 tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts (+6 -4)
➕ tests/conformance/contracts/mcpInputSchemaProfile.test.ts (+29 -0)
📝 tests/process-global/mcpDeliveryEnvironment.test.ts (+14 -10)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/1514 **Author:** [@haythemsellami](https://github.com/haythemsellami) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/10/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `feat/mcp-compact-input-schema-profile` --- ### 📝 Commits (3) - [`06b12d8`](https://github.com/morluto/rea/commit/06b12d8d471adfa28477d745ccc08553f709152e) feat(mcp): add compact input schema profile for size-capped providers - [`e7acfd2`](https://github.com/morluto/rea/commit/e7acfd2e23191c08cdcb097ca49b13511d30b9da) fix(mcp): preserve compact schemas through Kimi conversion - [`cdfdbfb`](https://github.com/morluto/rea/commit/cdfdbfbb6db87268550150ed5b558f43d22d94b2) chore: merge main into compact schema profile ### 📊 Changes **15 files changed** (+1190 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `docs/mcp-contracts.md` (+43 -0) 📝 `src/config/environment.ts` (+2 -0) ➕ `src/config/mcpInputSchemaProfile.ts` (+38 -0) 📝 `src/config/parseConfig.ts` (+3 -0) 📝 `src/config/types.ts` (+3 -0) ➕ `src/contracts/compactInputSchema.test.ts` (+314 -0) ➕ `src/contracts/compactInputSchema.ts` (+311 -0) 📝 `src/contracts/inputSchemaPresentation.ts` (+3 -3) 📝 `src/contracts/toolSchemaMetadata.ts` (+43 -0) 📝 `src/server/EvidenceMcpServer.ts` (+76 -0) 📝 `src/server/createServer.ts` (+24 -1) ➕ `tests/boundary/mcp/compactInputSchemaMcp.test.ts` (+281 -0) 📝 `tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts` (+6 -4) ➕ `tests/conformance/contracts/mcpInputSchemaProfile.test.ts` (+29 -0) 📝 `tests/process-global/mcpDeliveryEnvironment.test.ts` (+14 -10) </details> ### 📄 Description 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 ```json { "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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-17 21:11:59 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2934
No description provided.