* refactor(tools): pass Zod schemas to registerTool instead of raw shapes registerTool accepts either a ZodObject or a raw shape, and passing the schema itself keeps each tool definition closer to how its schema is declared. The advertised JSON Schema is unchanged either way. * fix(server): advertise tool schemas as JSON Schema 2020-12 The SDK converts our Zod schemas on every tools/list with a hardcoded draft-07 target: mcp.js calls toJsonSchemaCompat() without a `target`, and mapMiniTarget(undefined) falls back to 'draft-7'. No registerTool option overrides it, so every schema we advertised declared draft-07. Clients that validate against 2020-12 reject those definitions outright, which takes down the whole tool list rather than a single tool. Separately, brave_place_search's coordinates tuple emitted draft-07's array-form `items`, which is invalid under 2020-12 where positional validation moved to `prefixItems`. SEP-1613 §5 requires servers to generate 2020-12 by default, so re-emit the schemas on the tools/list response. Each correction is conditional, so this decays to a no-op once the SDK emits 2020-12 itself. Refs: https://github.com/modelcontextprotocol/typescript-sdk/issues/2084 * test(server): assert advertised schemas are valid JSON Schema 2020-12 Compile every tool's inputSchema and outputSchema from a real tools/list response with a 2020-12 validator. This runs against the wire format rather than our Zod definitions because the SDK performs the conversion itself: the Zod schemas can be correct while the advertised JSON Schema is not. Compiling resolves whichever dialect a schema declares, so a single check covers both failure modes - a draft-07 declaration, and keywords that are invalid under 2020-12. The SDK's own default client validator is Ajv draft-07 with schema validation disabled, so it accepts output that 2020-12 clients reject; add ajv as a devDependency to check the dialect explicitly.
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { after, before, describe, it } from 'node:test';
|
|
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
import { connectTestClient } from './testUtils/mcpTestHarness.js';
|
|
import tools from './tools/index.js';
|
|
|
|
describe('MCP server <-> SDK Client wiring (in-memory)', () => {
|
|
let client: Client;
|
|
let close: () => Promise<void>;
|
|
|
|
before(async () => {
|
|
({ client, close } = await connectTestClient());
|
|
});
|
|
|
|
after(() => close());
|
|
|
|
it('lists every registered tool with a valid input schema', async () => {
|
|
const { tools: listedTools } = await client.listTools();
|
|
const expectedNames = Object.values(tools)
|
|
.map((tool) => tool.name)
|
|
.sort();
|
|
|
|
assert.deepEqual(listedTools.map((tool) => tool.name).sort(), expectedNames);
|
|
|
|
for (const tool of listedTools) {
|
|
assert.ok(tool.inputSchema, `${tool.name} is missing an inputSchema`);
|
|
}
|
|
});
|
|
|
|
it('advertises valid JSON Schema 2020-12 schemas', async () => {
|
|
const { tools: listedTools } = await client.listTools();
|
|
|
|
// Compiling resolves the declared dialect, so a draft-07 tag fails here as
|
|
// readily as invalid 2020-12 keywords. The SDK does the Zod conversion, so
|
|
// only the wire format is worth asserting.
|
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
|
|
|
for (const tool of listedTools) {
|
|
assert.doesNotThrow(
|
|
() => ajv.compile(tool.inputSchema),
|
|
`${tool.name} has an invalid inputSchema`
|
|
);
|
|
|
|
const { outputSchema } = tool;
|
|
|
|
if (outputSchema) {
|
|
assert.doesNotThrow(
|
|
() => ajv.compile(outputSchema),
|
|
`${tool.name} has an invalid outputSchema`
|
|
);
|
|
}
|
|
}
|
|
});
|
|
});
|