Merge pull request #438 from koic/server_discover

Add `server/discover` and stateless lifecycle error codes per SEP-2575
This commit is contained in:
Koichi ITO 2026-07-10 00:26:49 +09:00 • committed by GitHub
commit 61233ed43b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -461,7 +461,9 @@ module MCP
# The `MCP-Protocol-Version` header is only meaningful after negotiation, so on `initialize`
# the JSON-RPC body `params.protocolVersion` is authoritative and the header (if any) is ignored.
# This matches the TypeScript and Python SDKs.
unless initialize_request?(body)
# `server/discover` (SEP-2575) is likewise exempt: it is sessionless capability discovery that
# happens before (or instead of) negotiation.
unless initialize_request?(body) || discover_request?(body)
return missing_session_id_response if !@stateless && !session_id
protocol_version_error = validate_protocol_version_header(request)
@ -712,6 +714,10 @@ module MCP
body.is_a?(Hash) && body[:method] == Methods::INITIALIZE
end
def discover_request?(body)
body.is_a?(Hash) && body[:method] == Methods::SERVER_DISCOVER
end
def validate_protocol_version_header(request)
header_value = request.env["HTTP_MCP_PROTOCOL_VERSION"] || MCP::Configuration::DEFAULT_NEGOTIATED_PROTOCOL_VERSION
return if MCP::Configuration::SUPPORTED_STABLE_PROTOCOL_VERSIONS.include?(header_value)