mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 07:16:13 +00:00
* 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 (#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 <76467478+morluto@users.noreply.github.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { ConfigurationError } from "../domain/configurationErrors.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
|
|
// Moonshot's function-calling API rejects requests while any single tool
|
|
// parameters schema exceeds its literal serialized size cap. Community
|
|
// measurements bound the cap between ~13.7 KB (accepted) and ~15 KB
|
|
// (rejected); 13 KiB leaves margin under the lower bound. See
|
|
// https://github.com/morluto/rea/issues/1484 for the measured evidence.
|
|
export const COMPACT_INPUT_SCHEMA_BUDGET_BYTES = 13 * 1024;
|
|
|
|
export const mcpInputSchemaProfileSchema = z.enum(["full", "compact"]);
|
|
|
|
const profileConstraint =
|
|
'REA_MCP_INPUT_SCHEMA_PROFILE must be "full" (default) or "compact". The compact profile advertises input schemas without nested annotation prose for providers that cap each tool schema\'s serialized size.';
|
|
|
|
export type McpInputSchemaProfile = z.infer<typeof mcpInputSchemaProfileSchema>;
|
|
|
|
/** Parse the advertised input schema presentation selection. */
|
|
export const parseMcpInputSchemaProfile = (
|
|
value: string | undefined,
|
|
): Result<McpInputSchemaProfile | undefined, ConfigurationError> => {
|
|
if (value === undefined) return ok(undefined);
|
|
const parsed = mcpInputSchemaProfileSchema.safeParse(value);
|
|
return parsed.success
|
|
? ok(parsed.data)
|
|
: err(
|
|
new ConfigurationError(profileConstraint, {
|
|
settings: [
|
|
{
|
|
setting: "REA_MCP_INPUT_SCHEMA_PROFILE",
|
|
constraint: profileConstraint,
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
};
|