@@ -84,8 +84,8 @@ public class McpAsyncClient {
8484 private final ConcurrentHashMap <String , Root > roots ;
8585
8686 /**
87- * MCP provides a standardized way for servers to request LLM sampling (“ completions”
88- * or “ generations” ) from language models via clients. This flow allows clients to
87+ * MCP provides a standardized way for servers to request LLM sampling (" completions"
88+ * or " generations" ) from language models via clients. This flow allows clients to
8989 * maintain control over model access, selection, and permissions while enabling
9090 * servers to leverage AI capabilities—with no server API keys necessary. Servers can
9191 * request text or image-based interactions and optionally include context from MCP
@@ -108,10 +108,13 @@ public class McpAsyncClient {
108108 * timeout.
109109 * @param transport the transport to use.
110110 * @param requestTimeout the session request-response timeout.
111- * @param rootsListProviders the list of suppliers that provide the list of roots
112- * backing the roots list request.
113- * @param rootsListChangedNotification whether the client supports roots/list_changed
114- * notification.
111+ * @param clientInfo the client implementation information.
112+ * @param clientCapabilities the client capabilities.
113+ * @param roots the roots.
114+ * @param toolsChangeConsumers the tools change consumers.
115+ * @param resourcesChangeConsumers the resources change consumers.
116+ * @param promptsChangeConsumers the prompts change consumers.
117+ * @param samplingHandler the sampling handler.
115118 */
116119 public McpAsyncClient (McpTransport transport , Duration requestTimeout , Implementation clientInfo ,
117120 ClientCapabilities clientCapabilities , Map <String , Root > roots ,
@@ -215,9 +218,9 @@ public McpAsyncClient(McpTransport transport, Duration requestTimeout, Implement
215218 */
216219 public Mono <McpSchema .InitializeResult > initialize () {
217220 McpSchema .InitializeRequest initializeRequest = new McpSchema .InitializeRequest (// @formatter:off
218- McpSchema .LATEST_PROTOCOL_VERSION ,
219- this .clientCapabilities ,
220- this .clientInfo ); // @formatter:on
221+ McpSchema .LATEST_PROTOCOL_VERSION ,
222+ this .clientCapabilities ,
223+ this .clientInfo ); // @formatter:on
221224
222225 Mono <McpSchema .InitializeResult > result = this .mcpSession .sendRequest ("initialize" , initializeRequest ,
223226 new TypeReference <McpSchema .InitializeResult >() {
@@ -239,10 +242,17 @@ public Mono<McpSchema.InitializeResult> initialize() {
239242 });
240243 }
241244
245+ /**
246+ * Closes the client connection immediately.
247+ */
242248 public void close () {
243249 this .mcpSession .close ();
244250 }
245251
252+ /**
253+ * Gracefully closes the client connection.
254+ * @return A Mono that completes when the connection is closed
255+ */
246256 public Mono <Void > closeGracefully () {
247257 return this .mcpSession .closeGracefully ();
248258 }
@@ -252,7 +262,8 @@ public Mono<Void> closeGracefully() {
252262 // --------------------------
253263
254264 /**
255- * Send a synchronous ping request.
265+ * Sends a ping request to the server.
266+ * @return A Mono that completes with the server's ping response
256267 */
257268 public Mono <Object > ping () {
258269 return this .mcpSession .sendRequest ("ping" , null , new TypeReference <Object >() {
@@ -262,6 +273,11 @@ public Mono<Object> ping() {
262273 // --------------------------
263274 // Roots
264275 // --------------------------
276+ /**
277+ * Adds a new root to the client's root list.
278+ * @param root The root to add
279+ * @return A Mono that completes when the root is added and notifications are sent
280+ */
265281 public Mono <Void > addRoot (Root root ) {
266282
267283 if (root == null ) {
@@ -286,6 +302,11 @@ public Mono<Void> addRoot(Root root) {
286302 return Mono .empty ();
287303 }
288304
305+ /**
306+ * Removes a root from the client's root list.
307+ * @param rootUri The URI of the root to remove
308+ * @return A Mono that completes when the root is removed and notifications are sent
309+ */
289310 public Mono <Void > removeRoot (String rootUri ) {
290311
291312 if (rootUri == null ) {
@@ -309,8 +330,9 @@ public Mono<Void> removeRoot(String rootUri) {
309330 }
310331
311332 /**
312- * Manually, send a roots/list_changed notification. The addRoot and removeRoot
333+ * Manually sends a roots/list_changed notification. The addRoot and removeRoot
313334 * methods automatically send the roots/list_changed notification.
335+ * @return A Mono that completes when the notification is sent
314336 */
315337 public Mono <Void > rootsListChangedNotification () {
316338 return this .mcpSession .sendNotification ("notifications/roots/list_changed" );
@@ -436,16 +458,16 @@ public Mono<Void> handle(Object params) {
436458
437459 /**
438460 * Send a resources/list request.
439- * @return the list of resources result.
461+ * @return A Mono that completes with the list of resources result
440462 */
441463 public Mono <McpSchema .ListResourcesResult > listResources () {
442464 return this .listResources (null );
443465 }
444466
445467 /**
446468 * Send a resources/list request.
447- * @param cursor the cursor
448- * @return the list of resources result.
469+ * @param cursor the cursor for pagination
470+ * @return A Mono that completes with the list of resources result
449471 */
450472 public Mono <McpSchema .ListResourcesResult > listResources (String cursor ) {
451473 return this .mcpSession .sendRequest ("resources/list" , new McpSchema .PaginatedRequest (cursor ),
@@ -455,16 +477,16 @@ public Mono<McpSchema.ListResourcesResult> listResources(String cursor) {
455477 /**
456478 * Send a resources/read request.
457479 * @param resource the resource to read
458- * @return the resource content.
480+ * @return A Mono that completes with the resource content
459481 */
460482 public Mono <McpSchema .ReadResourceResult > readResource (McpSchema .Resource resource ) {
461483 return this .readResource (new McpSchema .ReadResourceRequest (resource .uri ()));
462484 }
463485
464486 /**
465487 * Send a resources/read request.
466- * @param readResourceRequest the read resource request.
467- * @return the resource content.
488+ * @param readResourceRequest the read resource request
489+ * @return A Mono that completes with the resource content
468490 */
469491 public Mono <McpSchema .ReadResourceResult > readResource (McpSchema .ReadResourceRequest readResourceRequest ) {
470492 return this .mcpSession .sendRequest ("resources/read" , readResourceRequest , READ_RESOURCE_RESULT_TYPE_REF );
@@ -475,7 +497,7 @@ public Mono<McpSchema.ReadResourceResult> readResource(McpSchema.ReadResourceReq
475497 * templates. Arguments may be auto-completed through the completion API.
476498 *
477499 * Request a list of resource templates the server has.
478- * @return the list of resource templates result.
500+ * @return A Mono that completes with the list of resource templates result
479501 */
480502 public Mono <McpSchema .ListResourceTemplatesResult > listResourceTemplates () {
481503 return this .listResourceTemplates (null );
@@ -486,8 +508,8 @@ public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates() {
486508 * templates. Arguments may be auto-completed through the completion API.
487509 *
488510 * Request a list of resource templates the server has.
489- * @param cursor the cursor
490- * @return the list of resource templates result.
511+ * @param cursor the cursor for pagination
512+ * @return A Mono that completes with the list of resource templates result
491513 */
492514 public Mono <McpSchema .ListResourceTemplatesResult > listResourceTemplates (String cursor ) {
493515 return this .mcpSession .sendRequest ("resources/templates/list" , new McpSchema .PaginatedRequest (cursor ),
@@ -496,7 +518,8 @@ public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates(String
496518
497519 /**
498520 * List Changed Notification. When the list of available resources changes, servers
499- * that declared the listChanged capability SHOULD send a notification:
521+ * that declared the listChanged capability SHOULD send a notification.
522+ * @return A Mono that completes when the notification is sent
500523 */
501524 public Mono <Void > sendResourcesListChanged () {
502525 return this .mcpSession .sendNotification ("notifications/resources/list_changed" );
@@ -509,7 +532,8 @@ public Mono<Void> sendResourcesListChanged() {
509532 *
510533 * Send a resources/subscribe request.
511534 * @param subscribeRequest the subscribe request contains the uri of the resource to
512- * subscribe to.
535+ * subscribe to
536+ * @return A Mono that completes when the subscription is complete
513537 */
514538 public Mono <Void > subscribeResource (McpSchema .SubscribeRequest subscribeRequest ) {
515539 return this .mcpSession .sendRequest ("resources/subscribe" , subscribeRequest , VOID_TYPE_REFERENCE );
@@ -518,7 +542,8 @@ public Mono<Void> subscribeResource(McpSchema.SubscribeRequest subscribeRequest)
518542 /**
519543 * Send a resources/unsubscribe request.
520544 * @param unsubscribeRequest the unsubscribe request contains the uri of the resource
521- * to unsubscribe from.
545+ * to unsubscribe from
546+ * @return A Mono that completes when the unsubscription is complete
522547 */
523548 public Mono <Void > unsubscribeResource (McpSchema .UnsubscribeRequest unsubscribeRequest ) {
524549 return this .mcpSession .sendRequest ("resources/unsubscribe" , unsubscribeRequest , VOID_TYPE_REFERENCE );
@@ -554,25 +579,25 @@ public Mono<Void> handle(Object params) {
554579
555580 /**
556581 * List all available prompts.
557- * @return the list of prompts result.
582+ * @return A Mono that completes with the list of prompts result
558583 */
559584 public Mono <ListPromptsResult > listPrompts () {
560585 return this .listPrompts (null );
561586 }
562587
563588 /**
564589 * List all available prompts.
565- * @param cursor the cursor
566- * @return the list of prompts result.
590+ * @param cursor the cursor for pagination
591+ * @return A Mono that completes with the list of prompts result
567592 */
568593 public Mono <ListPromptsResult > listPrompts (String cursor ) {
569594 return this .mcpSession .sendRequest ("prompts/list" , new PaginatedRequest (cursor ), LIST_PROMPTS_RESULT_TYPE_REF );
570595 }
571596
572597 /**
573598 * Get a prompt by its id.
574- * @param getPromptRequest the get prompt request.
575- * @return the get prompt result.
599+ * @param getPromptRequest the get prompt request
600+ * @return A Mono that completes with the get prompt result
576601 */
577602 public Mono <GetPromptResult > getPrompt (GetPromptRequest getPromptRequest ) {
578603 return this .mcpSession .sendRequest ("prompts/get" , getPromptRequest , GET_PROMPT_RESULT_TYPE_REF );
@@ -582,6 +607,7 @@ public Mono<GetPromptResult> getPrompt(GetPromptRequest getPromptRequest) {
582607 * (Server) An optional notification from the server to the client, informing it that
583608 * the list of prompts it offers has changed. This may be issued by servers without
584609 * any previous subscription from the client.
610+ * @return A Mono that completes when the notification is sent
585611 */
586612 public Mono <Void > promptListChangedNotification () {
587613 return this .mcpSession .sendNotification ("notifications/prompts/list_changed" );
0 commit comments