Skip to content

Commit 2b42379

Browse files
committed
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.
1 parent 8665934 commit 2b42379

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

mcp/src/main/java/org/springframework/ai/mcp/server/McpAsyncServer.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.ai.mcp.spec.McpError;
3939
import org.springframework.ai.mcp.spec.McpSchema;
4040
import org.springframework.ai.mcp.spec.McpSchema.CallToolResult;
41+
import org.springframework.ai.mcp.spec.McpSchema.ClientCapabilities;
4142
import org.springframework.ai.mcp.spec.McpSchema.LoggingLevel;
4243
import org.springframework.ai.mcp.spec.McpSchema.LoggingMessageNotification;
4344
import org.springframework.ai.mcp.spec.McpSchema.Tool;
@@ -66,6 +67,10 @@ public class McpAsyncServer {
6667

6768
private final McpSchema.Implementation serverInfo;
6869

70+
private McpSchema.ClientCapabilities clientCapabilities;
71+
72+
private McpSchema.Implementation clientInfo;
73+
6974
/**
7075
* Thread-safe list of tool handlers that can be modified at runtime.
7176
*/
@@ -165,6 +170,9 @@ private DefaultMcpSession.RequestHandler initializeRequestHandler() {
165170
new TypeReference<McpSchema.InitializeRequest>() {
166171
});
167172

173+
this.clientCapabilities = initializeRequest.capabilities();
174+
this.clientInfo = initializeRequest.clientInfo();
175+
168176
logger.info("Client initialize request - Protocol: {}, Capabilities: {}, Info: {}",
169177
initializeRequest.protocolVersion(), initializeRequest.capabilities(),
170178
initializeRequest.clientInfo());
@@ -183,6 +191,38 @@ private DefaultMcpSession.RequestHandler initializeRequestHandler() {
183191
};
184192
}
185193

194+
/**
195+
* Get the server capabilities that define the supported features and functionality.
196+
* @return The server capabilities
197+
*/
198+
public McpSchema.ServerCapabilities getServerCapabilities() {
199+
return this.serverCapabilities;
200+
}
201+
202+
/**
203+
* Get the server implementation information.
204+
* @return The server implementation details
205+
*/
206+
public McpSchema.Implementation getServerInfo() {
207+
return this.serverInfo;
208+
}
209+
210+
/**
211+
* Get the client capabilities that define the supported features and functionality.
212+
* @return The client capabilities
213+
*/
214+
public ClientCapabilities getClientCapabilities() {
215+
return this.clientCapabilities;
216+
}
217+
218+
/**
219+
* Get the client implementation information.
220+
* @return The client implementation details
221+
*/
222+
public McpSchema.Implementation getClientInfo() {
223+
return this.clientInfo;
224+
}
225+
186226
/**
187227
* Gracefully closes the server, allowing any in-progress operations to complete.
188228
* @return A Mono that completes when the server has been closed

mcp/src/main/java/org/springframework/ai/mcp/server/McpSyncServer.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package org.springframework.ai.mcp.server;
1818

19-
import reactor.core.publisher.Mono;
20-
2119
import org.springframework.ai.mcp.server.McpServer.PromptRegistration;
2220
import org.springframework.ai.mcp.server.McpServer.ResourceRegistration;
2321
import org.springframework.ai.mcp.server.McpServer.ToolRegistration;
22+
import org.springframework.ai.mcp.spec.McpSchema;
23+
import org.springframework.ai.mcp.spec.McpSchema.ClientCapabilities;
2424
import org.springframework.ai.mcp.spec.McpSchema.LoggingMessageNotification;
2525
import org.springframework.ai.mcp.util.Assert;
2626

@@ -124,6 +124,38 @@ public void loggingNotification(LoggingMessageNotification loggingMessageNotific
124124
this.asyncServer.loggingNotification(loggingMessageNotification).block();
125125
}
126126

127+
/**
128+
* Get the server capabilities that define the supported features and functionality.
129+
* @return The server capabilities
130+
*/
131+
public McpSchema.ServerCapabilities getServerCapabilities() {
132+
return this.asyncServer.getServerCapabilities();
133+
}
134+
135+
/**
136+
* Get the server implementation information.
137+
* @return The server implementation details
138+
*/
139+
public McpSchema.Implementation getServerInfo() {
140+
return this.asyncServer.getServerInfo();
141+
}
142+
143+
/**
144+
* Get the client capabilities that define the supported features and functionality.
145+
* @return The client capabilities
146+
*/
147+
public ClientCapabilities getClientCapabilities() {
148+
return this.asyncServer.getClientCapabilities();
149+
}
150+
151+
/**
152+
* Get the client implementation information.
153+
* @return The client implementation details
154+
*/
155+
public McpSchema.Implementation getClientInfo() {
156+
return this.asyncServer.getClientInfo();
157+
}
158+
127159
/**
128160
* Close the server gracefully.
129161
*/

0 commit comments

Comments
 (0)