@@ -659,16 +659,6 @@ export class McpServer {
659
659
if ( this . _registeredTools [ name ] ) {
660
660
throw new Error ( `Tool ${ name } is already registered` ) ;
661
661
}
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
- } ;
672
662
673
663
let description : string | undefined ;
674
664
if ( typeof rest [ 0 ] === "string" ) {
@@ -931,6 +921,24 @@ const EMPTY_OBJECT_JSON_SCHEMA = {
931
921
type : "object" as const ,
932
922
} ;
933
923
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
+
934
942
/**
935
943
* Additional, optional information for annotating a resource.
936
944
*/
0 commit comments