fix(mcp): advertise primitive semantic literal seeds

This commit is contained in:
morluto
2026-10-10 03:52:35 +08:00
parent 218c13160e
commit f62b44971d
2 changed files with 34 additions and 12 deletions
@@ -8,22 +8,16 @@ import {
javaScriptSemanticEvidenceContextSchema,
javaScriptSemanticUnknownSchema,
} from "./javascriptSemanticGraphSchemas.js";
import { jsonValueSchema } from "../jsonValue.js";
import { digestSchema } from "../digests.js";
import { prefixedDigestSchema } from "../digests.js";
const semanticNodeIdSchema = prefixedDigestSchema("jsrg_node");
const literalValueSchema = jsonValueSchema.refine(
(value) =>
value === null ||
typeof value === "string" ||
typeof value === "number" ||
typeof value === "boolean",
"Literal seeds accept only JSON primitive values",
);
// Zod derivations drop the shared schema's JSON Schema projection override;
// re-apply it so MCP catalog generation keeps projecting `{}`.
literalValueSchema._zod.toJSONSchema = () => ({});
const literalValueSchema = z.union([
z.string(),
z.number(),
z.boolean(),
z.null(),
]);
const literalSeedSchema = z.strictObject({
kind: z.literal("literal"),
@@ -37,6 +37,34 @@ async function connect() {
return { client, session };
}
it("advertises the primitive literal seeds accepted by semantic tracing", async () => {
const { client } = await connect();
const { tools } = await client.listTools();
const tool = tools.find(({ name }) => name === "trace_javascript_semantics");
if (tool === undefined) throw new Error("Semantic trace tool is missing");
const validate = new Ajv2020({
strict: false,
validateFormats: false,
}).compile(tool.inputSchema);
for (const value of ["literal", 42, true, null, {}, []]) {
const primitive = value === null || typeof value !== "object";
const arguments_ = {
application,
query: {
seed: { kind: "literal", value },
direction: "backward-provenance",
},
};
expect(validate(arguments_), JSON.stringify(value)).toBe(primitive);
const result = await client.callTool({
name: tool.name,
arguments: arguments_,
});
if (primitive) expect(result.isError).not.toBe(true);
else expect(result.isError).toBe(true);
}
});
it("runs the same trace/compare workflows with inline and retained application Evidence", async () => {
const { client, session } = await connect();
expect(session.recordEvidence(pair.left).ok).toBe(true);