diff --git a/changes.md b/changes.md index f6357e248a..1669d7f46b 100644 --- a/changes.md +++ b/changes.md @@ -58,6 +58,12 @@ Changes log bracketed and without zone, other hosts must be ASCII host names, and user information and percent-encoding are refused. - Enhancements + - `McpServerAdapter.setResourceSubscriptions(boolean)` lets an application that never + broadcasts resource updates stop advertising `capabilities.resources.subscribe` in + `server/discover`, so that no client waits for `notifications/resources/updated` that + never come; a `subscriptions/listen` asking for resource updates is then answered as for + any field the server doesn't honour. It is `true` by default, so nothing changes for + existing applications (#1751). - `McpClientAdapter.setCallCustomizer(BiConsumer)` gives the customizer of a 2026-07-28 request over HTTP the Reactor context its call was subscribed with, so a client passes per-call state, such as a credential computed from the call's parameters, diff --git a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpServerAdapter.java b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpServerAdapter.java index c2c61b97e0..c80e94ccb4 100644 --- a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpServerAdapter.java +++ b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpServerAdapter.java @@ -96,6 +96,7 @@ public final class McpServerAdapter extends Restlet { private final List callScopes = new CopyOnWriteArrayList<>(); private final Map> extensions = new ConcurrentHashMap<>(); private McpTaskStore taskStore; + private boolean resourceSubscriptions = true; private final McpCoalescingFeed changes = new McpCoalescingFeed(this::publishable); private final List subscriptions = new CopyOnWriteArrayList<>(); private SubscriptionRestriction subscriptionRestriction; @@ -260,6 +261,28 @@ public McpChangeBroadcaster getChanges() { return changes; } + /** + * Sets whether the adapter advertises resource subscriptions: {@code + * capabilities.resources.subscribe} in {@code server/discover}, and {@code + * notifications/resources/updated} on {@code subscriptions/listen} streams. It is {@code true} + * by default, which suits an application broadcasting resource updates through {@link + * #getChanges()}. An application never doing so should turn it off, so that no client waits for + * updates that never come: {@code resources} is then advertised without {@code subscribe}, and + * a {@code subscriptions/listen} asking for resource updates is answered as for any field the + * server doesn't honour. The legacy {@link McpProtocol#LEGACY_VERSIONS} edge never serves + * {@code resources/subscribe}, and advertises none either way. Experimental. + * + * @param value True to serve resource subscriptions. + */ + public synchronized void setResourceSubscriptions(boolean value) { + requireConfigurable(); + resourceSubscriptions = value; + } + + public synchronized boolean isResourceSubscriptions() { + return resourceSubscriptions; + } + /** * The change to broadcast: a notification with its params converted by the JSON mapper once, at * broadcast, so that the SDK converting them again per stream can't fail and silently drop it @@ -585,6 +608,7 @@ private io.modelcontextprotocol.modern.server.McpServer modernServer( List.copyOf(prompts), List.copyOf(toolFilters), taskStore != null, + resourceSubscriptions, Map.copyOf(cacheHints)))) .features(McpExtensionFeatures.of(runningMethods, runningExtensions)) .features(McpExtensionFeatures.subscriptions(List.copyOf(subscriptions))) diff --git a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernFeatures.java b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernFeatures.java index baf3031d2e..e28a89f8f9 100644 --- a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernFeatures.java +++ b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernFeatures.java @@ -62,6 +62,7 @@ private McpModernFeatures() {} * @param prompts The prompts. * @param toolFilters The tool list filters. * @param tasks Whether the adapter serves {@code tasks/*}. + * @param resourceSubscriptions Whether the adapter serves resource subscriptions. * @param cacheHints The cache hints of the listings, by method. */ public record Registrations( @@ -71,6 +72,7 @@ public record Registrations( List prompts, List toolFilters, boolean tasks, + boolean resourceSubscriptions, Map cacheHints) { /** The hint of a listing, none by default. */ @@ -220,7 +222,8 @@ private record Template( /** * The resources: exact URIs first, then templates, in registration order. Subscriptions are - * supported: the adapter publishes resource updates through its change feed. + * supported unless the application turned them off: the adapter publishes resource updates + * through its change feed. */ private static final class Resources implements McpAsyncResourceRepository { private final List listed = new ArrayList<>(); @@ -228,8 +231,10 @@ private static final class Resources implements McpAsyncResourceRepository { private final List