@@ -948,6 +948,17 @@ export class McpServer {
948948 cb : ToolCallback < Args >
949949 ) : RegisteredTool ;
950950
951+ /**
952+ * Registers a tool with a ZodObject schema (e.g., z.object({ ... })).
953+ * The schema's shape will be extracted and used for validation.
954+ * @deprecated Use `registerTool` instead.
955+ */
956+ tool < Schema extends AnyObjectSchema > (
957+ name : string ,
958+ paramsSchema : Schema ,
959+ cb : ToolCallback < Schema >
960+ ) : RegisteredTool ;
961+
951962 /**
952963 * Registers a tool `name` (with a description) taking either parameter schema or annotations.
953964 * This unified overload handles both `tool(name, description, paramsSchema, cb)` and
@@ -964,6 +975,18 @@ export class McpServer {
964975 cb : ToolCallback < Args >
965976 ) : RegisteredTool ;
966977
978+ /**
979+ * Registers a tool with a description and ZodObject schema (e.g., z.object({ ... })).
980+ * The schema's shape will be extracted and used for validation.
981+ * @deprecated Use `registerTool` instead.
982+ */
983+ tool < Schema extends AnyObjectSchema > (
984+ name : string ,
985+ description : string ,
986+ paramsSchema : Schema ,
987+ cb : ToolCallback < Schema >
988+ ) : RegisteredTool ;
989+
967990 /**
968991 * Registers a tool with both parameter schema and annotations.
969992 * @deprecated Use `registerTool` instead.
@@ -975,6 +998,18 @@ export class McpServer {
975998 cb : ToolCallback < Args >
976999 ) : RegisteredTool ;
9771000
1001+ /**
1002+ * Registers a tool with a ZodObject schema and annotations.
1003+ * The schema's shape will be extracted and used for validation.
1004+ * @deprecated Use `registerTool` instead.
1005+ */
1006+ tool < Schema extends AnyObjectSchema > (
1007+ name : string ,
1008+ paramsSchema : Schema ,
1009+ annotations : ToolAnnotations ,
1010+ cb : ToolCallback < Schema >
1011+ ) : RegisteredTool ;
1012+
9781013 /**
9791014 * Registers a tool with description, parameter schema, and annotations.
9801015 * @deprecated Use `registerTool` instead.
@@ -987,6 +1022,19 @@ export class McpServer {
9871022 cb : ToolCallback < Args >
9881023 ) : RegisteredTool ;
9891024
1025+ /**
1026+ * Registers a tool with description, ZodObject schema, and annotations.
1027+ * The schema's shape will be extracted and used for validation.
1028+ * @deprecated Use `registerTool` instead.
1029+ */
1030+ tool < Schema extends AnyObjectSchema > (
1031+ name : string ,
1032+ description : string ,
1033+ paramsSchema : Schema ,
1034+ annotations : ToolAnnotations ,
1035+ cb : ToolCallback < Schema >
1036+ ) : RegisteredTool ;
1037+
9901038 /**
9911039 * tool() implementation. Parses arguments passed to overrides defined above.
9921040 */
@@ -1023,8 +1071,25 @@ export class McpServer {
10231071 // Or: tool(name, description, paramsSchema, annotations, cb)
10241072 annotations = rest . shift ( ) as ToolAnnotations ;
10251073 }
1074+ } else if ( typeof firstArg === 'object' && firstArg !== null && isZodSchemaInstance ( firstArg ) ) {
1075+ // It's a Zod schema instance (like z.object()), extract its shape if it's an object schema
1076+ const shape = getObjectShape ( firstArg as AnyObjectSchema ) ;
1077+ if ( shape ) {
1078+ // We found an object schema, use its shape
1079+ inputSchema = shape ;
1080+ rest . shift ( ) ;
1081+
1082+ // Check if the next arg is potentially annotations
1083+ if ( rest . length > 1 && typeof rest [ 0 ] === 'object' && rest [ 0 ] !== null && ! isZodRawShapeCompat ( rest [ 0 ] ) && ! isZodSchemaInstance ( rest [ 0 ] ) ) {
1084+ annotations = rest . shift ( ) as ToolAnnotations ;
1085+ }
1086+ } else {
1087+ // It's a schema but not an object schema, treat as annotations
1088+ // (This maintains backward compatibility for edge cases)
1089+ annotations = rest . shift ( ) as ToolAnnotations ;
1090+ }
10261091 } else if ( typeof firstArg === 'object' && firstArg !== null ) {
1027- // Not a ZodRawShapeCompat, so must be annotations in this position
1092+ // Not a ZodRawShapeCompat or Zod schema , so must be annotations in this position
10281093 // Case: tool(name, annotations, cb)
10291094 // Or: tool(name, description, annotations, cb)
10301095 annotations = rest . shift ( ) as ToolAnnotations ;
0 commit comments