Document resource subscription support in server and client guides (#843)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov 2026-03-03 10:45:04 +01:00 • committed by GitHub
commit 26304a7a39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,7 +33,7 @@ The server supports both synchronous and asynchronous APIs, allowing for flexibl
McpSyncServer syncServer = McpServer.sync(transportProvider)
.serverInfo("my-server", "1.0.0")
.capabilities(ServerCapabilities.builder()
.resources(false, true) // Enable resource support with list changes
.resources(false, true) // Resource support: subscribe=false, listChanged=true
.tools(true) // Enable tool support with list changes
.prompts(true) // Enable prompt support with list changes
.completions() // Enable completions support
@ -57,7 +57,7 @@ The server supports both synchronous and asynchronous APIs, allowing for flexibl
McpAsyncServer asyncServer = McpServer.async(transportProvider)
.serverInfo("my-server", "1.0.0")
.capabilities(ServerCapabilities.builder()
.resources(false, true) // Enable resource support with list changes
.resources(false, true) // Resource support: subscribe=false, listChanged=true
.tools(true) // Enable tool support with list changes
.prompts(true) // Enable prompt support with list changes
.completions() // Enable completions support
@ -319,7 +319,7 @@ The server can be configured with various capabilities:
```java
var capabilities = ServerCapabilities.builder()
.resources(false, true) // Resource support (subscribe, listChanged)
.resources(true, true) // Resource support: subscribe=true, listChanged=true
.tools(true) // Tool support with list changes notifications
.prompts(true) // Prompt support with list changes notifications
.completions() // Enable completions support
@ -438,6 +438,42 @@ Resources provide context to AI models by exposing data such as: File contents,
);
```
### Resource Subscriptions
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.
Enable subscription support in the server capabilities:
```java
McpSyncServer server = McpServer.sync(transportProvider)
.serverInfo("my-server", "1.0.0")
.capabilities(ServerCapabilities.builder()
.resources(true, false) // subscribe=true, listChanged=false
.build())
.resources(myResourceSpec)
.build();
```
When a subscribed resource changes, notify only the interested sessions:
=== "Sync"
```java
server.notifyResourcesUpdated(
new McpSchema.ResourcesUpdatedNotification("custom://resource")
);
```
=== "Async"
```java
server.notifyResourcesUpdated(
new McpSchema.ResourcesUpdatedNotification("custom://resource")
).subscribe();
```
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.
### Resource Template Specification
Resource templates allow servers to expose parameterized resources using URI templates: