@@ -1024,9 +1024,10 @@ export class McpServer {
10241024 annotations = rest . shift ( ) as ToolAnnotations ;
10251025 }
10261026 } else if ( typeof firstArg === 'object' && firstArg !== null ) {
1027- // Not a ZodRawShapeCompat, so must be annotations in this position
1028- // Case: tool(name, annotations, cb)
1029- // Or: tool(name, description, annotations, cb)
1027+ // ToolAnnotations values are primitives. Nested objects indicate a misplaced schema
1028+ if ( Object . values ( firstArg ) . some ( v => typeof v === 'object' && v !== null ) ) {
1029+ throw new Error ( `Tool ${ name } expected a Zod schema or ToolAnnotations, but received an unrecognized object` ) ;
1030+ }
10301031 annotations = rest . shift ( ) as ToolAnnotations ;
10311032 }
10321033 }
@@ -1386,7 +1387,7 @@ function isZodRawShapeCompat(obj: unknown): obj is ZodRawShapeCompat {
13861387
13871388/**
13881389 * Converts a provided Zod schema to a Zod object if it is a ZodRawShapeCompat,
1389- * otherwise returns the schema as is.
1390+ * otherwise returns the schema as is. Throws if the value is not a valid Zod schema.
13901391 */
13911392function getZodSchemaObject ( schema : ZodRawShapeCompat | AnySchema | undefined ) : AnySchema | undefined {
13921393 if ( ! schema ) {
@@ -1397,6 +1398,10 @@ function getZodSchemaObject(schema: ZodRawShapeCompat | AnySchema | undefined):
13971398 return objectFromShape ( schema ) ;
13981399 }
13991400
1401+ if ( ! isZodSchemaInstance ( schema as object ) ) {
1402+ throw new Error ( 'inputSchema must be a Zod schema or raw shape, received an unrecognized object' ) ;
1403+ }
1404+
14001405 return schema ;
14011406}
14021407
0 commit comments