Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ configuration = MCP::Configuration.new(protocol_version: "2024-11-05")
MCP::Server.new(name: "test_server", configuration: configuration)
```

If no protocol version is specified, the [Draft version](https://modelcontextprotocol.io/specification/draft) will be applied by default.
If no protocol version is specified, the latest stable version will be applied by default.
The latest stable version includes new features from the [draft version](https://modelcontextprotocol.io/specification/draft).

This will make all new server instances use the specified protocol version instead of the default version. The protocol version can be reset to the default by setting it to `nil`:

Expand Down
8 changes: 3 additions & 5 deletions lib/mcp/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

module MCP
class Configuration
# DRAFT-2025-v3 is the latest draft protocol version:
# https://github.com/modelcontextprotocol/modelcontextprotocol/blob/14ec41c/schema/draft/schema.ts#L15
DRAFT_PROTOCOL_VERSION = "DRAFT-2025-v3"
SUPPORTED_STABLE_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"]
LATEST_STABLE_PROTOCOL_VERSION = "2025-06-18"
SUPPORTED_STABLE_PROTOCOL_VERSIONS = [LATEST_STABLE_PROTOCOL_VERSION, "2025-03-26", "2024-11-05"]

attr_writer :exception_reporter, :instrumentation_callback

Expand Down Expand Up @@ -35,7 +33,7 @@ def validate_tool_call_arguments=(validate_tool_call_arguments)
end

def protocol_version
@protocol_version || DRAFT_PROTOCOL_VERSION
@protocol_version || LATEST_STABLE_PROTOCOL_VERSION
end

def protocol_version?
Expand Down
9 changes: 5 additions & 4 deletions test/mcp/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ class ConfigurationTest < ActiveSupport::TestCase
# https://github.com/modelcontextprotocol/modelcontextprotocol/blob/14ec41c/schema/draft/schema.ts#L15
test "initializes with default protocol version" do
config = Configuration.new
assert_equal Configuration::DRAFT_PROTOCOL_VERSION, config.protocol_version
assert_equal Configuration::LATEST_STABLE_PROTOCOL_VERSION, config.protocol_version
end

test "uses the draft protocol version when protocol_version is set to nil" do
config = Configuration.new(protocol_version: nil)
assert_equal Configuration::DRAFT_PROTOCOL_VERSION, config.protocol_version
assert_equal Configuration::LATEST_STABLE_PROTOCOL_VERSION, config.protocol_version
end

test "raises ArgumentError when setting the draft protocol version" do
exception = assert_raises(ArgumentError) do
# To use the draft version externally, either omit `protocol_version` or set it to nil.
Configuration.new(protocol_version: Configuration::DRAFT_PROTOCOL_VERSION)
# DRAFT-2025-v3 is the latest draft protocol version:
# https://github.com/modelcontextprotocol/modelcontextprotocol/blob/14ec41c/schema/draft/schema.ts#L15
Configuration.new(protocol_version: "DRAFT-2025-v3")
end

assert_equal("protocol_version must be 2025-06-18, 2025-03-26, or 2024-11-05", exception.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class StreamableHTTPTransportTest < ActiveSupport::TestCase
body = JSON.parse(response[2][0])
assert_equal "2.0", body["jsonrpc"]
assert_equal "123", body["id"]
assert_equal Configuration::DRAFT_PROTOCOL_VERSION, body["result"]["protocolVersion"]
assert_equal Configuration::LATEST_STABLE_PROTOCOL_VERSION, body["result"]["protocolVersion"]
end

test "handles GET request with valid session ID" do
Expand Down
4 changes: 2 additions & 2 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ServerTest < ActiveSupport::TestCase
jsonrpc: "2.0",
id: 1,
result: {
protocolVersion: Configuration::DRAFT_PROTOCOL_VERSION,
protocolVersion: Configuration::LATEST_STABLE_PROTOCOL_VERSION,
capabilities: {
prompts: { listChanged: true },
resources: { listChanged: true },
Expand Down Expand Up @@ -776,7 +776,7 @@ def call(message:, server_context: nil)
}

response = @server.handle(request)
assert_equal Configuration::DRAFT_PROTOCOL_VERSION, response[:result][:protocolVersion]
assert_equal Configuration::LATEST_STABLE_PROTOCOL_VERSION, response[:result][:protocolVersion]
end

test "server response does not include title when not configured" do
Expand Down