@@ -942,7 +942,10 @@ export class McpServer {
942942 * );
943943 * ```
944944 */
945- registerTool < OutputArgs extends StandardSchemaWithJSON , InputArgs extends StandardSchemaWithJSON | undefined = undefined > (
945+ registerTool <
946+ InputArgs extends StandardSchemaWithJSON | ZodRawShape | undefined = undefined ,
947+ OutputArgs extends StandardSchemaWithJSON | ZodRawShape | undefined = undefined
948+ > (
946949 name : string ,
947950 config : {
948951 title ?: string ;
@@ -953,21 +956,7 @@ export class McpServer {
953956 icons ?: Icon [ ] ;
954957 _meta ?: Record < string , unknown > ;
955958 } ,
956- cb : ToolCallback < InputArgs >
957- ) : RegisteredTool ;
958- /** @deprecated Wrap with `z.object({...})` instead. Raw-shape form: `inputSchema`/`outputSchema` may be a plain `{ field: z.string() }` record; it is auto-wrapped with `z.object()`. */
959- registerTool < InputArgs extends ZodRawShape , OutputArgs extends ZodRawShape | StandardSchemaWithJSON | undefined = undefined > (
960- name : string ,
961- config : {
962- title ?: string ;
963- description ?: string ;
964- inputSchema ?: InputArgs ;
965- outputSchema ?: OutputArgs ;
966- annotations ?: ToolAnnotations ;
967- icons ?: Icon [ ] ;
968- _meta ?: Record < string , unknown > ;
969- } ,
970- cb : LegacyToolCallback < InputArgs >
959+ cb : ToolCallback < InputArgs , OutputArgs >
971960 ) : RegisteredTool ;
972961 registerTool (
973962 name : string ,
@@ -980,7 +969,9 @@ export class McpServer {
980969 icons ?: Icon [ ] ;
981970 _meta ?: Record < string , unknown > ;
982971 } ,
983- cb : ToolCallback < StandardSchemaWithJSON | undefined > | LegacyToolCallback < ZodRawShape >
972+ cb :
973+ | ToolCallback < StandardSchemaWithJSON | undefined , StandardSchemaWithJSON | undefined >
974+ | LegacyToolCallback < ZodRawShape , StandardSchemaWithJSON | ZodRawShape | undefined >
984975 ) : RegisteredTool {
985976 if ( this . _registeredTools [ name ] ) {
986977 throw new Error ( `Tool ${ name } is already registered` ) ;
@@ -1211,12 +1202,10 @@ export type ZodRawShape = Record<string, z.ZodType>;
12111202export type InferRawShape < S extends ZodRawShape > = z . infer < z . ZodObject < S > > ;
12121203
12131204/** {@linkcode ToolCallback } variant used when `inputSchema` is a {@linkcode ZodRawShape}. */
1214- export type LegacyToolCallback < Args extends ZodRawShape | undefined > = Args extends ZodRawShape
1215- ? (
1216- args : InferRawShape < Args > ,
1217- ctx : ServerContext
1218- ) => CallToolResult | InputRequiredResult | Promise < CallToolResult | InputRequiredResult >
1219- : ( ctx : ServerContext ) => CallToolResult | InputRequiredResult | Promise < CallToolResult | InputRequiredResult > ;
1205+ export type LegacyToolCallback <
1206+ Args extends ZodRawShape | undefined ,
1207+ OutputArgs extends StandardSchemaWithJSON | ZodRawShape | undefined = undefined
1208+ > = ToolCallback < Args , OutputArgs > ;
12201209
12211210/** {@linkcode PromptCallback } variant used when `argsSchema` is a {@linkcode ZodRawShape}. */
12221211export type LegacyPromptCallback < Args extends ZodRawShape | undefined > = Args extends ZodRawShape
@@ -1229,16 +1218,30 @@ export type LegacyPromptCallback<Args extends ZodRawShape | undefined> = Args ex
12291218export type BaseToolCallback <
12301219 SendResultT extends Result ,
12311220 Ctx extends ServerContext ,
1232- Args extends StandardSchemaWithJSON | undefined
1221+ Args extends StandardSchemaWithJSON | ZodRawShape | undefined
12331222> = Args extends StandardSchemaWithJSON
12341223 ? ( args : StandardSchemaWithJSON . InferOutput < Args > , ctx : Ctx ) => SendResultT | Promise < SendResultT >
1235- : ( ctx : Ctx ) => SendResultT | Promise < SendResultT > ;
1224+ : Args extends ZodRawShape
1225+ ? ( args : InferRawShape < Args > , ctx : Ctx ) => SendResultT | Promise < SendResultT >
1226+ : ( ctx : Ctx ) => SendResultT | Promise < SendResultT > ;
12361227
12371228/**
12381229 * Callback for a tool handler registered with {@linkcode McpServer.registerTool}.
12391230 */
1240- export type ToolCallback < Args extends StandardSchemaWithJSON | undefined = undefined > = BaseToolCallback <
1241- CallToolResult | InputRequiredResult ,
1231+ export type ToolCallback <
1232+ Args extends StandardSchemaWithJSON | ZodRawShape | undefined = undefined ,
1233+ OutputArgs extends StandardSchemaWithJSON | ZodRawShape | undefined = undefined
1234+ > = BaseToolCallback <
1235+ | ( OutputArgs extends StandardSchemaWithJSON
1236+ ? Omit < CallToolResult , 'structuredContent' > & {
1237+ structuredContent ?: StandardSchemaWithJSON . InferOutput < OutputArgs > ;
1238+ }
1239+ : OutputArgs extends ZodRawShape
1240+ ? Omit < CallToolResult , 'structuredContent' > & {
1241+ structuredContent ?: InferRawShape < OutputArgs > ;
1242+ }
1243+ : CallToolResult )
1244+ | InputRequiredResult ,
12421245 ServerContext ,
12431246 Args
12441247> ;
0 commit comments