Merge pull request #438 from koic/server_discover
Add `server/discover` and stateless lifecycle error codes per SEP-2575
This commit is contained in:
commit
61233ed43b
1 changed files with 149 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue