address comments: 1. validate schemas w/o codegen, 2. relax no-structured-output restriction

This commit is contained in:
Basil Hosmer 2025-05-14 10:52:20 -04:00
commit 18c7e795a0
No known key found for this signature in database

View file

@ -1261,72 +1261,5 @@ describe('outputSchema validation', () => {
);
});
/***
* Test: Throw Error when Tool Without outputSchema Returns structuredContent
*/
test('should throw error when tool without outputSchema returns structuredContent', async () => {
const server = new Server({
name: 'test-server',
version: '1.0.0',
}, {
capabilities: {
tools: {},
},
});
// Set up server handlers
server.setRequestHandler(InitializeRequestSchema, async (request) => ({
protocolVersion: request.params.protocolVersion,
capabilities: {},
serverInfo: {
name: 'test-server',
version: '1.0.0',
}
}));
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: 'test-tool',
description: 'A test tool',
inputSchema: {
type: 'object',
properties: {},
},
// No outputSchema defined
},
],
}));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === 'test-tool') {
// Incorrectly return structuredContent for a tool without outputSchema
return {
structuredContent: { result: 'This should not be allowed' },
};
}
throw new Error('Unknown tool');
});
const client = new Client({
name: 'test-client',
version: '1.0.0',
});
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([
client.connect(clientTransport),
server.connect(serverTransport),
]);
// List tools to cache the schemas
await client.listTools();
// Call the tool - should throw validation error
await expect(client.callTool({ name: 'test-tool' })).rejects.toThrow(
/Tool without outputSchema cannot return structuredContent/
);
});
});