55 * @experimental
66 */
77
8+ import { SdkError , SdkErrorCode } from '../../errors/sdkErrors.js' ;
9+
810/**
911 * Type representing the task requests capability structure.
1012 * This is derived from `ClientTasksCapability.requests` and `ServerTasksCapability.requests`.
@@ -22,7 +24,7 @@ interface TaskRequestsCapability {
2224 * @param requests - The task requests capability object
2325 * @param method - The method being checked
2426 * @param entityName - `'Server'` or `'Client'` for error messages
25- * @throws Error if the capability is not supported
27+ * @throws { @linkcode SdkError } with { @linkcode SdkErrorCode.CapabilityNotSupported} if the capability is not supported
2628 *
2729 * @experimental
2830 */
@@ -32,13 +34,16 @@ export function assertToolsCallTaskCapability(
3234 entityName : 'Server' | 'Client'
3335) : void {
3436 if ( ! requests ) {
35- throw new Error ( `${ entityName } does not support task creation (required for ${ method } )` ) ;
37+ throw new SdkError ( SdkErrorCode . CapabilityNotSupported , `${ entityName } does not support task creation (required for ${ method } )` ) ;
3638 }
3739
3840 switch ( method ) {
3941 case 'tools/call' : {
4042 if ( ! requests . tools ?. call ) {
41- throw new Error ( `${ entityName } does not support task creation for tools/call (required for ${ method } )` ) ;
43+ throw new SdkError (
44+ SdkErrorCode . CapabilityNotSupported ,
45+ `${ entityName } does not support task creation for tools/call (required for ${ method } )`
46+ ) ;
4247 }
4348 break ;
4449 }
@@ -57,7 +62,7 @@ export function assertToolsCallTaskCapability(
5762 * @param requests - The task requests capability object
5863 * @param method - The method being checked
5964 * @param entityName - `'Server'` or `'Client'` for error messages
60- * @throws Error if the capability is not supported
65+ * @throws { @linkcode SdkError } with { @linkcode SdkErrorCode.CapabilityNotSupported} if the capability is not supported
6166 *
6267 * @experimental
6368 */
@@ -67,20 +72,26 @@ export function assertClientRequestTaskCapability(
6772 entityName : 'Server' | 'Client'
6873) : void {
6974 if ( ! requests ) {
70- throw new Error ( `${ entityName } does not support task creation (required for ${ method } )` ) ;
75+ throw new SdkError ( SdkErrorCode . CapabilityNotSupported , `${ entityName } does not support task creation (required for ${ method } )` ) ;
7176 }
7277
7378 switch ( method ) {
7479 case 'sampling/createMessage' : {
7580 if ( ! requests . sampling ?. createMessage ) {
76- throw new Error ( `${ entityName } does not support task creation for sampling/createMessage (required for ${ method } )` ) ;
81+ throw new SdkError (
82+ SdkErrorCode . CapabilityNotSupported ,
83+ `${ entityName } does not support task creation for sampling/createMessage (required for ${ method } )`
84+ ) ;
7785 }
7886 break ;
7987 }
8088
8189 case 'elicitation/create' : {
8290 if ( ! requests . elicitation ?. create ) {
83- throw new Error ( `${ entityName } does not support task creation for elicitation/create (required for ${ method } )` ) ;
91+ throw new SdkError (
92+ SdkErrorCode . CapabilityNotSupported ,
93+ `${ entityName } does not support task creation for elicitation/create (required for ${ method } )`
94+ ) ;
8495 }
8596 break ;
8697 }
0 commit comments