From e9bafe9f21d4dd806a99d02b98c90d4aea310f62 Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Thu, 12 Dec 2024 14:28:39 +0100 Subject: [PATCH] feat(client): add convenience methods for listing operations without cursor Add overloaded methods for list operations (tools, resources, templates, prompts) that don't require a cursor parameter. This simplifies the API for cases where pagination is not needed. --- .../ai/mcp/client/McpAsyncClient.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpAsyncClient.java b/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpAsyncClient.java index 7c6c896..4589855 100644 --- a/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpAsyncClient.java +++ b/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpAsyncClient.java @@ -132,6 +132,15 @@ public class McpAsyncClient extends DefaultMcpSession { * Send a tools/list request. * @return the list of tools result. */ + public Mono listTools() { + return this.listTools(null); + } + + /** + * Send a tools/list request. + * @param cursor the cursor + * @return the list of tools result. + */ public Mono listTools(String cursor) { return this.sendRequest("tools/list", new McpSchema.PaginatedRequest(cursor), LIST_TOOLS_RESULT_TYPE_REF); } @@ -149,6 +158,14 @@ public class McpAsyncClient extends DefaultMcpSession { private static TypeReference LIST_RESOURCE_TEMPLATES_RESULT_TYPE_REF = new TypeReference() { }; + /** + * Send a resources/list request. + * @return the list of resources result. + */ + public Mono listResources() { + return this.listResources(null); + } + /** * Send a resources/list request. * @param cursor the cursor @@ -177,6 +194,17 @@ public class McpAsyncClient extends DefaultMcpSession { return this.sendRequest("resources/read", readResourceRequest, READ_RESOURCE_RESULT_TYPE_REF); } + /** + * Resource templates allow servers to expose parameterized resources using URI + * templates. Arguments may be auto-completed through the completion API. + * + * Request a list of resource templates the server has. + * @return the list of resource templates result. + */ + public Mono listResourceTemplates() { + return this.listResourceTemplates(null); + } + /** * Resource templates allow servers to expose parameterized resources using URI * templates. Arguments may be auto-completed through the completion API. @@ -229,10 +257,28 @@ public class McpAsyncClient extends DefaultMcpSession { private static TypeReference GET_PROMPT_RESULT_TYPE_REF = new TypeReference() { }; + /** + * List all available prompts. + * @return the list of prompts result. + */ + public Mono listPrompts() { + return this.listPrompts(null); + } + + /** + * List all available prompts. + * @param cursor the cursor + * @return the list of prompts result. + */ public Mono listPrompts(String cursor) { return this.sendRequest("prompts/list", new PaginatedRequest(cursor), LIST_PROMPTS_RESULT_TYPE_REF); } + /** + * Get a prompt by its id. + * @param getPromptRequest the get prompt request. + * @return the get prompt result. + */ public Mono getPrompt(GetPromptRequest getPromptRequest) { return this.sendRequest("prompts/get", getPromptRequest, GET_PROMPT_RESULT_TYPE_REF); }