From 2b42379c577b5753ade1b0408e9b27c5639e554a Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Wed, 1 Jan 2025 13:33:54 +0100 Subject: [PATCH] feat: add getters for server/client capabilities and implementation info Add getter methods to expose server and client capabilities and implementation information in both McpAsyncServer and McpSyncServer classes. Store client metadata received during initialization for later retrieval. --- .../ai/mcp/server/McpAsyncServer.java | 40 +++++++++++++++++++ .../ai/mcp/server/McpSyncServer.java | 36 ++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/mcp/src/main/java/org/springframework/ai/mcp/server/McpAsyncServer.java b/mcp/src/main/java/org/springframework/ai/mcp/server/McpAsyncServer.java index 75d68e7..d25003d 100644 --- a/mcp/src/main/java/org/springframework/ai/mcp/server/McpAsyncServer.java +++ b/mcp/src/main/java/org/springframework/ai/mcp/server/McpAsyncServer.java @@ -38,6 +38,7 @@ import org.springframework.ai.mcp.spec.DefaultMcpSession.NotificationHandler; import org.springframework.ai.mcp.spec.McpError; import org.springframework.ai.mcp.spec.McpSchema; import org.springframework.ai.mcp.spec.McpSchema.CallToolResult; +import org.springframework.ai.mcp.spec.McpSchema.ClientCapabilities; import org.springframework.ai.mcp.spec.McpSchema.LoggingLevel; import org.springframework.ai.mcp.spec.McpSchema.LoggingMessageNotification; import org.springframework.ai.mcp.spec.McpSchema.Tool; @@ -66,6 +67,10 @@ public class McpAsyncServer { private final McpSchema.Implementation serverInfo; + private McpSchema.ClientCapabilities clientCapabilities; + + private McpSchema.Implementation clientInfo; + /** * Thread-safe list of tool handlers that can be modified at runtime. */ @@ -165,6 +170,9 @@ public class McpAsyncServer { new TypeReference() { }); + this.clientCapabilities = initializeRequest.capabilities(); + this.clientInfo = initializeRequest.clientInfo(); + logger.info("Client initialize request - Protocol: {}, Capabilities: {}, Info: {}", initializeRequest.protocolVersion(), initializeRequest.capabilities(), initializeRequest.clientInfo()); @@ -183,6 +191,38 @@ public class McpAsyncServer { }; } + /** + * Get the server capabilities that define the supported features and functionality. + * @return The server capabilities + */ + public McpSchema.ServerCapabilities getServerCapabilities() { + return this.serverCapabilities; + } + + /** + * Get the server implementation information. + * @return The server implementation details + */ + public McpSchema.Implementation getServerInfo() { + return this.serverInfo; + } + + /** + * Get the client capabilities that define the supported features and functionality. + * @return The client capabilities + */ + public ClientCapabilities getClientCapabilities() { + return this.clientCapabilities; + } + + /** + * Get the client implementation information. + * @return The client implementation details + */ + public McpSchema.Implementation getClientInfo() { + return this.clientInfo; + } + /** * Gracefully closes the server, allowing any in-progress operations to complete. * @return A Mono that completes when the server has been closed diff --git a/mcp/src/main/java/org/springframework/ai/mcp/server/McpSyncServer.java b/mcp/src/main/java/org/springframework/ai/mcp/server/McpSyncServer.java index 97f6b9e..4a11943 100644 --- a/mcp/src/main/java/org/springframework/ai/mcp/server/McpSyncServer.java +++ b/mcp/src/main/java/org/springframework/ai/mcp/server/McpSyncServer.java @@ -16,11 +16,11 @@ package org.springframework.ai.mcp.server; -import reactor.core.publisher.Mono; - import org.springframework.ai.mcp.server.McpServer.PromptRegistration; import org.springframework.ai.mcp.server.McpServer.ResourceRegistration; import org.springframework.ai.mcp.server.McpServer.ToolRegistration; +import org.springframework.ai.mcp.spec.McpSchema; +import org.springframework.ai.mcp.spec.McpSchema.ClientCapabilities; import org.springframework.ai.mcp.spec.McpSchema.LoggingMessageNotification; import org.springframework.ai.mcp.util.Assert; @@ -124,6 +124,38 @@ public class McpSyncServer { this.asyncServer.loggingNotification(loggingMessageNotification).block(); } + /** + * Get the server capabilities that define the supported features and functionality. + * @return The server capabilities + */ + public McpSchema.ServerCapabilities getServerCapabilities() { + return this.asyncServer.getServerCapabilities(); + } + + /** + * Get the server implementation information. + * @return The server implementation details + */ + public McpSchema.Implementation getServerInfo() { + return this.asyncServer.getServerInfo(); + } + + /** + * Get the client capabilities that define the supported features and functionality. + * @return The client capabilities + */ + public ClientCapabilities getClientCapabilities() { + return this.asyncServer.getClientCapabilities(); + } + + /** + * Get the client implementation information. + * @return The client implementation details + */ + public McpSchema.Implementation getClientInfo() { + return this.asyncServer.getClientInfo(); + } + /** * Close the server gracefully. */