Skip to content

Commit 9d1724a

Browse files
committed
fix: Support updating output schema
1 parent e74a358 commit 9d1724a

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/server/mcp.test.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,95 @@ describe('tool()', () => {
453453
expect(notifications).toHaveLength(0);
454454
});
455455

456+
/***
457+
* Test: Updating Tool with outputSchema
458+
*/
459+
test('should update tool with outputSchema', async () => {
460+
const mcpServer = new McpServer({
461+
name: 'test server',
462+
version: '1.0'
463+
});
464+
const notifications: Notification[] = [];
465+
const client = new Client({
466+
name: 'test client',
467+
version: '1.0'
468+
});
469+
client.fallbackNotificationHandler = async notification => {
470+
notifications.push(notification);
471+
};
472+
473+
// Register initial tool
474+
const tool = mcpServer.registerTool(
475+
'test',
476+
{
477+
outputSchema: {
478+
result: z.number()
479+
}
480+
},
481+
async () => ({
482+
content: [{ type: 'text', text: '' }],
483+
structuredContent: {
484+
result: 42
485+
}
486+
})
487+
);
488+
489+
// Update the tool with a different outputSchema
490+
tool.update({
491+
outputSchema: {
492+
result: z.number(),
493+
sum: z.number()
494+
},
495+
callback: async () => ({
496+
content: [{ type: 'text', text: '' }],
497+
structuredContent: {
498+
result: 42,
499+
sum: 100
500+
}
501+
})
502+
});
503+
504+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
505+
506+
await Promise.all([client.connect(clientTransport), mcpServer.connect(serverTransport)]);
507+
508+
// Verify the outputSchema was updated
509+
const listResult = await client.request(
510+
{
511+
method: 'tools/list'
512+
},
513+
ListToolsResultSchema
514+
);
515+
516+
expect(listResult.tools[0].outputSchema).toMatchObject({
517+
type: 'object',
518+
properties: {
519+
result: { type: 'number' },
520+
sum: { type: 'number' }
521+
}
522+
});
523+
524+
// Call the tool to verify it works with the updated outputSchema
525+
const callResult = await client.request(
526+
{
527+
method: 'tools/call',
528+
params: {
529+
name: 'test',
530+
arguments: {}
531+
}
532+
},
533+
CallToolResultSchema
534+
);
535+
536+
expect(callResult.structuredContent).toEqual({
537+
result: 42,
538+
sum: 100
539+
});
540+
541+
// Update happened before transport was connected, so no notifications should be expected
542+
expect(notifications).toHaveLength(0);
543+
});
544+
456545
/***
457546
* Test: Tool List Changed Notifications
458547
*/

src/server/mcp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ export class McpServer {
672672
if (typeof updates.title !== 'undefined') registeredTool.title = updates.title;
673673
if (typeof updates.description !== 'undefined') registeredTool.description = updates.description;
674674
if (typeof updates.paramsSchema !== 'undefined') registeredTool.inputSchema = z.object(updates.paramsSchema);
675+
if (typeof updates.outputSchema !== 'undefined') registeredTool.outputSchema = z.object(updates.outputSchema);
675676
if (typeof updates.callback !== 'undefined') registeredTool.callback = updates.callback;
676677
if (typeof updates.annotations !== 'undefined') registeredTool.annotations = updates.annotations;
677678
if (typeof updates._meta !== 'undefined') registeredTool._meta = updates._meta;

0 commit comments

Comments
 (0)