From 192d981d693b0ebb7899b558a1109ee7e29b2eac Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Thu, 27 Nov 2025 11:47:06 +0000 Subject: [PATCH] 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 --- src/server/mcp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/mcp.ts b/src/server/mcp.ts index b9b6d5596..b91d488dd 100644 --- a/src/server/mcp.ts +++ b/src/server/mcp.ts @@ -1088,7 +1088,7 @@ export class ResourceTemplate { */ export type ToolCallback = Args extends ZodRawShapeCompat ? (args: ShapeOutput, extra: RequestHandlerExtra) => CallToolResult | Promise - : Args extends AnySchema + : [Args] extends [AnySchema] ? ( args: SchemaOutput, extra: RequestHandlerExtra