Skip to content

Commit 3c94968

Browse files
committed
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"
1 parent b6617dc commit 3c94968

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/server/mcp.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -925,19 +925,18 @@ const EMPTY_OBJECT_JSON_SCHEMA = {
925925
function isZodRawShape(obj: unknown): obj is ZodRawShape {
926926
if (typeof obj !== "object" || obj === null) return false;
927927

928-
const isEmptyObject = z.object({}).strict().safeParse(obj).success;
928+
const isEmptyObject = Object.keys(obj).length === 0;
929929

930930
// Check if object is empty or at least one property is a ZodType instance
931-
return isEmptyObject || Object.values(obj as object).some(isZodType);
931+
// Note: use heuristic check to avoid instanceof failure across different Zod versions
932+
return isEmptyObject || Object.values(obj as object).some(isZodTypeLike);
932933
}
933934

934-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
935-
function isZodType(value: any): value is ZodType {
935+
function isZodTypeLike(value: unknown): value is ZodType {
936936
return value !== null &&
937937
typeof value === 'object' &&
938-
typeof value.parse === 'function' &&
939-
typeof value.safeParse === 'function' &&
940-
typeof value._def === 'object';
938+
'parse' in value && typeof value.parse === 'function' &&
939+
'safeParse' in value && typeof value.safeParse === 'function';
941940
}
942941

943942
/**

0 commit comments

Comments
 (0)