Skip to content

Commit 0b0d508

Browse files
committed
feat: add server/client metadata getters to MCP clients
Add getter methods to expose server and client capabilities and implementation info in McpAsyncClient and McpSyncClient. Store server metadata received during initialization for later access.
1 parent 2b42379 commit 0b0d508

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

mcp/src/main/java/org/springframework/ai/mcp/client/McpAsyncClient.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ public class McpAsyncClient {
7777
*/
7878
private final McpSchema.ClientCapabilities clientCapabilities;
7979

80+
/**
81+
* Client implementation information.
82+
*/
83+
private final McpSchema.Implementation clientInfo;
84+
85+
/**
86+
* Server capabilities.
87+
*/
88+
private McpSchema.ServerCapabilities serverCapabilities;
89+
90+
/**
91+
* Server implementation information.
92+
*/
93+
private McpSchema.Implementation serverInfo;
94+
8095
/**
8196
* Roots define the boundaries of where servers can operate within the filesystem,
8297
* allowing them to understand which directories and files they have access to.
@@ -100,11 +115,6 @@ public class McpAsyncClient {
100115
*/
101116
private final McpTransport transport;
102117

103-
/**
104-
* Client implementation information.
105-
*/
106-
private Implementation clientInfo;
107-
108118
/**
109119
* Create a new McpAsyncClient with the given transport and session request-response
110120
* timeout.
@@ -241,6 +251,9 @@ public Mono<McpSchema.InitializeResult> initialize() {
241251

242252
return result.flatMap(initializeResult -> {
243253

254+
this.serverCapabilities = initializeResult.capabilities();
255+
this.serverInfo = initializeResult.serverInfo();
256+
244257
logger.info("Server response with Protocol: {}, Capabilities: {}, Info: {} and Instructions {}",
245258
initializeResult.protocolVersion(), initializeResult.capabilities(), initializeResult.serverInfo(),
246259
initializeResult.instructions());
@@ -256,6 +269,38 @@ public Mono<McpSchema.InitializeResult> initialize() {
256269
});
257270
}
258271

272+
/**
273+
* Get the server capabilities that define the supported features and functionality.
274+
* @return The server capabilities
275+
*/
276+
public McpSchema.ServerCapabilities getServerCapabilities() {
277+
return this.serverCapabilities;
278+
}
279+
280+
/**
281+
* Get the server implementation information.
282+
* @return The server implementation details
283+
*/
284+
public McpSchema.Implementation getServerInfo() {
285+
return this.serverInfo;
286+
}
287+
288+
/**
289+
* Get the client capabilities that define the supported features and functionality.
290+
* @return The client capabilities
291+
*/
292+
public ClientCapabilities getClientCapabilities() {
293+
return this.clientCapabilities;
294+
}
295+
296+
/**
297+
* Get the client implementation information.
298+
* @return The client implementation details
299+
*/
300+
public McpSchema.Implementation getClientInfo() {
301+
return this.clientInfo;
302+
}
303+
259304
/**
260305
* Closes the client connection immediately.
261306
*/

mcp/src/main/java/org/springframework/ai/mcp/client/McpSyncClient.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.slf4j.LoggerFactory;
2323

2424
import org.springframework.ai.mcp.spec.McpSchema;
25+
import org.springframework.ai.mcp.spec.McpSchema.ClientCapabilities;
2526
import org.springframework.ai.mcp.spec.McpSchema.GetPromptRequest;
2627
import org.springframework.ai.mcp.spec.McpSchema.GetPromptResult;
2728
import org.springframework.ai.mcp.spec.McpSchema.ListPromptsResult;
@@ -49,6 +50,38 @@ public McpSyncClient(McpAsyncClient delegate) {
4950
this.delegate = delegate;
5051
}
5152

53+
/**
54+
* Get the server capabilities that define the supported features and functionality.
55+
* @return The server capabilities
56+
*/
57+
public McpSchema.ServerCapabilities getServerCapabilities() {
58+
return this.delegate.getServerCapabilities();
59+
}
60+
61+
/**
62+
* Get the server implementation information.
63+
* @return The server implementation details
64+
*/
65+
public McpSchema.Implementation getServerInfo() {
66+
return this.delegate.getServerInfo();
67+
}
68+
69+
/**
70+
* Get the client capabilities that define the supported features and functionality.
71+
* @return The client capabilities
72+
*/
73+
public ClientCapabilities getClientCapabilities() {
74+
return this.delegate.getClientCapabilities();
75+
}
76+
77+
/**
78+
* Get the client implementation information.
79+
* @return The client implementation details
80+
*/
81+
public McpSchema.Implementation getClientInfo() {
82+
return this.delegate.getClientInfo();
83+
}
84+
5285
@Override
5386
public void close() {
5487
this.delegate.close();

0 commit comments

Comments
 (0)