Skip to content

Commit d5ebad4

Browse files
committed
Update docs
Signed-off-by: Christian Tzolov <[email protected]>
1 parent 3c69651 commit d5ebad4

File tree

3 files changed

+48
-111
lines changed

3 files changed

+48
-111
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-annotations-client.adoc

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The MCP Client Annotations provide a declarative way to implement MCP client han
44
These annotations simplify the handling of server notifications and client-side operations.
55

66
[IMPORTANT]
7-
**All MCP client annotations MUST include a `clientId` parameter** to associate the handler with a specific MCP client connection. The `clientId` must match the connection name configured in your application properties.
7+
**All MCP client annotations MUST include a `clients` parameter** to associate the handler with a specific MCP client connection. The `clients` must match the connection name configured in your application properties.
88

99
== Client Annotations
1010

@@ -19,7 +19,7 @@ The `@McpLogging` annotation handles logging message notifications from MCP serv
1919
@Component
2020
public class LoggingHandler {
2121
22-
@McpLogging(clientId = "my-mcp-server")
22+
@McpLogging(clients = "my-mcp-server")
2323
public void handleLoggingMessage(LoggingMessageNotification notification) {
2424
System.out.println("Received log: " + notification.level() +
2525
" - " + notification.data());
@@ -31,7 +31,7 @@ public class LoggingHandler {
3131

3232
[source,java]
3333
----
34-
@McpLogging(clientId = "my-mcp-server")
34+
@McpLogging(clients = "my-mcp-server")
3535
public void handleLoggingWithParams(LoggingLevel level, String logger, String data) {
3636
System.out.println(String.format("[%s] %s: %s", level, logger, data));
3737
}
@@ -41,13 +41,13 @@ public void handleLoggingWithParams(LoggingLevel level, String logger, String da
4141

4242
[source,java]
4343
----
44-
@McpLogging(clientId = "server1")
44+
@McpLogging(clients = "server1")
4545
public void handleServer1Logs(LoggingMessageNotification notification) {
4646
// Handle logs from specific server
4747
logToFile("server1.log", notification);
4848
}
4949
50-
@McpLogging(clientId = "server2")
50+
@McpLogging(clients = "server2")
5151
public void handleServer2Logs(LoggingMessageNotification notification) {
5252
// Handle logs from another server
5353
logToDatabase("server2", notification);
@@ -65,7 +65,7 @@ The `@McpSampling` annotation handles sampling requests from MCP servers for LLM
6565
@Component
6666
public class SamplingHandler {
6767
68-
@McpSampling(clientId = "llm-server")
68+
@McpSampling(clients = "llm-server")
6969
public CreateMessageResult handleSamplingRequest(CreateMessageRequest request) {
7070
// Process the request and generate a response
7171
String response = generateLLMResponse(request);
@@ -86,7 +86,7 @@ public class SamplingHandler {
8686
@Component
8787
public class AsyncSamplingHandler {
8888
89-
@McpSampling(clientId = "llm-server")
89+
@McpSampling(clients = "llm-server")
9090
public Mono<CreateMessageResult> handleAsyncSampling(CreateMessageRequest request) {
9191
return Mono.fromCallable(() -> {
9292
String response = generateLLMResponse(request);
@@ -105,7 +105,7 @@ public class AsyncSamplingHandler {
105105

106106
[source,java]
107107
----
108-
@McpSampling(clientId = "specialized-server")
108+
@McpSampling(clients = "specialized-server")
109109
public CreateMessageResult handleSpecializedSampling(CreateMessageRequest request) {
110110
// Use specialized model for this server
111111
String response = generateSpecializedResponse(request);
@@ -129,7 +129,7 @@ The `@McpElicitation` annotation handles elicitation requests to gather addition
129129
@Component
130130
public class ElicitationHandler {
131131
132-
@McpElicitation(clientId = "interactive-server")
132+
@McpElicitation(clients = "interactive-server")
133133
public ElicitResult handleElicitationRequest(ElicitRequest request) {
134134
// Present the request to the user and gather input
135135
Map<String, Object> userData = presentFormToUser(request.requestedSchema());
@@ -147,7 +147,7 @@ public class ElicitationHandler {
147147

148148
[source,java]
149149
----
150-
@McpElicitation(clientId = "interactive-server")
150+
@McpElicitation(clients = "interactive-server")
151151
public ElicitResult handleInteractiveElicitation(ElicitRequest request) {
152152
Map<String, Object> schema = request.requestedSchema();
153153
Map<String, Object> userData = new HashMap<>();
@@ -177,7 +177,7 @@ public ElicitResult handleInteractiveElicitation(ElicitRequest request) {
177177

178178
[source,java]
179179
----
180-
@McpElicitation(clientId = "interactive-server")
180+
@McpElicitation(clients = "interactive-server")
181181
public Mono<ElicitResult> handleAsyncElicitation(ElicitRequest request) {
182182
return Mono.fromCallable(() -> {
183183
// Async user interaction
@@ -199,7 +199,7 @@ The `@McpProgress` annotation handles progress notifications for long-running op
199199
@Component
200200
public class ProgressHandler {
201201
202-
@McpProgress(clientId = "my-mcp-server")
202+
@McpProgress(clients = "my-mcp-server")
203203
public void handleProgressNotification(ProgressNotification notification) {
204204
double percentage = notification.progress() * 100;
205205
System.out.println(String.format("Progress: %.2f%% - %s",
@@ -212,7 +212,7 @@ public class ProgressHandler {
212212

213213
[source,java]
214214
----
215-
@McpProgress(clientId = "my-mcp-server")
215+
@McpProgress(clients = "my-mcp-server")
216216
public void handleProgressWithDetails(
217217
String progressToken,
218218
double progress,
@@ -236,7 +236,7 @@ public void handleProgressWithDetails(
236236

237237
[source,java]
238238
----
239-
@McpProgress(clientId = "long-running-server")
239+
@McpProgress(clients = "long-running-server")
240240
public void handleLongRunningProgress(ProgressNotification notification) {
241241
// Track progress for specific server
242242
progressTracker.update("long-running-server", notification);
@@ -259,7 +259,7 @@ The `@McpToolListChanged` annotation handles notifications when the server's too
259259
@Component
260260
public class ToolListChangedHandler {
261261
262-
@McpToolListChanged(clientId = "tool-server")
262+
@McpToolListChanged(clients = "tool-server")
263263
public void handleToolListChanged(List<McpSchema.Tool> updatedTools) {
264264
System.out.println("Tool list updated: " + updatedTools.size() + " tools available");
265265
@@ -278,7 +278,7 @@ public class ToolListChangedHandler {
278278

279279
[source,java]
280280
----
281-
@McpToolListChanged(clientId = "tool-server")
281+
@McpToolListChanged(clients = "tool-server")
282282
public Mono<Void> handleAsyncToolListChanged(List<McpSchema.Tool> updatedTools) {
283283
return Mono.fromRunnable(() -> {
284284
// Process tool list update asynchronously
@@ -294,7 +294,7 @@ public Mono<Void> handleAsyncToolListChanged(List<McpSchema.Tool> updatedTools)
294294

295295
[source,java]
296296
----
297-
@McpToolListChanged(clientId = "dynamic-server")
297+
@McpToolListChanged(clients = "dynamic-server")
298298
public void handleDynamicServerToolUpdate(List<McpSchema.Tool> updatedTools) {
299299
// Handle tools from a specific server that frequently changes its tools
300300
dynamicToolManager.updateServerTools("dynamic-server", updatedTools);
@@ -315,7 +315,7 @@ The `@McpResourceListChanged` annotation handles notifications when the server's
315315
@Component
316316
public class ResourceListChangedHandler {
317317
318-
@McpResourceListChanged(clientId = "resource-server")
318+
@McpResourceListChanged(clients = "resource-server")
319319
public void handleResourceListChanged(List<McpSchema.Resource> updatedResources) {
320320
System.out.println("Resources updated: " + updatedResources.size());
321321
@@ -332,7 +332,7 @@ public class ResourceListChangedHandler {
332332

333333
[source,java]
334334
----
335-
@McpResourceListChanged(clientId = "resource-server")
335+
@McpResourceListChanged(clients = "resource-server")
336336
public void analyzeResourceChanges(List<McpSchema.Resource> updatedResources) {
337337
// Analyze what changed
338338
Set<String> newUris = updatedResources.stream()
@@ -363,7 +363,7 @@ The `@McpPromptListChanged` annotation handles notifications when the server's p
363363
@Component
364364
public class PromptListChangedHandler {
365365
366-
@McpPromptListChanged(clientId = "prompt-server")
366+
@McpPromptListChanged(clients = "prompt-server")
367367
public void handlePromptListChanged(List<McpSchema.Prompt> updatedPrompts) {
368368
System.out.println("Prompts updated: " + updatedPrompts.size());
369369
@@ -382,7 +382,7 @@ public class PromptListChangedHandler {
382382

383383
[source,java]
384384
----
385-
@McpPromptListChanged(clientId = "prompt-server")
385+
@McpPromptListChanged(clients = "prompt-server")
386386
public Mono<Void> handleAsyncPromptUpdate(List<McpSchema.Prompt> updatedPrompts) {
387387
return Flux.fromIterable(updatedPrompts)
388388
.flatMap(prompt -> validatePrompt(prompt))
@@ -409,18 +409,18 @@ public class McpClientApplication {
409409
410410
@Component
411411
public class MyClientHandlers {
412-
413-
@McpLogging(clientId = "my-server")
412+
413+
@McpLogging(clients = "my-server")
414414
public void handleLogs(LoggingMessageNotification notification) {
415415
// Handle logs
416416
}
417-
418-
@McpSampling(clientId = "my-server")
417+
418+
@McpSampling(clients = "my-server")
419419
public CreateMessageResult handleSampling(CreateMessageRequest request) {
420420
// Handle sampling
421421
}
422-
423-
@McpProgress(clientId = "my-server")
422+
423+
@McpProgress(clients = "my-server")
424424
public void handleProgress(ProgressNotification notification) {
425425
// Handle progress
426426
}
@@ -448,23 +448,23 @@ spring:
448448
type: SYNC # or ASYNC
449449
annotation-scanner:
450450
enabled: true
451-
# Configure client connections - the connection names become clientId values
451+
# Configure client connections - the connection names become clients values
452452
sse:
453453
connections:
454-
my-server: # This becomes the clientId
454+
my-server: # This becomes the clients
455455
url: http://localhost:8080
456-
tool-server: # Another clientId
456+
tool-server: # Another clients
457457
url: http://localhost:8081
458458
stdio:
459459
connections:
460-
local-server: # This becomes the clientId
460+
local-server: # This becomes the clients
461461
command: /path/to/mcp-server
462462
args:
463463
- --mode=production
464464
----
465465

466466
[IMPORTANT]
467-
The `clientId` parameter in annotations must match the connection names defined in your configuration. In the example above, valid `clientId` values would be: `"my-server"`, `"tool-server"`, and `"local-server"`.
467+
The `clients` parameter in annotations must match the connection names defined in your configuration. In the example above, valid `clients` values would be: `"my-server"`, `"tool-server"`, and `"local-server"`.
468468

469469
== Usage with MCP Client
470470

@@ -475,11 +475,11 @@ The annotated handlers are automatically integrated with the MCP client:
475475
@Autowired
476476
private List<McpSyncClient> mcpClients;
477477
478-
// The clients will automatically use your annotated handlers based on clientId
478+
// The clients will automatically use your annotated handlers based on clients
479479
// No manual registration needed - handlers are matched to clients by name
480480
----
481481

482-
For each MCP client connection, handlers with matching `clientId` will be automatically registered and invoked when the corresponding events occur.
482+
For each MCP client connection, handlers with matching `clients` will be automatically registered and invoked when the corresponding events occur.
483483

484484
== Additional Resources
485485

0 commit comments

Comments
 (0)