Skip to content

Commit 87a8653

Browse files
committed
Test README protocol version examples
This revealed that the `protocol_version` accessors weren't available on the `Server` at all.
1 parent 825594a commit 87a8653

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@ config.instrumentation_callback = ->(data) {
242242

243243
The server's protocol version can be overridden using the `protocol_version` class method:
244244

245+
<!-- SNIPPET ID: set_server_protocol_version -->
245246
```ruby
246247
MCP::Server.protocol_version = "2024-11-05"
247248
```
248249

249250
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`:
250251

252+
<!-- SNIPPET ID: unset_server_protocol_version -->
251253
```ruby
252254
MCP::Server.protocol_version = nil
253255
```

lib/mcp/server.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ module MCP
99
class Server
1010
DEFAULT_VERSION = "0.1.0"
1111

12+
class << self
13+
def protocol_version = MCP.configuration.protocol_version
14+
15+
def protocol_version=(version)
16+
MCP.configuration.protocol_version = version
17+
end
18+
end
19+
1220
class RequestHandlerError < StandardError
1321
attr_reader :error_type
1422
attr_reader :original_error
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require "mcp"
4+
5+
require_relative "code_snippet"
6+
7+
puts MCP::Server.protocol_version
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set_server_protocol_version.rb

test/integration/readme_code_snippets_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class ReadmeCodeSnippetsTest < ActiveSupport::TestCase
132132
STDOUT
133133
end
134134

135+
test "Protocol Version example works exactly as documented in README" do
136+
assert_equal("2024-11-05", run_code_snippet("set_server_protocol_version").chomp)
137+
assert_equal(MCP::Configuration::DEFAULT_PROTOCOL_VERSION, run_code_snippet("unset_server_protocol_version").chomp)
138+
end
139+
135140
private
136141

137142
def assert_json_lines(expected, actual, message = "Expected the given JSON lines")

0 commit comments

Comments
 (0)