Merge pull request #495 from koic/subscriptions_listen

Serve the `subscriptions/listen` notification stream per SEP-2575
This commit is contained in:
Koichi ITO 2026-08-13 23:05:35 +09:00 • committed by GitHub
commit ebed930927
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -941,7 +941,7 @@ module MCP
def discover(_request)
{
supportedVersions: Configuration::SUPPORTED_MODERN_PROTOCOL_VERSIONS,
capabilities: capabilities,
capabilities: discover_capabilities,
instructions: instructions,
_meta: { RequestEnvelope::SERVER_INFO_META_KEY => server_info },
}.compact.merge(
@ -953,6 +953,21 @@ module MCP
)
end
# Capabilities as advertised by `server/discover`. In the modern lifecycle, `listChanged` and `subscribe` flags
# promise delivery over `subscriptions/listen` streams, so they are stripped when the transport does not serve that RPC
# (e.g. stdio), matching the Python SDK's era-aware capability derivation.
def discover_capabilities
return capabilities if @transport.respond_to?(:serves_subscriptions_listen?) && @transport.serves_subscriptions_listen?
capabilities.each_with_object({}) do |(name, value), stripped|
stripped[name] = if value.is_a?(Hash)
value.reject { |flag, _| ["listChanged", "subscribe"].include?(flag.to_s) }
else
value
end
end
end
def configure_logging_level(request, session: nil)
if capabilities[:logging].nil?
raise RequestHandlerError.new("Server does not support logging", request, error_type: :internal_error)