## Motivation and Context Clients that require MCP 2026-07-28, such as ChatGPT, reject connections because the SDK does not advertise that version: `Server#init` answers a 2026-07-28 request with 2025-11-25, the Streamable HTTP transport 400s an `MCP-Protocol-Version: 2026-07-28` header, and `server/discover` omits the version from `supportedVersions`. Making 2026-07-28 the latest entry in `SUPPORTED_STABLE_PROTOCOL_VERSIONS` fixes all three at once, since they all read that list. The version now serves both lifecycles of the SEP-2575 dual-era model: negotiable through the legacy `initialize` handshake, and simultaneously the version of the per-request modern lifecycle. Parts of the 2026-07-28 feature set remain unimplemented, such as the stateless modern lifecycle over the transports, and are being built separately. This change deliberately limits itself to the version bump, focusing first on eliminating the connection errors that 2026-07-28 clients hit. Known follow-up: the in-progress modern HTTP path routes requests to the sessionless modern lifecycle when the header version is absent from `SUPPORTED_STABLE_PROTOCOL_VERSIONS`, so that routing predicate needs rework on top of this change. Closes #474 ## How Has This Been Tested? New regression tests: `initialize` with `protocolVersion: "2026-07-28"` echoes it back (`server_test.rb`), a follow-up POST with `MCP-Protocol-Version: 2026-07-28` passes header validation (`streamable_http_transport_test.rb`), and `Configuration.new(protocol_version: "2026-07-28")` is accepted (`configuration_test.rb`). `bundle exec rake test` passes (1454 runs, 0 failures). The conformance server suite passes 30/30. The client `initialize` scenario is added to the expected-failures baseline: the conformance framework pins the client's requested version to 2025-11-25 and does not accept 2026-07-28 yet; the entry carries a TODO to remove it when the framework catches up. ## Breaking Changes Servers that do not pin `configuration.protocol_version` now answer version negotiation fallbacks and default client requests with 2026-07-28 instead of 2025-11-25. 2025-11-25 remains fully supported and negotiable; clients that request it are unaffected.
191 lines
6.4 KiB
Ruby
191 lines
6.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module MCP
|
|
class Configuration
|
|
LATEST_STABLE_PROTOCOL_VERSION = "2026-07-28"
|
|
SUPPORTED_STABLE_PROTOCOL_VERSIONS = [
|
|
LATEST_STABLE_PROTOCOL_VERSION, "2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05",
|
|
].freeze
|
|
DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26"
|
|
|
|
# Protocol versions of the stateless "modern" lifecycle introduced by the MCP 2026-07-28 spec release (SEP-2575).
|
|
# 2026-07-28 serves both lifecycles of the dual-era model: it is negotiable through the legacy `initialize`
|
|
# handshake (so it also appears in `SUPPORTED_STABLE_PROTOCOL_VERSIONS`), and it is the version of the modern
|
|
# lifecycle, where each request carries its own version in `_meta` and is validated against this list
|
|
# independently, with no handshake.
|
|
# https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2575
|
|
LATEST_MODERN_PROTOCOL_VERSION = "2026-07-28"
|
|
SUPPORTED_MODERN_PROTOCOL_VERSIONS = [LATEST_MODERN_PROTOCOL_VERSION].freeze
|
|
|
|
class << self
|
|
def modern_protocol_version?(version)
|
|
SUPPORTED_MODERN_PROTOCOL_VERSIONS.include?(version)
|
|
end
|
|
end
|
|
|
|
attr_writer :exception_reporter, :around_request
|
|
|
|
# @deprecated Use {#around_request=} instead. `instrumentation_callback`
|
|
# fires only after a request completes and cannot wrap execution in a
|
|
# surrounding block (e.g. for Application Performance Monitoring (APM) spans).
|
|
# @see #around_request=
|
|
attr_writer :instrumentation_callback
|
|
|
|
def initialize(exception_reporter: nil, around_request: nil, instrumentation_callback: nil, protocol_version: nil,
|
|
validate_tool_call_arguments: true, validate_tool_call_results: false)
|
|
@exception_reporter = exception_reporter
|
|
@around_request = around_request
|
|
@instrumentation_callback = instrumentation_callback
|
|
@protocol_version = protocol_version
|
|
if protocol_version
|
|
validate_protocol_version!(protocol_version)
|
|
end
|
|
validate_value_of_validate_tool_call_arguments!(validate_tool_call_arguments)
|
|
validate_value_of_validate_tool_call_results!(validate_tool_call_results)
|
|
|
|
@validate_tool_call_arguments = validate_tool_call_arguments
|
|
@validate_tool_call_results = validate_tool_call_results
|
|
end
|
|
|
|
def protocol_version=(protocol_version)
|
|
validate_protocol_version!(protocol_version)
|
|
|
|
@protocol_version = protocol_version
|
|
end
|
|
|
|
def validate_tool_call_arguments=(validate_tool_call_arguments)
|
|
validate_value_of_validate_tool_call_arguments!(validate_tool_call_arguments)
|
|
|
|
@validate_tool_call_arguments = validate_tool_call_arguments
|
|
end
|
|
|
|
def validate_tool_call_results=(validate_tool_call_results)
|
|
validate_value_of_validate_tool_call_results!(validate_tool_call_results)
|
|
|
|
@validate_tool_call_results = validate_tool_call_results
|
|
end
|
|
|
|
def protocol_version
|
|
@protocol_version || LATEST_STABLE_PROTOCOL_VERSION
|
|
end
|
|
|
|
def protocol_version?
|
|
!@protocol_version.nil?
|
|
end
|
|
|
|
def exception_reporter
|
|
@exception_reporter || default_exception_reporter
|
|
end
|
|
|
|
def exception_reporter?
|
|
!@exception_reporter.nil?
|
|
end
|
|
|
|
def around_request
|
|
@around_request || default_around_request
|
|
end
|
|
|
|
def around_request?
|
|
!@around_request.nil?
|
|
end
|
|
|
|
# @deprecated Use {#around_request} instead. `instrumentation_callback`
|
|
# fires only after a request completes and cannot wrap execution in a
|
|
# surrounding block (e.g. for Application Performance Monitoring (APM) spans).
|
|
# @see #around_request
|
|
def instrumentation_callback
|
|
@instrumentation_callback || default_instrumentation_callback
|
|
end
|
|
|
|
# @deprecated Use {#around_request?} instead.
|
|
# @see #around_request?
|
|
def instrumentation_callback?
|
|
!@instrumentation_callback.nil?
|
|
end
|
|
|
|
attr_reader :validate_tool_call_arguments
|
|
attr_reader :validate_tool_call_results
|
|
|
|
def validate_tool_call_arguments?
|
|
!!@validate_tool_call_arguments
|
|
end
|
|
|
|
def validate_tool_call_results?
|
|
!!@validate_tool_call_results
|
|
end
|
|
|
|
def merge(other)
|
|
return self if other.nil?
|
|
|
|
exception_reporter = if other.exception_reporter?
|
|
other.exception_reporter
|
|
else
|
|
@exception_reporter
|
|
end
|
|
|
|
around_request = if other.around_request?
|
|
other.around_request
|
|
else
|
|
@around_request
|
|
end
|
|
|
|
instrumentation_callback = if other.instrumentation_callback?
|
|
other.instrumentation_callback
|
|
else
|
|
@instrumentation_callback
|
|
end
|
|
|
|
protocol_version = if other.protocol_version?
|
|
other.protocol_version
|
|
else
|
|
@protocol_version
|
|
end
|
|
|
|
validate_tool_call_arguments = other.validate_tool_call_arguments
|
|
validate_tool_call_results = other.validate_tool_call_results
|
|
|
|
Configuration.new(
|
|
exception_reporter: exception_reporter,
|
|
around_request: around_request,
|
|
instrumentation_callback: instrumentation_callback,
|
|
protocol_version: protocol_version,
|
|
validate_tool_call_arguments: validate_tool_call_arguments,
|
|
validate_tool_call_results: validate_tool_call_results,
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def validate_protocol_version!(protocol_version)
|
|
unless SUPPORTED_STABLE_PROTOCOL_VERSIONS.include?(protocol_version)
|
|
message = "protocol_version must be #{SUPPORTED_STABLE_PROTOCOL_VERSIONS[0...-1].join(", ")}, or #{SUPPORTED_STABLE_PROTOCOL_VERSIONS[-1]}"
|
|
raise ArgumentError, message
|
|
end
|
|
end
|
|
|
|
def validate_value_of_validate_tool_call_arguments!(validate_tool_call_arguments)
|
|
unless validate_tool_call_arguments.is_a?(TrueClass) || validate_tool_call_arguments.is_a?(FalseClass)
|
|
raise ArgumentError, "validate_tool_call_arguments must be a boolean"
|
|
end
|
|
end
|
|
|
|
def validate_value_of_validate_tool_call_results!(validate_tool_call_results)
|
|
unless validate_tool_call_results.is_a?(TrueClass) || validate_tool_call_results.is_a?(FalseClass)
|
|
raise ArgumentError, "validate_tool_call_results must be a boolean"
|
|
end
|
|
end
|
|
|
|
def default_exception_reporter
|
|
@default_exception_reporter ||= ->(exception, server_context) {}
|
|
end
|
|
|
|
def default_around_request
|
|
@default_around_request ||= ->(_data, &request_handler) { request_handler.call }
|
|
end
|
|
|
|
# @deprecated Use {#default_around_request} instead.
|
|
def default_instrumentation_callback
|
|
@default_instrumentation_callback ||= ->(data) {}
|
|
end
|
|
end
|
|
end
|