@@ -190,7 +190,8 @@ public class McpAsyncClient {
190190 // Sampling Handler
191191 if (this .clientCapabilities .sampling () != null ) {
192192 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" );
194195 }
195196 this .samplingHandler = features .samplingHandler ();
196197 requestHandlers .put (McpSchema .METHOD_SAMPLING_CREATE_MESSAGE , samplingCreateMessageHandler ());
@@ -199,7 +200,8 @@ public class McpAsyncClient {
199200 // Elicitation Handler
200201 if (this .clientCapabilities .elicitation () != null ) {
201202 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" );
203205 }
204206 this .elicitationHandler = features .elicitationHandler ();
205207 requestHandlers .put (McpSchema .METHOD_ELICITATION_CREATE , elicitationCreateHandler ());
@@ -413,15 +415,15 @@ public Mono<Object> ping() {
413415 public Mono <Void > addRoot (Root root ) {
414416
415417 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" ));
417419 }
418420
419421 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" ));
421423 }
422424
423425 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" ));
425427 }
426428
427429 this .roots .put (root .uri (), root );
@@ -447,11 +449,11 @@ public Mono<Void> addRoot(Root root) {
447449 public Mono <Void > removeRoot (String rootUri ) {
448450
449451 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" ));
451453 }
452454
453455 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" ));
455457 }
456458
457459 Root removed = this .roots .remove (rootUri );
@@ -469,7 +471,7 @@ public Mono<Void> removeRoot(String rootUri) {
469471 }
470472 return Mono .empty ();
471473 }
472- return Mono .error (new McpError ("Root with uri '" + rootUri + "' not found" ));
474+ return Mono .error (new IllegalStateException ("Root with uri '" + rootUri + "' not found" ));
473475 }
474476
475477 /**
@@ -540,7 +542,7 @@ private RequestHandler<ElicitResult> elicitationCreateHandler() {
540542 public Mono <McpSchema .CallToolResult > callTool (McpSchema .CallToolRequest callToolRequest ) {
541543 return this .initializer .withIntitialization ("calling tools" , init -> {
542544 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" ));
544546 }
545547 return init .mcpSession ()
546548 .sendRequest (McpSchema .METHOD_TOOLS_CALL , callToolRequest , CALL_TOOL_RESULT_TYPE_REF );
@@ -569,7 +571,7 @@ public Mono<McpSchema.ListToolsResult> listTools() {
569571 public Mono <McpSchema .ListToolsResult > listTools (String cursor ) {
570572 return this .initializer .withIntitialization ("listing tools" , init -> {
571573 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" ));
573575 }
574576 return init .mcpSession ()
575577 .sendRequest (McpSchema .METHOD_TOOLS_LIST , new McpSchema .PaginatedRequest (cursor ),
@@ -633,7 +635,7 @@ public Mono<McpSchema.ListResourcesResult> listResources() {
633635 public Mono <McpSchema .ListResourcesResult > listResources (String cursor ) {
634636 return this .initializer .withIntitialization ("listing resources" , init -> {
635637 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" ));
637639 }
638640 return init .mcpSession ()
639641 .sendRequest (McpSchema .METHOD_RESOURCES_LIST , new McpSchema .PaginatedRequest (cursor ),
@@ -665,7 +667,7 @@ public Mono<McpSchema.ReadResourceResult> readResource(McpSchema.Resource resour
665667 public Mono <McpSchema .ReadResourceResult > readResource (McpSchema .ReadResourceRequest readResourceRequest ) {
666668 return this .initializer .withIntitialization ("reading resources" , init -> {
667669 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" ));
669671 }
670672 return init .mcpSession ()
671673 .sendRequest (McpSchema .METHOD_RESOURCES_READ , readResourceRequest , READ_RESOURCE_RESULT_TYPE_REF );
@@ -703,7 +705,7 @@ public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates() {
703705 public Mono <McpSchema .ListResourceTemplatesResult > listResourceTemplates (String cursor ) {
704706 return this .initializer .withIntitialization ("listing resource templates" , init -> {
705707 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" ));
707709 }
708710 return init .mcpSession ()
709711 .sendRequest (McpSchema .METHOD_RESOURCES_TEMPLATES_LIST , new McpSchema .PaginatedRequest (cursor ),
@@ -863,7 +865,7 @@ private NotificationHandler asyncLoggingNotificationHandler(
863865 */
864866 public Mono <Void > setLoggingLevel (LoggingLevel loggingLevel ) {
865867 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" ));
867869 }
868870
869871 return this .initializer .withIntitialization ("setting logging level" , init -> {
0 commit comments