1313import java .util .function .Function ;
1414import java .util .function .Supplier ;
1515
16+ import org .slf4j .Logger ;
17+ import org .slf4j .LoggerFactory ;
18+
1619import com .fasterxml .jackson .core .type .TypeReference ;
20+
1721import io .modelcontextprotocol .spec .McpClientSession ;
1822import io .modelcontextprotocol .spec .McpClientSession .NotificationHandler ;
1923import io .modelcontextprotocol .spec .McpClientSession .RequestHandler ;
3539import io .modelcontextprotocol .spec .McpTransportSessionNotFoundException ;
3640import io .modelcontextprotocol .util .Assert ;
3741import io .modelcontextprotocol .util .Utils ;
38- import org .slf4j .Logger ;
39- import org .slf4j .LoggerFactory ;
4042import reactor .core .publisher .Flux ;
4143import reactor .core .publisher .Mono ;
4244import reactor .core .publisher .Sinks ;
@@ -656,7 +658,7 @@ public Mono<McpSchema.CallToolResult> callTool(McpSchema.CallToolRequest callToo
656658 }
657659
658660 /**
659- * Retrieves the list of all tools provided by the server.
661+ * Retrieves the first page of tools provided by the server.
660662 * @return A Mono that emits the list of tools result.
661663 */
662664 public Mono <McpSchema .ListToolsResult > listTools () {
@@ -679,18 +681,26 @@ public Mono<McpSchema.ListToolsResult> listTools(String cursor) {
679681 });
680682 }
681683
682- private NotificationHandler asyncToolsChangeNotificationHandler (
683- List <Function <List <McpSchema .Tool >, Mono <Void >>> toolsChangeConsumers ) {
684- // TODO: params are not used yet
685- return params -> this .listTools ().expand (result -> {
684+ /**
685+ * Retrieves list of all tools provided by the server after handling pagination.
686+ * @return A Mono that emits a list of all tools
687+ */
688+ public Mono <List <McpSchema .Tool >> listAllTools () {
689+ return this .listTools ().expand (result -> {
686690 if (result .nextCursor () != null ) {
687691 return this .listTools (result .nextCursor ());
688692 }
689693 return Mono .empty ();
690- }).reduce (new ArrayList <McpSchema . Tool >(), (allTools , result ) -> {
694+ }).reduce (new ArrayList <>(), (allTools , result ) -> {
691695 allTools .addAll (result .tools ());
692696 return allTools ;
693- })
697+ });
698+ }
699+
700+ private NotificationHandler asyncToolsChangeNotificationHandler (
701+ List <Function <List <McpSchema .Tool >, Mono <Void >>> toolsChangeConsumers ) {
702+ // TODO: params are not used yet
703+ return params -> this .listAllTools ()
694704 .flatMap (allTools -> Flux .fromIterable (toolsChangeConsumers )
695705 .flatMap (consumer -> consumer .apply (allTools ))
696706 .onErrorResume (error -> {
@@ -714,9 +724,9 @@ private NotificationHandler asyncToolsChangeNotificationHandler(
714724 };
715725
716726 /**
717- * Retrieves the list of all resources provided by the server. Resources represent any
718- * kind of UTF-8 encoded data that an MCP server makes available to clients, such as
719- * database records, API responses, log files, and more.
727+ * Retrieves the first page of resources provided by the server. Resources represent
728+ * any kind of UTF-8 encoded data that an MCP server makes available to clients, such
729+ * as database records, API responses, log files, and more.
720730 * @return A Mono that completes with the list of resources result.
721731 * @see McpSchema.ListResourcesResult
722732 * @see #readResource(McpSchema.Resource)
@@ -745,6 +755,26 @@ public Mono<McpSchema.ListResourcesResult> listResources(String cursor) {
745755 });
746756 }
747757
758+ /**
759+ * Retrieves the list of all resources provided by the server. Resources represent any
760+ * kind of UTF-8 encoded data that an MCP server makes available to clients, such as
761+ * database records, API responses, log files, and more.
762+ * @return A Mono that completes with list of all resources.
763+ * @see McpSchema.Resource
764+ * @see #readResource(McpSchema.Resource)
765+ */
766+ public Mono <List <McpSchema .Resource >> listAllResources () {
767+ return this .listResources ().expand (result -> {
768+ if (result .nextCursor () != null ) {
769+ return this .listResources (result .nextCursor ());
770+ }
771+ return Mono .empty ();
772+ }).reduce (new ArrayList <>(), (allResources , result ) -> {
773+ allResources .addAll (result .resources ());
774+ return allResources ;
775+ });
776+ }
777+
748778 /**
749779 * Reads the content of a specific resource identified by the provided Resource
750780 * object. This method fetches the actual data that the resource represents.
@@ -777,7 +807,7 @@ public Mono<McpSchema.ReadResourceResult> readResource(McpSchema.ReadResourceReq
777807 }
778808
779809 /**
780- * Retrieves the list of all resource templates provided by the server. Resource
810+ * Retrieves the first page of resource templates provided by the server. Resource
781811 * templates allow servers to expose parameterized resources using URI templates,
782812 * enabling dynamic resource access based on variable parameters.
783813 * @return A Mono that completes with the list of resource templates result.
@@ -806,6 +836,25 @@ public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates(String
806836 });
807837 }
808838
839+ /**
840+ * Retrieves the list of all resource templates provided by the server. Resource
841+ * templates allow servers to expose parameterized resources using URI templates,
842+ * enabling dynamic resource access based on variable parameters.
843+ * @return A Mono that completes with the list of all resource templates.
844+ * @see McpSchema.ResourceTemplate
845+ */
846+ public Mono <List <McpSchema .ResourceTemplate >> listAllResourceTemplates () {
847+ return this .listResourceTemplates ().expand (result -> {
848+ if (result .nextCursor () != null ) {
849+ return this .listResourceTemplates (result .nextCursor ());
850+ }
851+ return Mono .empty ();
852+ }).reduce (new ArrayList <>(), (allResourceTemplates , result ) -> {
853+ allResourceTemplates .addAll (result .resourceTemplates ());
854+ return allResourceTemplates ;
855+ });
856+ }
857+
809858 /**
810859 * Subscribes to changes in a specific resource. When the resource changes on the
811860 * server, the client will receive notifications through the resources change
@@ -855,7 +904,7 @@ private NotificationHandler asyncResourcesChangeNotificationHandler(
855904 };
856905
857906 /**
858- * Retrieves the list of all prompts provided by the server.
907+ * Retrieves the first page of prompts provided by the server.
859908 * @return A Mono that completes with the list of prompts result.
860909 * @see McpSchema.ListPromptsResult
861910 * @see #getPrompt(GetPromptRequest)
@@ -876,6 +925,24 @@ public Mono<ListPromptsResult> listPrompts(String cursor) {
876925 .sendRequest (McpSchema .METHOD_PROMPT_LIST , new PaginatedRequest (cursor ), LIST_PROMPTS_RESULT_TYPE_REF ));
877926 }
878927
928+ /**
929+ * Retrieves the list of all prompts provided by the server.
930+ * @return A Mono that completes with the list of all prompts.
931+ * @see McpSchema.Prompt
932+ * @see #getPrompt(GetPromptRequest)
933+ */
934+ public Mono <List <McpSchema .Prompt >> listAllPrompts () {
935+ return this .listPrompts ().expand (result -> {
936+ if (result .nextCursor () != null ) {
937+ return this .listPrompts (result .nextCursor ());
938+ }
939+ return Mono .empty ();
940+ }).reduce (new ArrayList <>(), (allPrompts , result ) -> {
941+ allPrompts .addAll (result .prompts ());
942+ return allPrompts ;
943+ });
944+ }
945+
879946 /**
880947 * Retrieves a specific prompt by its ID. This provides the complete prompt template
881948 * including all parameters and instructions for generating AI content.
0 commit comments