@@ -950,6 +950,13 @@ export class McpServer {
950950 cb : ToolCallback < Args >
951951 ) : RegisteredTool ;
952952
953+ /**
954+ * Registers a tool with a ZodObject schema (e.g., z.object({ ... })).
955+ * The schema's shape will be extracted and used for validation.
956+ * @deprecated Use `registerTool` instead.
957+ */
958+ tool < Schema extends AnyObjectSchema > ( name : string , paramsSchema : Schema , cb : ToolCallback < Schema > ) : RegisteredTool ;
959+
953960 /**
954961 * Registers a tool `name` (with a description) taking either parameter schema or annotations.
955962 * This unified overload handles both `tool(name, description, paramsSchema, cb)` and
@@ -966,6 +973,13 @@ export class McpServer {
966973 cb : ToolCallback < Args >
967974 ) : RegisteredTool ;
968975
976+ /**
977+ * Registers a tool with a description and ZodObject schema (e.g., z.object({ ... })).
978+ * The schema's shape will be extracted and used for validation.
979+ * @deprecated Use `registerTool` instead.
980+ */
981+ tool < Schema extends AnyObjectSchema > ( name : string , description : string , paramsSchema : Schema , cb : ToolCallback < Schema > ) : RegisteredTool ;
982+
969983 /**
970984 * Registers a tool with both parameter schema and annotations.
971985 * @deprecated Use `registerTool` instead.
@@ -977,6 +991,18 @@ export class McpServer {
977991 cb : ToolCallback < Args >
978992 ) : RegisteredTool ;
979993
994+ /**
995+ * Registers a tool with a ZodObject schema and annotations.
996+ * The schema's shape will be extracted and used for validation.
997+ * @deprecated Use `registerTool` instead.
998+ */
999+ tool < Schema extends AnyObjectSchema > (
1000+ name : string ,
1001+ paramsSchema : Schema ,
1002+ annotations : ToolAnnotations ,
1003+ cb : ToolCallback < Schema >
1004+ ) : RegisteredTool ;
1005+
9801006 /**
9811007 * Registers a tool with description, parameter schema, and annotations.
9821008 * @deprecated Use `registerTool` instead.
@@ -989,6 +1015,19 @@ export class McpServer {
9891015 cb : ToolCallback < Args >
9901016 ) : RegisteredTool ;
9911017
1018+ /**
1019+ * Registers a tool with description, ZodObject schema, and annotations.
1020+ * The schema's shape will be extracted and used for validation.
1021+ * @deprecated Use `registerTool` instead.
1022+ */
1023+ tool < Schema extends AnyObjectSchema > (
1024+ name : string ,
1025+ description : string ,
1026+ paramsSchema : Schema ,
1027+ annotations : ToolAnnotations ,
1028+ cb : ToolCallback < Schema >
1029+ ) : RegisteredTool ;
1030+
9921031 /**
9931032 * tool() implementation. Parses arguments passed to overrides defined above.
9941033 */
@@ -1025,8 +1064,31 @@ export class McpServer {
10251064 // Or: tool(name, description, paramsSchema, annotations, cb)
10261065 annotations = rest . shift ( ) as ToolAnnotations ;
10271066 }
1067+ } else if ( typeof firstArg === 'object' && firstArg !== null && isZodSchemaInstance ( firstArg ) ) {
1068+ // It's a Zod schema instance (like z.object()), extract its shape if it's an object schema
1069+ const shape = getObjectShape ( firstArg as AnyObjectSchema ) ;
1070+ if ( shape ) {
1071+ // We found an object schema, use its shape
1072+ inputSchema = shape ;
1073+ rest . shift ( ) ;
1074+
1075+ // Check if the next arg is potentially annotations
1076+ if (
1077+ rest . length > 1 &&
1078+ typeof rest [ 0 ] === 'object' &&
1079+ rest [ 0 ] !== null &&
1080+ ! isZodRawShapeCompat ( rest [ 0 ] ) &&
1081+ ! isZodSchemaInstance ( rest [ 0 ] )
1082+ ) {
1083+ annotations = rest . shift ( ) as ToolAnnotations ;
1084+ }
1085+ } else {
1086+ // It's a schema but not an object schema, treat as annotations
1087+ // (This maintains backward compatibility for edge cases)
1088+ annotations = rest . shift ( ) as ToolAnnotations ;
1089+ }
10281090 } else if ( typeof firstArg === 'object' && firstArg !== null ) {
1029- // Not a ZodRawShapeCompat, so must be annotations in this position
1091+ // Not a ZodRawShapeCompat or Zod schema , so must be annotations in this position
10301092 // Case: tool(name, annotations, cb)
10311093 // Or: tool(name, description, annotations, cb)
10321094 annotations = rest . shift ( ) as ToolAnnotations ;
0 commit comments