fix: reject plain JSON Schema objects passed as inputSchema (#1596)

Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>
This commit is contained in:
Tilak Dave 2026-03-23 20:15:17 +05:30 • committed by GitHub
commit 93640d33ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2050,6 +2050,37 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
// Clean up spies
warnSpy.mockRestore();
});
test('should reject plain JSON Schema objects passed as inputSchema', () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});
const jsonSchema = {
type: 'object',
properties: {
directory_id: {
type: 'string',
format: 'uuid',
description: 'The UUID of the directory'
}
},
required: ['directory_id']
} as any;
const cb = async ({ directory_id }: any) => ({
content: [{ type: 'text' as const, text: `Got: ${directory_id}` }]
});
expect(() => {
mcpServer.tool('test', 'A tool', jsonSchema, cb);
}).toThrow(/unrecognized object/);
expect(() => {
mcpServer.registerTool('test', { description: 'A tool', inputSchema: jsonSchema }, cb);
}).toThrow(/unrecognized object/);
});
});
describe('resource()', () => {