@@ -66,7 +66,8 @@ import {
6666 ResourceListChangedNotificationSchema ,
6767 safeParse ,
6868 SUPPORTED_PROTOCOL_VERSIONS ,
69- ToolListChangedNotificationSchema
69+ ToolListChangedNotificationSchema ,
70+ UnsupportedCapabilityError
7071} from '@modelcontextprotocol/core' ;
7172
7273import { ExperimentalClientTasks } from '../experimental/tasks/client.js' ;
@@ -479,7 +480,7 @@ export class Client<
479480
480481 protected assertCapability ( capability : keyof ServerCapabilities , method : string ) : void {
481482 if ( ! this . _serverCapabilities ?. [ capability ] ) {
482- throw new Error ( `Server does not support ${ capability } (required for ${ method } )` ) ;
483+ throw new UnsupportedCapabilityError ( `Server does not support ${ capability } (required for ${ method } )` ) ;
483484 }
484485 }
485486
@@ -562,14 +563,14 @@ export class Client<
562563 switch ( method as ClientRequest [ 'method' ] ) {
563564 case 'logging/setLevel' :
564565 if ( ! this . _serverCapabilities ?. logging ) {
565- throw new Error ( `Server does not support logging (required for ${ method } )` ) ;
566+ throw new UnsupportedCapabilityError ( `Server does not support logging (required for ${ method } )` ) ;
566567 }
567568 break ;
568569
569570 case 'prompts/get' :
570571 case 'prompts/list' :
571572 if ( ! this . _serverCapabilities ?. prompts ) {
572- throw new Error ( `Server does not support prompts (required for ${ method } )` ) ;
573+ throw new UnsupportedCapabilityError ( `Server does not support prompts (required for ${ method } )` ) ;
573574 }
574575 break ;
575576
@@ -579,25 +580,25 @@ export class Client<
579580 case 'resources/subscribe' :
580581 case 'resources/unsubscribe' :
581582 if ( ! this . _serverCapabilities ?. resources ) {
582- throw new Error ( `Server does not support resources (required for ${ method } )` ) ;
583+ throw new UnsupportedCapabilityError ( `Server does not support resources (required for ${ method } )` ) ;
583584 }
584585
585586 if ( method === 'resources/subscribe' && ! this . _serverCapabilities . resources . subscribe ) {
586- throw new Error ( `Server does not support resource subscriptions (required for ${ method } )` ) ;
587+ throw new UnsupportedCapabilityError ( `Server does not support resource subscriptions (required for ${ method } )` ) ;
587588 }
588589
589590 break ;
590591
591592 case 'tools/call' :
592593 case 'tools/list' :
593594 if ( ! this . _serverCapabilities ?. tools ) {
594- throw new Error ( `Server does not support tools (required for ${ method } )` ) ;
595+ throw new UnsupportedCapabilityError ( `Server does not support tools (required for ${ method } )` ) ;
595596 }
596597 break ;
597598
598599 case 'completion/complete' :
599600 if ( ! this . _serverCapabilities ?. completions ) {
600- throw new Error ( `Server does not support completions (required for ${ method } )` ) ;
601+ throw new UnsupportedCapabilityError ( `Server does not support completions (required for ${ method } )` ) ;
601602 }
602603 break ;
603604
@@ -615,7 +616,7 @@ export class Client<
615616 switch ( method as ClientNotification [ 'method' ] ) {
616617 case 'notifications/roots/list_changed' :
617618 if ( ! this . _capabilities . roots ?. listChanged ) {
618- throw new Error ( `Client does not support roots list changed notifications (required for ${ method } )` ) ;
619+ throw new UnsupportedCapabilityError ( `Client does not support roots list changed notifications (required for ${ method } )` ) ;
619620 }
620621 break ;
621622
@@ -643,19 +644,19 @@ export class Client<
643644 switch ( method ) {
644645 case 'sampling/createMessage' :
645646 if ( ! this . _capabilities . sampling ) {
646- throw new Error ( `Client does not support sampling capability (required for ${ method } )` ) ;
647+ throw new UnsupportedCapabilityError ( `Client does not support sampling capability (required for ${ method } )` ) ;
647648 }
648649 break ;
649650
650651 case 'elicitation/create' :
651652 if ( ! this . _capabilities . elicitation ) {
652- throw new Error ( `Client does not support elicitation capability (required for ${ method } )` ) ;
653+ throw new UnsupportedCapabilityError ( `Client does not support elicitation capability (required for ${ method } )` ) ;
653654 }
654655 break ;
655656
656657 case 'roots/list' :
657658 if ( ! this . _capabilities . roots ) {
658- throw new Error ( `Client does not support roots capability (required for ${ method } )` ) ;
659+ throw new UnsupportedCapabilityError ( `Client does not support roots capability (required for ${ method } )` ) ;
659660 }
660661 break ;
661662
@@ -664,7 +665,7 @@ export class Client<
664665 case 'tasks/result' :
665666 case 'tasks/cancel' :
666667 if ( ! this . _capabilities . tasks ) {
667- throw new Error ( `Client does not support tasks capability (required for ${ method } )` ) ;
668+ throw new UnsupportedCapabilityError ( `Client does not support tasks capability (required for ${ method } )` ) ;
668669 }
669670 break ;
670671
0 commit comments