fix(mcp): emit valid schemas for empty arrays (#535)
Replace empty tuples with a shared empty-array schema. Validate all input and output schemas against Draft 2020-12 during catalog generation and packaged MCP verification, with runtime and catalog regression coverage. Closes #528 Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -2,6 +2,7 @@ import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { format } from "prettier";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
|
||||
@@ -28,6 +29,16 @@ const sessionToolNames = new Set([
|
||||
...MANAGED_WORKFLOW_TOOL_CONTRACTS.map(({ name }) => name),
|
||||
]);
|
||||
const advertisedTools = await sdkToolCatalog();
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
for (const tool of advertisedTools.values()) {
|
||||
for (const kind of ["inputSchema", "outputSchema"]) {
|
||||
const schema = tool[kind];
|
||||
if (schema !== undefined && !ajv.validateSchema(schema))
|
||||
throw new Error(
|
||||
`Invalid JSON Schema for ${tool.name}.${kind}: ${ajv.errorsText(ajv.errors)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const catalog = TOOL_CONTRACTS.map((contract) => {
|
||||
const advertised = advertisedTools.get(contract.name);
|
||||
if (advertised === undefined)
|
||||
|
||||
Reference in New Issue
Block a user