You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/client.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -408,6 +408,49 @@ Resources represent server-side data sources that clients can access using URI t
408
408
.subscribe();
409
409
```
410
410
411
+
### Resource Subscriptions
412
+
413
+
When the server advertises `resources.subscribe` support, clients can subscribe to individual resources and receive a callback whenever the server pushes a `notifications/resources/updated` notification for that URI. The SDK automatically re-reads the resource on notification and delivers the updated contents to the registered consumer.
414
+
415
+
Register a consumer on the client builder, then subscribe/unsubscribe at any time:
416
+
417
+
=== "Sync API"
418
+
419
+
```java
420
+
McpSyncClient client = McpClient.sync(transport)
421
+
.resourcesUpdateConsumer(contents -> {
422
+
// called with the updated resource contents after each notification
The prompt system enables interaction with server-side prompt templates. These templates can be discovered and executed with custom parameters, allowing for dynamic text generation based on predefined patterns.
.tools(true) // Tool support with list changes notifications
324
324
.prompts(true) // Prompt support with list changes notifications
325
325
.completions() // Enable completions support
@@ -438,6 +438,42 @@ Resources provide context to AI models by exposing data such as: File contents,
438
438
);
439
439
```
440
440
441
+
### Resource Subscriptions
442
+
443
+
When the `subscribe` capability is enabled, clients can subscribe to specific resources and receive targeted `notifications/resources/updated` notifications when those resources change. Only sessions that have explicitly subscribed to a given URI receive the notification — not every connected client.
444
+
445
+
Enable subscription support in the server capabilities:
446
+
447
+
```java
448
+
McpSyncServer server =McpServer.sync(transportProvider)
When a subscribed resource changes, notify only the interested sessions:
458
+
459
+
=== "Sync"
460
+
461
+
```java
462
+
server.notifyResourcesUpdated(
463
+
new McpSchema.ResourcesUpdatedNotification("custom://resource")
464
+
);
465
+
```
466
+
467
+
=== "Async"
468
+
469
+
```java
470
+
server.notifyResourcesUpdated(
471
+
new McpSchema.ResourcesUpdatedNotification("custom://resource")
472
+
).subscribe();
473
+
```
474
+
475
+
If no sessions are subscribed to the given URI the call completes immediately without sending any messages. Subscription state is automatically cleaned up when a client session closes.
476
+
441
477
### Resource Template Specification
442
478
443
479
Resource templates allow servers to expose parameterized resources using URI templates:
0 commit comments