Skip to content

Commit 68ccf6c

Browse files
fix: prevent TS2589 type instantiation error in ToolCallback
Use [T] extends [U] pattern on the AnySchema check to prevent distributive conditional types. This fixes the "Type instantiation is excessively deep and possibly infinite" error that occurs when using registerTool after upgrading to v1.23.0. The issue was that AnySchema (z3.ZodTypeAny | z4.$ZodType) as a union caused TypeScript to distribute the conditional type check, leading to exponential type instantiation. Fixes #1180
1 parent 466483f commit 68ccf6c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/server/mcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ export class ResourceTemplate {
10881088
*/
10891089
export type ToolCallback<Args extends undefined | ZodRawShapeCompat | AnySchema = undefined> = Args extends ZodRawShapeCompat
10901090
? (args: ShapeOutput<Args>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => CallToolResult | Promise<CallToolResult>
1091-
: Args extends AnySchema
1091+
: [Args] extends [AnySchema]
10921092
? (
10931093
args: SchemaOutput<Args>,
10941094
extra: RequestHandlerExtra<ServerRequest, ServerNotification>

0 commit comments

Comments
 (0)