Skip to content

Commit 00e1ed8

Browse files
Merge branch 'main' into auto-determine-capabilities
2 parents 0f33dc0 + e89af18 commit 00e1ed8

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module ModelContextProtocol
5050
def index
5151
server = ModelContextProtocol::Server.new(
5252
name: "my_server",
53+
version: "1.0.0",
5354
tools: [SomeTool, AnotherTool],
5455
prompts: [MyPrompt],
5556
server_context: { user_id: current_user.id },

examples/stdio_server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def template(args, server_context:)
5454
# Set up the server
5555
server = MCP::Server.new(
5656
name: "example_server",
57+
version: "1.0.0",
5758
tools: [ExampleTool],
5859
prompts: [ExamplePrompt],
5960
resources: [

lib/model_context_protocol/server.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
module ModelContextProtocol
88
class Server
9+
DEFAULT_VERSION = "0.1.0"
10+
911
class RequestHandlerError < StandardError
1012
attr_reader :error_type
1113
attr_reader :original_error
@@ -20,11 +22,13 @@ def initialize(message, request, error_type: :internal_error, original_error: ni
2022

2123
include Instrumentation
2224

25+
2326
attr_writer :capabilities
24-
attr_accessor :name, :tools, :prompts, :resources, :server_context, :configuration
27+
attr_accessor :name, :version, :tools, :prompts, :resources, :server_context, :configuration
2528

2629
def initialize(
2730
name: "model_context_protocol",
31+
version: DEFAULT_VERSION,
2832
tools: [],
2933
prompts: [],
3034
resources: [],
@@ -34,6 +38,7 @@ def initialize(
3438
capabilities: nil
3539
)
3640
@name = name
41+
@version = version
3742
@tools = tools.to_h { |t| [t.name_value, t] }
3843
@prompts = prompts.to_h { |p| [p.name_value, p] }
3944
@resources = resources
@@ -169,7 +174,7 @@ def determine_capabilities
169174
def server_info
170175
@server_info ||= {
171176
name:,
172-
version: ModelContextProtocol::VERSION,
177+
version:,
173178
}
174179
end
175180

lib/model_context_protocol/transports/stdio.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class StdioTransport < Transport
99
def initialize(server)
1010
@server = server
1111
@open = false
12+
$stdin.set_encoding("UTF-8")
13+
$stdout.set_encoding("UTF-8")
1214
super
1315
end
1416

test/model_context_protocol/server_test.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ServerTest < ActiveSupport::TestCase
5151

5252
@server = Server.new(
5353
name: @server_name,
54+
version: "1.2.3",
5455
tools: [@tool, @tool_that_raises],
5556
prompts: [@prompt],
5657
resources: [@resource],
@@ -120,7 +121,7 @@ class ServerTest < ActiveSupport::TestCase
120121
},
121122
"serverInfo": {
122123
"name": @server_name,
123-
"version": ModelContextProtocol::VERSION,
124+
"version": "1.2.3",
124125
},
125126
},
126127
}
@@ -648,6 +649,18 @@ class ServerTest < ActiveSupport::TestCase
648649
assert_equal Configuration::DEFAULT_PROTOCOL_VERSION, response[:result][:protocolVersion]
649650
end
650651

652+
test "server uses default version when not configured" do
653+
server = Server.new(name: "test_server")
654+
request = {
655+
jsonrpc: "2.0",
656+
method: "initialize",
657+
id: 1,
658+
}
659+
660+
response = server.handle(request)
661+
assert_equal Server::DEFAULT_VERSION, response[:result][:serverInfo][:version]
662+
end
663+
651664
test "#define_tool adds a tool to the server" do
652665
@server.define_tool(
653666
name: "defined_tool",

0 commit comments

Comments
 (0)