From be31c6119ced3325a22077dbf00254beb3432070 Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Fri, 13 Dec 2024 09:15:28 +0100 Subject: [PATCH] feat(mcp): add convenience methods without cursor parameter Add overloaded methods for list operations (tools, resources, templates, prompts) that don't require a cursor parameter, simplifying the API for basic use cases where pagination is not needed. --- .../ai/mcp/client/McpSyncClient.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpSyncClient.java b/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpSyncClient.java index 208eedf..2454a2e 100644 --- a/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpSyncClient.java +++ b/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/McpSyncClient.java @@ -111,6 +111,15 @@ public class McpSyncClient implements AutoCloseable { * Send a tools/list request. * @return the list of tools result. */ + public McpSchema.ListToolsResult listTools() { + return this.delegate.listTools().block(); + } + + /** + * Send a tools/list request. + * @param cursor the cursor + * @return the list of tools result. + */ public McpSchema.ListToolsResult listTools(String cursor) { return this.delegate.listTools(cursor).block(); } @@ -128,6 +137,14 @@ public class McpSyncClient implements AutoCloseable { return this.delegate.listResources(cursor).block(); } + /** + * Send a resources/list request. + * @return the list of resources result. + */ + public McpSchema.ListResourcesResult listResources() { + return this.delegate.listResources().block(); + } + /** * Send a resources/read request. * @param resource the resource to read @@ -158,6 +175,14 @@ public class McpSyncClient implements AutoCloseable { return this.delegate.listResourceTemplates(cursor).block(); } + /** + * Request a list of resource templates the server has. + * @return the list of resource templates result. + */ + public McpSchema.ListResourceTemplatesResult listResourceTemplates() { + return this.delegate.listResourceTemplates().block(); + } + /** * List Changed Notification. When the list of available resources changes, servers * that declared the listChanged capability SHOULD send a notification: @@ -195,6 +220,10 @@ public class McpSyncClient implements AutoCloseable { return this.delegate.listPrompts(cursor).block(); } + public ListPromptsResult listPrompts() { + return this.delegate.listPrompts().block(); + } + public GetPromptResult getPrompt(GetPromptRequest getPromptRequest) { return this.delegate.getPrompt(getPromptRequest).block(); }