Currently, MCP has three versions: 2024-11-05, 2025-03-26, and 2025-06-18. - https://modelcontextprotocol.io/specification/2024-11-05/basic/transports (stdio and HTTP with SSE) - https://modelcontextprotocol.io/specification/2025-03-26/basic/transports (stdio and Streamable HTTP) - https://modelcontextprotocol.io/specification/2025-06-18/basic/transports (stdio and Streamable HTTP) The newer specification supports stdio and Streamable HTTP as transport mechanisms. Only the oldest version, 2024-11-05, supports stdin and HTTP with SSE, but that version is now considered legacy. Given the current behavior of the Ruby SDK, it likely makes more sense to set the default protocol version to the latest one, 2025-06-18, rather than the oldest, 2024-11-05. Ideally, the implementation should adjust its behavior based on the version, but this PR is limited to updating the default protocol version only.
94 lines
2.7 KiB
Ruby
94 lines
2.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module MCP
|
|
class Configuration
|
|
DEFAULT_PROTOCOL_VERSION = "2025-06-18"
|
|
SUPPORTED_PROTOCOL_VERSIONS = [DEFAULT_PROTOCOL_VERSION, "2025-03-26", "2024-11-05"]
|
|
|
|
attr_writer :exception_reporter, :instrumentation_callback, :protocol_version, :validate_tool_call_arguments
|
|
|
|
def initialize(exception_reporter: nil, instrumentation_callback: nil, protocol_version: nil,
|
|
validate_tool_call_arguments: true)
|
|
@exception_reporter = exception_reporter
|
|
@instrumentation_callback = instrumentation_callback
|
|
@protocol_version = protocol_version
|
|
if protocol_version && !SUPPORTED_PROTOCOL_VERSIONS.include?(protocol_version)
|
|
message = "protocol_version must be #{SUPPORTED_PROTOCOL_VERSIONS[0...-1].join(", ")}, or #{SUPPORTED_PROTOCOL_VERSIONS[-1]}"
|
|
raise ArgumentError, message
|
|
end
|
|
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
|
|
|
|
@validate_tool_call_arguments = validate_tool_call_arguments
|
|
end
|
|
|
|
def protocol_version
|
|
@protocol_version || DEFAULT_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 instrumentation_callback
|
|
@instrumentation_callback || default_instrumentation_callback
|
|
end
|
|
|
|
def instrumentation_callback?
|
|
!@instrumentation_callback.nil?
|
|
end
|
|
|
|
attr_reader :validate_tool_call_arguments
|
|
|
|
def validate_tool_call_arguments?
|
|
!!@validate_tool_call_arguments
|
|
end
|
|
|
|
def merge(other)
|
|
return self if other.nil?
|
|
|
|
exception_reporter = if other.exception_reporter?
|
|
other.exception_reporter
|
|
else
|
|
@exception_reporter
|
|
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
|
|
|
|
Configuration.new(
|
|
exception_reporter:,
|
|
instrumentation_callback:,
|
|
protocol_version:,
|
|
validate_tool_call_arguments:,
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def default_exception_reporter
|
|
@default_exception_reporter ||= ->(exception, server_context) {}
|
|
end
|
|
|
|
def default_instrumentation_callback
|
|
@default_instrumentation_callback ||= ->(data) {}
|
|
end
|
|
end
|
|
end
|