From a563e447aa23b526c1bf2035e6fb4e12e5f918f4 Mon Sep 17 00:00:00 2001 From: Matt Carey Date: Fri, 28 Nov 2025 12:49:03 +0000 Subject: [PATCH] fix: update registerTool signature for proper typed ToolCallback Swap generic type parameters and make InputArgs default to undefined, so callbacks are properly typed as (extra) => Result when no inputSchema is provided, eliminating the need for `as const` workarounds. Co-Authored-By: Gavin --- src/server/mcp.test.ts | 24 ++++++++++++------------ src/server/mcp.ts | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/server/mcp.test.ts b/src/server/mcp.test.ts index 2ad40ba5a..aa9a1477d 100644 --- a/src/server/mcp.test.ts +++ b/src/server/mcp.test.ts @@ -639,7 +639,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { async () => ({ content: [ { - type: 'text' as const, + type: 'text', text: 'Test response' } ] @@ -694,7 +694,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { async () => ({ content: [ { - type: 'text' as const, + type: 'text', text: 'Test response' } ] @@ -876,7 +876,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { } }, async () => ({ - content: [{ type: 'text' as const, text: 'Test response' }] + content: [{ type: 'text', text: 'Test response' }] }) ); @@ -1928,7 +1928,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { { description: 'A valid tool name' }, - async () => ({ content: [{ type: 'text' as const, text: 'Success' }] }) + async () => ({ content: [{ type: 'text', text: 'Success' }] }) ); // Test tool name with warnings (starts with dash) @@ -1937,7 +1937,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { { description: 'A tool name that generates warnings' }, - async () => ({ content: [{ type: 'text' as const, text: 'Success' }] }) + async () => ({ content: [{ type: 'text', text: 'Success' }] }) ); // Test invalid tool name (contains spaces) @@ -1946,7 +1946,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { { description: 'An invalid tool name' }, - async () => ({ content: [{ type: 'text' as const, text: 'Success' }] }) + async () => ({ content: [{ type: 'text', text: 'Success' }] }) ); // Verify that warnings were issued (both for warnings and validation failures) @@ -3894,7 +3894,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { // Tool 1: Only name mcpServer.tool('tool_name_only', async () => ({ - content: [{ type: 'text' as const, text: 'Response' }] + content: [{ type: 'text', text: 'Response' }] })); // Tool 2: Name and annotations.title @@ -3905,7 +3905,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { title: 'Annotations Title' }, async () => ({ - content: [{ type: 'text' as const, text: 'Response' }] + content: [{ type: 'text', text: 'Response' }] }) ); @@ -3917,7 +3917,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { description: 'Tool with regular title' }, async () => ({ - content: [{ type: 'text' as const, text: 'Response' }] + content: [{ type: 'text', text: 'Response' }] }) ); @@ -3932,7 +3932,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { } }, async () => ({ - content: [{ type: 'text' as const, text: 'Response' }] + content: [{ type: 'text', text: 'Response' }] }) ); @@ -5009,7 +5009,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { description: 'Tool with regular title' }, async () => ({ - content: [{ type: 'text' as const, text: 'Response' }] + content: [{ type: 'text', text: 'Response' }] }) ); @@ -5024,7 +5024,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { } }, async () => ({ - content: [{ type: 'text' as const, text: 'Response' }] + content: [{ type: 'text', text: 'Response' }] }) ); diff --git a/src/server/mcp.ts b/src/server/mcp.ts index 68a81764a..c097ae531 100644 --- a/src/server/mcp.ts +++ b/src/server/mcp.ts @@ -1030,7 +1030,7 @@ export class McpServer { /** * Registers a tool with a config object and callback. */ - registerTool( + registerTool( name: string, config: { title?: string;