Files
reverse-engineering-anything/scripts/lib/canonical-output-schema.mjs
T
morluto 960a387731 refactor(contracts): own CLI command names, catalog identity and schema presentation in contracts (#11425)
* refactor(contracts): move the CLI command name owner into src/contracts

* refactor(contracts): own catalog identity in contracts and server identity in process (#11435)

* refactor(contracts): move catalog identity into contracts and server identity into process

* refactor(contracts): own the advertised MCP schema presentation in contracts

* test(mcp): import the advertised presentation from contracts in toolSchemaValidity

* test(release): expect the catalog identity at its contracts path in the canary

* test(mcp): import the catalog identity from contracts in syntheticContractSurfaces

* refactor(contracts): import CLI command names from contracts in the capability conformance test
2026-11-16 05:31:37 +08:00

25 lines
1.1 KiB
JavaScript

import { z } from "zod";
import { DISCOVER_TOOLS } from "../../dist/contracts/catalog/catalogDiscovery.js";
import { TOOL_CONTRACTS } from "../../dist/contracts/toolContracts.js";
import { advertisedOutputJsonSchema } from "../../dist/contracts/toolSchemaMetadata.js";
/**
* The canonical output JSON Schema for one tool. `tools/list` omits output
* schemas by default (or bounds them), so verifiers validate replies against
* the compiled contract instead of a listed definition.
*/
export const canonicalOutputSchema = (name) => {
// Transport discovery is registered from its own schema, not a tool contract.
if (name === DISCOVER_TOOLS.name)
return z.toJSONSchema(DISCOVER_TOOLS.outputSchema, { io: "output" });
const contract = TOOL_CONTRACTS.find((candidate) => candidate.name === name);
if (contract === undefined) throw new Error(`No tool contract named ${name}`);
return advertisedOutputJsonSchema(contract);
};
/** A listed tool definition whose output schema the SDK client validates against. */
export const withCanonicalOutputSchema = (tool) => ({
...tool,
outputSchema: canonicalOutputSchema(tool.name),
});