@@ -659,16 +659,6 @@ export class McpServer {
659659 if ( this . _registeredTools [ name ] ) {
660660 throw new Error ( `Tool ${ name } is already registered` ) ;
661661 }
662-
663- // Helper to check if an object is a Zod schema (ZodRawShape)
664- const isZodRawShape = ( obj : unknown ) : obj is ZodRawShape => {
665- if ( typeof obj !== "object" || obj === null ) return false ;
666-
667- const isEmptyObject = z . object ( { } ) . strict ( ) . safeParse ( obj ) . success ;
668-
669- // Check if object is empty or at least one property is a ZodType instance
670- return isEmptyObject || Object . values ( obj as object ) . some ( v => v instanceof ZodType ) ;
671- } ;
672662
673663 let description : string | undefined ;
674664 if ( typeof rest [ 0 ] === "string" ) {
@@ -931,6 +921,24 @@ const EMPTY_OBJECT_JSON_SCHEMA = {
931921 type : "object" as const ,
932922} ;
933923
924+ // Helper to check if an object is a Zod schema (ZodRawShape)
925+ function isZodRawShape ( obj : unknown ) : obj is ZodRawShape {
926+ if ( typeof obj !== "object" || obj === null ) return false ;
927+
928+ const isEmptyObject = Object . keys ( obj ) . length === 0 ;
929+
930+ // Check if object is empty or at least one property is a ZodType instance
931+ // Note: use heuristic check to avoid instanceof failure across different Zod versions
932+ return isEmptyObject || Object . values ( obj as object ) . some ( isZodTypeLike ) ;
933+ }
934+
935+ function isZodTypeLike ( value : unknown ) : value is ZodType {
936+ return value !== null &&
937+ typeof value === 'object' &&
938+ 'parse' in value && typeof value . parse === 'function' &&
939+ 'safeParse' in value && typeof value . safeParse === 'function' ;
940+ }
941+
934942/**
935943 * Additional, optional information for annotating a resource.
936944 */
0 commit comments