@@ -190,7 +190,8 @@ public class McpAsyncClient {
190
190
// Sampling Handler
191
191
if (this .clientCapabilities .sampling () != null ) {
192
192
if (features .samplingHandler () == null ) {
193
- throw new McpError ("Sampling handler must not be null when client capabilities include sampling" );
193
+ throw new IllegalArgumentException (
194
+ "Sampling handler must not be null when client capabilities include sampling" );
194
195
}
195
196
this .samplingHandler = features .samplingHandler ();
196
197
requestHandlers .put (McpSchema .METHOD_SAMPLING_CREATE_MESSAGE , samplingCreateMessageHandler ());
@@ -199,7 +200,8 @@ public class McpAsyncClient {
199
200
// Elicitation Handler
200
201
if (this .clientCapabilities .elicitation () != null ) {
201
202
if (features .elicitationHandler () == null ) {
202
- throw new McpError ("Elicitation handler must not be null when client capabilities include elicitation" );
203
+ throw new IllegalArgumentException (
204
+ "Elicitation handler must not be null when client capabilities include elicitation" );
203
205
}
204
206
this .elicitationHandler = features .elicitationHandler ();
205
207
requestHandlers .put (McpSchema .METHOD_ELICITATION_CREATE , elicitationCreateHandler ());
@@ -413,15 +415,15 @@ public Mono<Object> ping() {
413
415
public Mono <Void > addRoot (Root root ) {
414
416
415
417
if (root == null ) {
416
- return Mono .error (new McpError ("Root must not be null" ));
418
+ return Mono .error (new IllegalArgumentException ("Root must not be null" ));
417
419
}
418
420
419
421
if (this .clientCapabilities .roots () == null ) {
420
- return Mono .error (new McpError ("Client must be configured with roots capabilities" ));
422
+ return Mono .error (new IllegalStateException ("Client must be configured with roots capabilities" ));
421
423
}
422
424
423
425
if (this .roots .containsKey (root .uri ())) {
424
- return Mono .error (new McpError ("Root with uri '" + root .uri () + "' already exists" ));
426
+ return Mono .error (new IllegalStateException ("Root with uri '" + root .uri () + "' already exists" ));
425
427
}
426
428
427
429
this .roots .put (root .uri (), root );
@@ -447,11 +449,11 @@ public Mono<Void> addRoot(Root root) {
447
449
public Mono <Void > removeRoot (String rootUri ) {
448
450
449
451
if (rootUri == null ) {
450
- return Mono .error (new McpError ("Root uri must not be null" ));
452
+ return Mono .error (new IllegalArgumentException ("Root uri must not be null" ));
451
453
}
452
454
453
455
if (this .clientCapabilities .roots () == null ) {
454
- return Mono .error (new McpError ("Client must be configured with roots capabilities" ));
456
+ return Mono .error (new IllegalStateException ("Client must be configured with roots capabilities" ));
455
457
}
456
458
457
459
Root removed = this .roots .remove (rootUri );
@@ -469,7 +471,7 @@ public Mono<Void> removeRoot(String rootUri) {
469
471
}
470
472
return Mono .empty ();
471
473
}
472
- return Mono .error (new McpError ("Root with uri '" + rootUri + "' not found" ));
474
+ return Mono .error (new IllegalStateException ("Root with uri '" + rootUri + "' not found" ));
473
475
}
474
476
475
477
/**
@@ -540,7 +542,7 @@ private RequestHandler<ElicitResult> elicitationCreateHandler() {
540
542
public Mono <McpSchema .CallToolResult > callTool (McpSchema .CallToolRequest callToolRequest ) {
541
543
return this .initializer .withIntitialization ("calling tools" , init -> {
542
544
if (init .initializeResult ().capabilities ().tools () == null ) {
543
- return Mono .error (new McpError ("Server does not provide tools capability" ));
545
+ return Mono .error (new IllegalStateException ("Server does not provide tools capability" ));
544
546
}
545
547
return init .mcpSession ()
546
548
.sendRequest (McpSchema .METHOD_TOOLS_CALL , callToolRequest , CALL_TOOL_RESULT_TYPE_REF );
@@ -569,7 +571,7 @@ public Mono<McpSchema.ListToolsResult> listTools() {
569
571
public Mono <McpSchema .ListToolsResult > listTools (String cursor ) {
570
572
return this .initializer .withIntitialization ("listing tools" , init -> {
571
573
if (init .initializeResult ().capabilities ().tools () == null ) {
572
- return Mono .error (new McpError ("Server does not provide tools capability" ));
574
+ return Mono .error (new IllegalStateException ("Server does not provide tools capability" ));
573
575
}
574
576
return init .mcpSession ()
575
577
.sendRequest (McpSchema .METHOD_TOOLS_LIST , new McpSchema .PaginatedRequest (cursor ),
@@ -633,7 +635,7 @@ public Mono<McpSchema.ListResourcesResult> listResources() {
633
635
public Mono <McpSchema .ListResourcesResult > listResources (String cursor ) {
634
636
return this .initializer .withIntitialization ("listing resources" , init -> {
635
637
if (init .initializeResult ().capabilities ().resources () == null ) {
636
- return Mono .error (new McpError ("Server does not provide the resources capability" ));
638
+ return Mono .error (new IllegalStateException ("Server does not provide the resources capability" ));
637
639
}
638
640
return init .mcpSession ()
639
641
.sendRequest (McpSchema .METHOD_RESOURCES_LIST , new McpSchema .PaginatedRequest (cursor ),
@@ -665,7 +667,7 @@ public Mono<McpSchema.ReadResourceResult> readResource(McpSchema.Resource resour
665
667
public Mono <McpSchema .ReadResourceResult > readResource (McpSchema .ReadResourceRequest readResourceRequest ) {
666
668
return this .initializer .withIntitialization ("reading resources" , init -> {
667
669
if (init .initializeResult ().capabilities ().resources () == null ) {
668
- return Mono .error (new McpError ("Server does not provide the resources capability" ));
670
+ return Mono .error (new IllegalStateException ("Server does not provide the resources capability" ));
669
671
}
670
672
return init .mcpSession ()
671
673
.sendRequest (McpSchema .METHOD_RESOURCES_READ , readResourceRequest , READ_RESOURCE_RESULT_TYPE_REF );
@@ -703,7 +705,7 @@ public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates() {
703
705
public Mono <McpSchema .ListResourceTemplatesResult > listResourceTemplates (String cursor ) {
704
706
return this .initializer .withIntitialization ("listing resource templates" , init -> {
705
707
if (init .initializeResult ().capabilities ().resources () == null ) {
706
- return Mono .error (new McpError ("Server does not provide the resources capability" ));
708
+ return Mono .error (new IllegalStateException ("Server does not provide the resources capability" ));
707
709
}
708
710
return init .mcpSession ()
709
711
.sendRequest (McpSchema .METHOD_RESOURCES_TEMPLATES_LIST , new McpSchema .PaginatedRequest (cursor ),
@@ -863,7 +865,7 @@ private NotificationHandler asyncLoggingNotificationHandler(
863
865
*/
864
866
public Mono <Void > setLoggingLevel (LoggingLevel loggingLevel ) {
865
867
if (loggingLevel == null ) {
866
- return Mono .error (new McpError ("Logging level must not be null" ));
868
+ return Mono .error (new IllegalArgumentException ("Logging level must not be null" ));
867
869
}
868
870
869
871
return this .initializer .withIntitialization ("setting logging level" , init -> {
0 commit comments