feat(mcp): compact input schema profile for size-capped providers (kimi-cli/Moonshot) (#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 (#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>
This commit is contained in:
co-authored by
morluto
parent
2b6f14f528
commit
b6ad1f2c3d
@@ -15,6 +15,11 @@ import {
|
||||
type ToolResultDelivery,
|
||||
} from "./toolResult.js";
|
||||
import { parseMcpResponseBudget } from "../config/mcpResponseBudget.js";
|
||||
import {
|
||||
COMPACT_INPUT_SCHEMA_BUDGET_BYTES,
|
||||
parseMcpInputSchemaProfile,
|
||||
} from "../config/mcpInputSchemaProfile.js";
|
||||
import type { CompactInputSchemaPresentation } from "./EvidenceMcpServer.js";
|
||||
import { isAbsolute } from "node:path";
|
||||
|
||||
import type { BinarySessionPort } from "../application/binary/BinarySessionPort.js";
|
||||
@@ -148,6 +153,7 @@ const installSessionToolAvailability = (
|
||||
const createMcpServer = (
|
||||
session: BinarySessionPort | undefined,
|
||||
delivery: ToolResultDelivery,
|
||||
compactPresentation: CompactInputSchemaPresentation | undefined,
|
||||
): EvidenceMcpServer =>
|
||||
new EvidenceMcpServer(
|
||||
{
|
||||
@@ -165,6 +171,7 @@ const createMcpServer = (
|
||||
? undefined
|
||||
: (evidence) => session.recordEvidence(evidence),
|
||||
delivery,
|
||||
compactPresentation,
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -183,7 +190,11 @@ export const createServer = (
|
||||
const selectedOptions = { ...options, environment, delivery };
|
||||
const startedAt = new Date().toISOString();
|
||||
const logger = options.logger ?? silentLogger;
|
||||
const server = createMcpServer(session, delivery);
|
||||
const server = createMcpServer(
|
||||
session,
|
||||
delivery,
|
||||
selectCompactInputSchemaPresentation(environment),
|
||||
);
|
||||
const android =
|
||||
options.androidAnalysis ?? createAndroidAnalysisProvider(environment);
|
||||
const availability = installSessionToolAvailability(
|
||||
@@ -256,6 +267,18 @@ const selectToolResultDelivery = (
|
||||
return createToolResultDelivery(configured.value);
|
||||
};
|
||||
|
||||
const selectCompactInputSchemaPresentation = (
|
||||
environment: Readonly<NodeJS.ProcessEnv>,
|
||||
): CompactInputSchemaPresentation | undefined => {
|
||||
const configured = parseMcpInputSchemaProfile(
|
||||
environment.REA_MCP_INPUT_SCHEMA_PROFILE,
|
||||
);
|
||||
if (!configured.ok) throw configured.error;
|
||||
return configured.value === "compact"
|
||||
? { budgetBytes: COMPACT_INPUT_SCHEMA_BUDGET_BYTES }
|
||||
: undefined;
|
||||
};
|
||||
|
||||
const registerConfiguredAnalysisTools = (
|
||||
{
|
||||
server,
|
||||
|
||||
Reference in New Issue
Block a user