@@ -30,6 +30,7 @@ import type {
3030import {
3131 assertCompleteRequestPrompt ,
3232 assertCompleteRequestResourceTemplate ,
33+ normalizeRawShapeSchema ,
3334 promptArgumentsFromStandardSchema ,
3435 ProtocolError ,
3536 ProtocolErrorCode ,
@@ -873,6 +874,31 @@ export class McpServer {
873874 _meta ?: Record < string , unknown > ;
874875 } ,
875876 cb : ToolCallback < InputArgs >
877+ ) : RegisteredTool ;
878+ /** Raw-shape form: `inputSchema`/`outputSchema` may be a plain `{ field: z.string() }` record; it is auto-wrapped with `z.object()`. */
879+ registerTool < InputArgs extends ZodRawShape , OutputArgs extends ZodRawShape | StandardSchemaWithJSON | undefined = undefined > (
880+ name : string ,
881+ config : {
882+ title ?: string ;
883+ description ?: string ;
884+ inputSchema ?: InputArgs ;
885+ outputSchema ?: OutputArgs ;
886+ annotations ?: ToolAnnotations ;
887+ _meta ?: Record < string , unknown > ;
888+ } ,
889+ cb : LegacyToolCallback < InputArgs >
890+ ) : RegisteredTool ;
891+ registerTool (
892+ name : string ,
893+ config : {
894+ title ?: string ;
895+ description ?: string ;
896+ inputSchema ?: StandardSchemaWithJSON | ZodRawShape ;
897+ outputSchema ?: StandardSchemaWithJSON | ZodRawShape ;
898+ annotations ?: ToolAnnotations ;
899+ _meta ?: Record < string , unknown > ;
900+ } ,
901+ cb : ToolCallback < StandardSchemaWithJSON | undefined > | LegacyToolCallback < ZodRawShape >
876902 ) : RegisteredTool {
877903 if ( this . _registeredTools [ name ] ) {
878904 throw new Error ( `Tool ${ name } is already registered` ) ;
@@ -884,8 +910,8 @@ export class McpServer {
884910 name ,
885911 title ,
886912 description ,
887- inputSchema ,
888- outputSchema ,
913+ normalizeRawShapeSchema ( inputSchema ) ,
914+ normalizeRawShapeSchema ( outputSchema ) ,
889915 annotations ,
890916 { taskSupport : 'forbidden' } ,
891917 _meta ,
@@ -928,6 +954,27 @@ export class McpServer {
928954 _meta ?: Record < string , unknown > ;
929955 } ,
930956 cb : PromptCallback < Args >
957+ ) : RegisteredPrompt ;
958+ /** Raw-shape form: `argsSchema` may be a plain `{ field: z.string() }` record; it is auto-wrapped with `z.object()`. */
959+ registerPrompt < Args extends ZodRawShape > (
960+ name : string ,
961+ config : {
962+ title ?: string ;
963+ description ?: string ;
964+ argsSchema ?: Args ;
965+ _meta ?: Record < string , unknown > ;
966+ } ,
967+ cb : LegacyPromptCallback < Args >
968+ ) : RegisteredPrompt ;
969+ registerPrompt (
970+ name : string ,
971+ config : {
972+ title ?: string ;
973+ description ?: string ;
974+ argsSchema ?: StandardSchemaWithJSON | ZodRawShape ;
975+ _meta ?: Record < string , unknown > ;
976+ } ,
977+ cb : PromptCallback < StandardSchemaWithJSON > | LegacyPromptCallback < ZodRawShape >
931978 ) : RegisteredPrompt {
932979 if ( this . _registeredPrompts [ name ] ) {
933980 throw new Error ( `Prompt ${ name } is already registered` ) ;
@@ -939,7 +986,7 @@ export class McpServer {
939986 name ,
940987 title ,
941988 description ,
942- argsSchema ,
989+ normalizeRawShapeSchema ( argsSchema ) ,
943990 cb as PromptCallback < StandardSchemaWithJSON | undefined > ,
944991 _meta
945992 ) ;
@@ -1062,6 +1109,25 @@ export class ResourceTemplate {
10621109 }
10631110}
10641111
1112+ /**
1113+ * A plain record of field schemas, e.g. `{ name: z.string() }`. Accepted by
1114+ * `registerTool`/`registerPrompt` as a shorthand; auto-wrapped with `z.object()`.
1115+ */
1116+ export type ZodRawShape = Record < string , StandardSchemaWithJSON > ;
1117+
1118+ /** Infers the parsed-output type of a {@linkcode ZodRawShape}. */
1119+ export type InferRawShape < S extends ZodRawShape > = { [ K in keyof S ] : StandardSchemaWithJSON . InferOutput < S [ K ] > } ;
1120+
1121+ /** {@linkcode ToolCallback } variant used when `inputSchema` is a {@linkcode ZodRawShape}. */
1122+ export type LegacyToolCallback < Args extends ZodRawShape | undefined > = Args extends ZodRawShape
1123+ ? ( args : InferRawShape < Args > , ctx : ServerContext ) => CallToolResult | Promise < CallToolResult >
1124+ : ( ctx : ServerContext ) => CallToolResult | Promise < CallToolResult > ;
1125+
1126+ /** {@linkcode PromptCallback } variant used when `argsSchema` is a {@linkcode ZodRawShape}. */
1127+ export type LegacyPromptCallback < Args extends ZodRawShape | undefined > = Args extends ZodRawShape
1128+ ? ( args : InferRawShape < Args > , ctx : ServerContext ) => GetPromptResult | Promise < GetPromptResult >
1129+ : ( ctx : ServerContext ) => GetPromptResult | Promise < GetPromptResult > ;
1130+
10651131export type BaseToolCallback <
10661132 SendResultT extends Result ,
10671133 Ctx extends ServerContext ,
0 commit comments