fix: update registerTool signature for proper typed ToolCallback (#1188)

Co-authored-by: Gavin <gching@users.noreply.github.com>
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
This commit is contained in:
Matt 2025-11-28 16:14:26 +00:00 • committed by GitHub
commit b37f08ae3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 13 deletions

View file

@ -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' }]
})
);

View file

@ -1030,7 +1030,7 @@ export class McpServer {
/**
* Registers a tool with a config object and callback.
*/
registerTool<InputArgs extends ZodRawShapeCompat | AnySchema, OutputArgs extends ZodRawShapeCompat | AnySchema>(
registerTool<OutputArgs extends ZodRawShapeCompat | AnySchema, InputArgs extends undefined | ZodRawShapeCompat | AnySchema = undefined>(
name: string,
config: {
title?: string;