perf(mcp): share repeated output schema definitions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { inlineLocalJsonSchemaReferences } from "../../tests/fixtures/localJsonSchemaReferences.js";
|
||||
import { TOOL_CONTRACTS, toolContract } from "./toolContracts.js";
|
||||
import {
|
||||
toolInputSchemaWithMetadata,
|
||||
@@ -19,8 +20,13 @@ describe("advertised tool JSON Schema", () => {
|
||||
expect(advertisedInput.examples, contract.name).toEqual(
|
||||
contract.examples.map(({ input: example }) => example),
|
||||
);
|
||||
expect(advertisedOutput, contract.name).toEqual(
|
||||
contract.outputSchema["~standard"].jsonSchema.output({ target }),
|
||||
expect(
|
||||
inlineLocalJsonSchemaReferences(advertisedOutput),
|
||||
contract.name,
|
||||
).toEqual(
|
||||
inlineLocalJsonSchemaReferences(
|
||||
contract.outputSchema["~standard"].jsonSchema.output({ target }),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -34,4 +40,46 @@ describe("advertised tool JSON Schema", () => {
|
||||
expect(latest.$schema).toBe("https://json-schema.org/draft/2020-12/schema");
|
||||
expect(draft07.$schema).toBe("http://json-schema.org/draft-07/schema#");
|
||||
});
|
||||
|
||||
it("preserves complete output meaning across JSON Schema dialects", () => {
|
||||
for (const dialect of ["draft-2020-12", "draft-07"] as const)
|
||||
for (const contract of TOOL_CONTRACTS) {
|
||||
const advertised = toolOutputSchemaWithMetadata(contract)[
|
||||
"~standard"
|
||||
].jsonSchema.output({ target: dialect });
|
||||
const canonical = contract.outputSchema["~standard"].jsonSchema.output({
|
||||
target: dialect,
|
||||
});
|
||||
expect(
|
||||
inlineLocalJsonSchemaReferences(advertised),
|
||||
contract.name,
|
||||
).toEqual(inlineLocalJsonSchemaReferences(canonical));
|
||||
}
|
||||
});
|
||||
|
||||
it("retains memoization and explicit caller projection options", () => {
|
||||
const contract = toolContract("analyze_javascript_application");
|
||||
const output =
|
||||
toolOutputSchemaWithMetadata(contract)["~standard"].jsonSchema;
|
||||
const shared = output.output({ target });
|
||||
expect(shared.$defs).toBeDefined();
|
||||
expect(output.output({ target })).toBe(shared);
|
||||
const options = { target, libraryOptions: { reused: "inline" } };
|
||||
const inline = output.output(options);
|
||||
expect(inline).toEqual(
|
||||
contract.outputSchema["~standard"].jsonSchema.output(options),
|
||||
);
|
||||
expect(inline.$defs).toBeUndefined();
|
||||
expect(output.output({ target })).toBe(shared);
|
||||
const draft07 = output.output({ target: "draft-07" });
|
||||
expect(draft07.$schema).toBe("http://json-schema.org/draft-07/schema#");
|
||||
expect(inlineLocalJsonSchemaReferences(draft07)).toEqual(
|
||||
inlineLocalJsonSchemaReferences(
|
||||
contract.outputSchema["~standard"].jsonSchema.output({
|
||||
target: "draft-07",
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(output.output({ target: "draft-07" })).toBe(draft07);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user