From 3c9496812eddf5511db977a023cbb118d0fb5770 Mon Sep 17 00:00:00 2001 From: Basil Hosmer Date: Fri, 9 May 2025 17:43:00 -0400 Subject: [PATCH] tweak heuristic type test for isZodRawShape - simpler test for empty object - only test public zod properties (parse, safeParse) Confirmed that vendored-library tests still pass. Note that you need the --testPathIgnorePatterns to avoid the __tests__ directory (this is what was breaking the build): $ npm test -- --testPathIgnorePatterns="vendor" --- src/server/mcp.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/server/mcp.ts b/src/server/mcp.ts index 52c90d9d..97459fb1 100644 --- a/src/server/mcp.ts +++ b/src/server/mcp.ts @@ -925,19 +925,18 @@ const EMPTY_OBJECT_JSON_SCHEMA = { function isZodRawShape(obj: unknown): obj is ZodRawShape { if (typeof obj !== "object" || obj === null) return false; - const isEmptyObject = z.object({}).strict().safeParse(obj).success; + const isEmptyObject = Object.keys(obj).length === 0; // Check if object is empty or at least one property is a ZodType instance - return isEmptyObject || Object.values(obj as object).some(isZodType); + // Note: use heuristic check to avoid instanceof failure across different Zod versions + return isEmptyObject || Object.values(obj as object).some(isZodTypeLike); } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function isZodType(value: any): value is ZodType { +function isZodTypeLike(value: unknown): value is ZodType { return value !== null && typeof value === 'object' && - typeof value.parse === 'function' && - typeof value.safeParse === 'function' && - typeof value._def === 'object'; + 'parse' in value && typeof value.parse === 'function' && + 'safeParse' in value && typeof value.safeParse === 'function'; } /**