@@ -7,9 +7,12 @@ import {
77 ShapeOutput ,
88 normalizeObjectSchema ,
99 safeParseAsync ,
10- isZ4Schema ,
1110 getObjectShape ,
12- objectFromShape
11+ objectFromShape ,
12+ getParseErrorMessage ,
13+ getSchemaDescription ,
14+ isSchemaOptional ,
15+ getLiteralValue
1316} from './zod-compat.js' ;
1417import { toJsonSchemaCompat } from './zod-json-schema-compat.js' ;
1518import {
@@ -169,7 +172,7 @@ export class McpServer {
169172 if ( ! parseResult . success ) {
170173 throw new McpError (
171174 ErrorCode . InvalidParams ,
172- `Input validation error: Invalid arguments for tool ${ request . params . name } : ${ ( parseResult as any ) . error . message } `
175+ `Input validation error: Invalid arguments for tool ${ request . params . name } : ${ getParseErrorMessage ( parseResult . error ) } `
173176 ) ;
174177 }
175178
@@ -195,7 +198,7 @@ export class McpServer {
195198 if ( ! parseResult . success ) {
196199 throw new McpError (
197200 ErrorCode . InvalidParams ,
198- `Output validation error: Invalid structured content for tool ${ request . params . name } : ${ ( parseResult as any ) . error . message } `
201+ `Output validation error: Invalid structured content for tool ${ request . params . name } : ${ getParseErrorMessage ( parseResult . error ) } `
199202 ) ;
200203 }
201204 }
@@ -441,7 +444,7 @@ export class McpServer {
441444 if ( ! parseResult . success ) {
442445 throw new McpError (
443446 ErrorCode . InvalidParams ,
444- `Invalid arguments for prompt ${ request . params . name } : ${ ( parseResult as any ) . error . message } `
447+ `Invalid arguments for prompt ${ request . params . name } : ${ getParseErrorMessage ( parseResult . error ) } `
445448 ) ;
446449 }
447450
@@ -1079,10 +1082,7 @@ export class ResourceTemplate {
10791082 * - Both fields are optional but typically one should be provided
10801083 */
10811084export type ToolCallback < Args extends undefined | ZodRawShapeCompat | AnySchema = undefined > = Args extends ZodRawShapeCompat
1082- ? (
1083- args : ShapeOutput < Args > ,
1084- extra : RequestHandlerExtra < ServerRequest , ServerNotification >
1085- ) => CallToolResult | Promise < CallToolResult >
1085+ ? ( args : ShapeOutput < Args > , extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => CallToolResult | Promise < CallToolResult >
10861086 : Args extends AnySchema
10871087 ? (
10881088 args : SchemaOutput < Args > ,
@@ -1228,10 +1228,7 @@ export type RegisteredResourceTemplate = {
12281228type PromptArgsRawShape = ZodRawShapeCompat ;
12291229
12301230export type PromptCallback < Args extends undefined | PromptArgsRawShape = undefined > = Args extends PromptArgsRawShape
1231- ? (
1232- args : ShapeOutput < Args > ,
1233- extra : RequestHandlerExtra < ServerRequest , ServerNotification >
1234- ) => GetPromptResult | Promise < GetPromptResult >
1231+ ? ( args : ShapeOutput < Args > , extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => GetPromptResult | Promise < GetPromptResult >
12351232 : ( extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => GetPromptResult | Promise < GetPromptResult > ;
12361233
12371234export type RegisteredPrompt = {
@@ -1258,9 +1255,9 @@ function promptArgumentsFromSchema(schema: AnyObjectSchema): PromptArgument[] {
12581255 if ( ! shape ) return [ ] ;
12591256 return Object . entries ( shape ) . map ( ( [ name , field ] ) : PromptArgument => {
12601257 // Get description - works for both v3 and v4
1261- const description = ( field as any ) . description ?? ( field as any ) . _def ?. description ;
1258+ const description = getSchemaDescription ( field ) ;
12621259 // Check if optional - works for both v3 and v4
1263- const isOptional = ( field as any ) . isOptional ?. ( ) ?? ( field as any ) . _def ?. typeName === 'ZodOptional' ;
1260+ const isOptional = isSchemaOptional ( field ) ;
12641261 return {
12651262 name,
12661263 description,
@@ -1277,21 +1274,9 @@ function getMethodValue(schema: AnyObjectSchema): string {
12771274 }
12781275
12791276 // Extract literal value - works for both v3 and v4
1280- const v4Def = isZ4Schema ( methodSchema ) ? ( methodSchema as any ) . _zod ?. def : undefined ;
1281- const legacyDef = ( methodSchema as any ) . _def ;
1282-
1283- const candidates = [
1284- v4Def ?. value ,
1285- legacyDef ?. value ,
1286- Array . isArray ( v4Def ?. values ) ? v4Def . values [ 0 ] : undefined ,
1287- Array . isArray ( legacyDef ?. values ) ? legacyDef . values [ 0 ] : undefined ,
1288- ( methodSchema as any ) . value
1289- ] ;
1290-
1291- for ( const candidate of candidates ) {
1292- if ( typeof candidate === 'string' ) {
1293- return candidate ;
1294- }
1277+ const value = getLiteralValue ( methodSchema ) ;
1278+ if ( typeof value === 'string' ) {
1279+ return value ;
12951280 }
12961281
12971282 throw new Error ( 'Schema method literal must be a string' ) ;
0 commit comments