model-context-protocol-rb 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -2
- data/README.md +172 -34
- data/lib/model_context_protocol/server/completion.rb +6 -0
- data/lib/model_context_protocol/server/configuration.rb +94 -2
- data/lib/model_context_protocol/server/mcp_logger.rb +109 -0
- data/lib/model_context_protocol/server/prompt.rb +21 -19
- data/lib/model_context_protocol/server/resource.rb +6 -4
- data/lib/model_context_protocol/server/session_store.rb +108 -0
- data/lib/model_context_protocol/server/stdio_transport.rb +26 -11
- data/lib/model_context_protocol/server/streamable_http_transport.rb +291 -0
- data/lib/model_context_protocol/server/tool.rb +10 -8
- data/lib/model_context_protocol/server.rb +45 -6
- data/lib/model_context_protocol/version.rb +1 -3
- data/tasks/templates/dev.erb +10 -1
- metadata +5 -2
@@ -19,13 +19,25 @@ module ModelContextProtocol
|
|
19
19
|
|
20
20
|
def start
|
21
21
|
configuration.validate!
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
transport = case configuration.transport_type
|
24
|
+
when :stdio, nil
|
25
|
+
StdioTransport.new(router: @router, configuration: @configuration)
|
26
|
+
when :streamable_http
|
27
|
+
StreamableHttpTransport.new(
|
28
|
+
router: @router,
|
29
|
+
configuration: @configuration
|
30
|
+
)
|
31
|
+
else
|
32
|
+
raise ArgumentError, "Unknown transport: #{configuration.transport_type}"
|
33
|
+
end
|
34
|
+
|
35
|
+
transport.handle
|
24
36
|
end
|
25
37
|
|
26
38
|
private
|
27
39
|
|
28
|
-
PROTOCOL_VERSION = "
|
40
|
+
PROTOCOL_VERSION = "2025-06-18".freeze
|
29
41
|
private_constant :PROTOCOL_VERSION
|
30
42
|
|
31
43
|
InitializeResponse = Data.define(:protocol_version, :capabilities, :server_info) do
|
@@ -44,6 +56,12 @@ module ModelContextProtocol
|
|
44
56
|
end
|
45
57
|
end
|
46
58
|
|
59
|
+
LoggingSetLevelResponse = Data.define do
|
60
|
+
def serialized
|
61
|
+
{}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
47
65
|
def map_handlers
|
48
66
|
router.map("initialize") do |_message|
|
49
67
|
InitializeResponse[
|
@@ -60,6 +78,17 @@ module ModelContextProtocol
|
|
60
78
|
PingResponse[]
|
61
79
|
end
|
62
80
|
|
81
|
+
router.map("logging/setLevel") do |message|
|
82
|
+
level = message["params"]["level"]
|
83
|
+
|
84
|
+
unless Configuration::VALID_LOG_LEVELS.include?(level)
|
85
|
+
raise ParameterValidationError, "Invalid log level: #{level}. Valid levels are: #{Configuration::VALID_LOG_LEVELS.join(", ")}"
|
86
|
+
end
|
87
|
+
|
88
|
+
configuration.logger.set_mcp_level(level)
|
89
|
+
LoggingSetLevelResponse[]
|
90
|
+
end
|
91
|
+
|
63
92
|
router.map("completion/complete") do |message|
|
64
93
|
type = message["params"]["ref"]["type"]
|
65
94
|
|
@@ -94,7 +123,7 @@ module ModelContextProtocol
|
|
94
123
|
raise ModelContextProtocol::Server::ParameterValidationError, "resource not found for #{uri}"
|
95
124
|
end
|
96
125
|
|
97
|
-
resource.call
|
126
|
+
resource.call(configuration.logger, configuration.context)
|
98
127
|
end
|
99
128
|
|
100
129
|
router.map("resources/templates/list") do |message|
|
@@ -106,7 +135,12 @@ module ModelContextProtocol
|
|
106
135
|
end
|
107
136
|
|
108
137
|
router.map("prompts/get") do |message|
|
109
|
-
|
138
|
+
arguments = message["params"]["arguments"]
|
139
|
+
symbolized_arguments = arguments.transform_keys(&:to_sym)
|
140
|
+
configuration
|
141
|
+
.registry
|
142
|
+
.find_prompt(message["params"]["name"])
|
143
|
+
.call(symbolized_arguments, configuration.logger, configuration.context)
|
110
144
|
end
|
111
145
|
|
112
146
|
router.map("tools/list") do
|
@@ -114,7 +148,12 @@ module ModelContextProtocol
|
|
114
148
|
end
|
115
149
|
|
116
150
|
router.map("tools/call") do |message|
|
117
|
-
|
151
|
+
arguments = message["params"]["arguments"]
|
152
|
+
symbolized_arguments = arguments.transform_keys(&:to_sym)
|
153
|
+
configuration
|
154
|
+
.registry
|
155
|
+
.find_tool(message["params"]["name"])
|
156
|
+
.call(symbolized_arguments, configuration.logger, configuration.context)
|
118
157
|
end
|
119
158
|
end
|
120
159
|
|
data/tasks/templates/dev.erb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env <%= @ruby_path %>
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
+
require "securerandom"
|
4
5
|
require_relative "../lib/model_context_protocol"
|
5
6
|
|
6
7
|
Dir[File.join(__dir__, "../spec/support/**/*.rb")].each { |file| require file }
|
@@ -8,7 +9,15 @@ Dir[File.join(__dir__, "../spec/support/**/*.rb")].each { |file| require file }
|
|
8
9
|
server = ModelContextProtocol::Server.new do |config|
|
9
10
|
config.name = "MCP Development Server"
|
10
11
|
config.version = "1.0.0"
|
11
|
-
config.
|
12
|
+
config.logging_enabled = true
|
13
|
+
|
14
|
+
config.set_environment_variable("MCP_ENV", "development")
|
15
|
+
|
16
|
+
config.context = {
|
17
|
+
user_id: "123456",
|
18
|
+
request_id: SecureRandom.uuid
|
19
|
+
}
|
20
|
+
|
12
21
|
config.registry = ModelContextProtocol::Server::Registry.new do
|
13
22
|
prompts list_changed: true do
|
14
23
|
register TestPrompt
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model-context-protocol-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dick Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -58,12 +58,15 @@ files:
|
|
58
58
|
- lib/model_context_protocol/server.rb
|
59
59
|
- lib/model_context_protocol/server/completion.rb
|
60
60
|
- lib/model_context_protocol/server/configuration.rb
|
61
|
+
- lib/model_context_protocol/server/mcp_logger.rb
|
61
62
|
- lib/model_context_protocol/server/prompt.rb
|
62
63
|
- lib/model_context_protocol/server/registry.rb
|
63
64
|
- lib/model_context_protocol/server/resource.rb
|
64
65
|
- lib/model_context_protocol/server/resource_template.rb
|
65
66
|
- lib/model_context_protocol/server/router.rb
|
67
|
+
- lib/model_context_protocol/server/session_store.rb
|
66
68
|
- lib/model_context_protocol/server/stdio_transport.rb
|
69
|
+
- lib/model_context_protocol/server/streamable_http_transport.rb
|
67
70
|
- lib/model_context_protocol/server/tool.rb
|
68
71
|
- lib/model_context_protocol/version.rb
|
69
72
|
- tasks/mcp.rake
|