@@ -255,23 +255,23 @@ export class Client extends Protocol<ClientContext> {
255255 * Handlers are silently skipped if the server doesn't advertise the corresponding listChanged capability.
256256 * @internal
257257 */
258- private _setupListChangedHandlers ( config : ListChangedHandlers ) : void {
258+ private async _setupListChangedHandlers ( config : ListChangedHandlers ) : Promise < void > {
259259 if ( config . tools && this . _serverCapabilities ?. tools ?. listChanged ) {
260- this . _setupListChangedHandler ( 'tools' , 'notifications/tools/list_changed' , config . tools , async ( ) => {
260+ await this . _setupListChangedHandler ( 'tools' , 'notifications/tools/list_changed' , config . tools , async ( ) => {
261261 const result = await this . listTools ( ) ;
262262 return result . tools ;
263263 } ) ;
264264 }
265265
266266 if ( config . prompts && this . _serverCapabilities ?. prompts ?. listChanged ) {
267- this . _setupListChangedHandler ( 'prompts' , 'notifications/prompts/list_changed' , config . prompts , async ( ) => {
267+ await this . _setupListChangedHandler ( 'prompts' , 'notifications/prompts/list_changed' , config . prompts , async ( ) => {
268268 const result = await this . listPrompts ( ) ;
269269 return result . prompts ;
270270 } ) ;
271271 }
272272
273273 if ( config . resources && this . _serverCapabilities ?. resources ?. listChanged ) {
274- this . _setupListChangedHandler ( 'resources' , 'notifications/resources/list_changed' , config . resources , async ( ) => {
274+ await this . _setupListChangedHandler ( 'resources' , 'notifications/resources/list_changed' , config . resources , async ( ) => {
275275 const result = await this . listResources ( ) ;
276276 return result . resources ;
277277 } ) ;
@@ -339,7 +339,7 @@ export class Client extends Protocol<ClientContext> {
339339 ) : void {
340340 if ( method === 'elicitation/create' ) {
341341 const wrappedHandler = async ( request : RequestTypeMap [ M ] , ctx : ClientContext ) : Promise < ClientResult > => {
342- const validatedRequest = parseSchema ( ElicitRequestSchema , request ) ;
342+ const validatedRequest = await parseSchema ( ElicitRequestSchema , request ) ;
343343 if ( ! validatedRequest . success ) {
344344 // Type guard: if success is false, error is guaranteed to exist
345345 const errorMessage =
@@ -363,7 +363,7 @@ export class Client extends Protocol<ClientContext> {
363363
364364 // When task creation is requested, validate and return CreateTaskResult
365365 if ( params . task ) {
366- const taskValidationResult = parseSchema ( CreateTaskResultSchema , result ) ;
366+ const taskValidationResult = await parseSchema ( CreateTaskResultSchema , result ) ;
367367 if ( ! taskValidationResult . success ) {
368368 const errorMessage =
369369 taskValidationResult . error instanceof Error
@@ -375,7 +375,7 @@ export class Client extends Protocol<ClientContext> {
375375 }
376376
377377 // For non-task requests, validate against ElicitResultSchema
378- const validationResult = parseSchema ( ElicitResultSchema , result ) ;
378+ const validationResult = await parseSchema ( ElicitResultSchema , result ) ;
379379 if ( ! validationResult . success ) {
380380 // Type guard: if success is false, error is guaranteed to exist
381381 const errorMessage =
@@ -409,7 +409,7 @@ export class Client extends Protocol<ClientContext> {
409409
410410 if ( method === 'sampling/createMessage' ) {
411411 const wrappedHandler = async ( request : RequestTypeMap [ M ] , ctx : ClientContext ) : Promise < ClientResult > => {
412- const validatedRequest = parseSchema ( CreateMessageRequestSchema , request ) ;
412+ const validatedRequest = await parseSchema ( CreateMessageRequestSchema , request ) ;
413413 if ( ! validatedRequest . success ) {
414414 const errorMessage =
415415 validatedRequest . error instanceof Error ? validatedRequest . error . message : String ( validatedRequest . error ) ;
@@ -422,7 +422,7 @@ export class Client extends Protocol<ClientContext> {
422422
423423 // When task creation is requested, validate and return CreateTaskResult
424424 if ( params . task ) {
425- const taskValidationResult = parseSchema ( CreateTaskResultSchema , result ) ;
425+ const taskValidationResult = await parseSchema ( CreateTaskResultSchema , result ) ;
426426 if ( ! taskValidationResult . success ) {
427427 const errorMessage =
428428 taskValidationResult . error instanceof Error
@@ -436,7 +436,7 @@ export class Client extends Protocol<ClientContext> {
436436 // For non-task requests, validate against appropriate schema based on tools presence
437437 const hasTools = params . tools || params . toolChoice ;
438438 const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema ;
439- const validationResult = parseSchema ( resultSchema , result ) ;
439+ const validationResult = await parseSchema ( resultSchema , result ) ;
440440 if ( ! validationResult . success ) {
441441 const errorMessage =
442442 validationResult . error instanceof Error ? validationResult . error . message : String ( validationResult . error ) ;
@@ -538,7 +538,7 @@ export class Client extends Protocol<ClientContext> {
538538
539539 // Set up list changed handlers now that we know server capabilities
540540 if ( this . _pendingListChangedConfig ) {
541- this . _setupListChangedHandlers ( this . _pendingListChangedConfig ) ;
541+ await this . _setupListChangedHandlers ( this . _pendingListChangedConfig ) ;
542542 this . _pendingListChangedConfig = undefined ;
543543 }
544544 } catch ( error ) {
@@ -1005,14 +1005,14 @@ export class Client extends Protocol<ClientContext> {
10051005 * Set up a single list changed handler.
10061006 * @internal
10071007 */
1008- private _setupListChangedHandler < T > (
1008+ private async _setupListChangedHandler < T > (
10091009 listType : string ,
10101010 notificationMethod : NotificationMethod ,
10111011 options : ListChangedOptions < T > ,
10121012 fetcher : ( ) => Promise < T [ ] >
1013- ) : void {
1014- // Validate options using Zod schema (validates autoRefresh and debounceMs)
1015- const parseResult = parseSchema ( ListChangedOptionsBaseSchema , options ) ;
1013+ ) : Promise < void > {
1014+ // Validate options ( autoRefresh and debounceMs)
1015+ const parseResult = await parseSchema ( ListChangedOptionsBaseSchema , options ) ;
10161016 if ( ! parseResult . success ) {
10171017 throw new Error ( `Invalid ${ listType } listChanged options: ${ parseResult . error . message } ` ) ;
10181018 }
0 commit comments