mcp 0.9.0 → 0.9.2
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/lib/mcp/client.rb +11 -3
- data/lib/mcp/server/transports/streamable_http_transport.rb +20 -4
- data/lib/mcp/server.rb +4 -4
- data/lib/mcp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0f26c1a29af5a799a750d9ad00a224f39d24638a9ad267a540313f06da674ed
|
|
4
|
+
data.tar.gz: d340e2c1f6492f74a28c6dabc6a04575285269e13a2352e3f747195d4dac1527
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f428407e35305f1cb5a087bd7abb708df12d17abe6cb66f335c8dc2d82d1020407942dd36ad3cb200377e7d60783d87a72bab765b202ae8426cb267f5d3f46a
|
|
7
|
+
data.tar.gz: 49d835de35b9c6c124d99ffe82561a5f7554901d43971afbb82adfb31fe13d0d6d1b6782d460d9b861b6924cc43705266cb09e5de3afd9249b7caa68634fff63
|
data/lib/mcp/client.rb
CHANGED
|
@@ -92,12 +92,17 @@ module MCP
|
|
|
92
92
|
|
|
93
93
|
# Calls a tool via the transport layer and returns the full response from the server.
|
|
94
94
|
#
|
|
95
|
+
# @param name [String] The name of the tool to call.
|
|
95
96
|
# @param tool [MCP::Client::Tool] The tool to be called.
|
|
96
97
|
# @param arguments [Object, nil] The arguments to pass to the tool.
|
|
97
98
|
# @param progress_token [String, Integer, nil] A token to request progress notifications from the server during tool execution.
|
|
98
99
|
# @return [Hash] The full JSON-RPC response from the transport.
|
|
99
100
|
#
|
|
100
|
-
# @example
|
|
101
|
+
# @example Call by name
|
|
102
|
+
# response = client.call_tool(name: "my_tool", arguments: { foo: "bar" })
|
|
103
|
+
# content = response.dig("result", "content")
|
|
104
|
+
#
|
|
105
|
+
# @example Call with a tool object
|
|
101
106
|
# tool = client.tools.first
|
|
102
107
|
# response = client.call_tool(tool: tool, arguments: { foo: "bar" })
|
|
103
108
|
# structured_content = response.dig("result", "structuredContent")
|
|
@@ -105,8 +110,11 @@ module MCP
|
|
|
105
110
|
# @note
|
|
106
111
|
# The exact requirements for `arguments` are determined by the transport layer in use.
|
|
107
112
|
# Consult the documentation for your transport (e.g., MCP::Client::HTTP) for details.
|
|
108
|
-
def call_tool(tool
|
|
109
|
-
|
|
113
|
+
def call_tool(name: nil, tool: nil, arguments: nil, progress_token: nil)
|
|
114
|
+
tool_name = name || tool&.name
|
|
115
|
+
raise ArgumentError, "Either `name:` or `tool:` must be provided." unless tool_name
|
|
116
|
+
|
|
117
|
+
params = { name: tool_name, arguments: arguments }
|
|
110
118
|
if progress_token
|
|
111
119
|
params[:_meta] = { progressToken: progress_token }
|
|
112
120
|
end
|
|
@@ -142,6 +142,7 @@ module MCP
|
|
|
142
142
|
|
|
143
143
|
return missing_session_id_response unless session_id
|
|
144
144
|
return session_not_found_response unless session_exists?(session_id)
|
|
145
|
+
return session_already_connected_response if get_session_stream(session_id)
|
|
145
146
|
|
|
146
147
|
setup_sse_stream(session_id)
|
|
147
148
|
end
|
|
@@ -155,8 +156,10 @@ module MCP
|
|
|
155
156
|
end
|
|
156
157
|
|
|
157
158
|
return missing_session_id_response unless (session_id = request.env["HTTP_MCP_SESSION_ID"])
|
|
159
|
+
return session_not_found_response unless session_exists?(session_id)
|
|
158
160
|
|
|
159
161
|
cleanup_session(session_id)
|
|
162
|
+
|
|
160
163
|
success_response
|
|
161
164
|
end
|
|
162
165
|
|
|
@@ -303,6 +306,14 @@ module MCP
|
|
|
303
306
|
[404, { "Content-Type" => "application/json" }, [{ error: "Session not found" }.to_json]]
|
|
304
307
|
end
|
|
305
308
|
|
|
309
|
+
def session_already_connected_response
|
|
310
|
+
[
|
|
311
|
+
409,
|
|
312
|
+
{ "Content-Type" => "application/json" },
|
|
313
|
+
[{ error: "Conflict: Only one SSE stream is allowed per session" }.to_json],
|
|
314
|
+
]
|
|
315
|
+
end
|
|
316
|
+
|
|
306
317
|
def setup_sse_stream(session_id)
|
|
307
318
|
body = create_sse_body(session_id)
|
|
308
319
|
|
|
@@ -317,17 +328,22 @@ module MCP
|
|
|
317
328
|
|
|
318
329
|
def create_sse_body(session_id)
|
|
319
330
|
proc do |stream|
|
|
320
|
-
store_stream_for_session(session_id, stream)
|
|
321
|
-
start_keepalive_thread(session_id)
|
|
331
|
+
stored = store_stream_for_session(session_id, stream)
|
|
332
|
+
start_keepalive_thread(session_id) if stored
|
|
322
333
|
end
|
|
323
334
|
end
|
|
324
335
|
|
|
325
336
|
def store_stream_for_session(session_id, stream)
|
|
326
337
|
@mutex.synchronize do
|
|
327
|
-
|
|
328
|
-
|
|
338
|
+
session = @sessions[session_id]
|
|
339
|
+
if session && !session[:stream]
|
|
340
|
+
session[:stream] = stream
|
|
329
341
|
else
|
|
342
|
+
# Either session was removed, or another request already established a stream.
|
|
330
343
|
stream.close
|
|
344
|
+
# `stream.close` may return a truthy value depending on the stream class.
|
|
345
|
+
# Explicitly return nil to guarantee a falsy return for callers.
|
|
346
|
+
nil
|
|
331
347
|
end
|
|
332
348
|
end
|
|
333
349
|
end
|
data/lib/mcp/server.rb
CHANGED
|
@@ -531,14 +531,14 @@ module MCP
|
|
|
531
531
|
|
|
532
532
|
def server_context_with_meta(request)
|
|
533
533
|
meta = request[:_meta]
|
|
534
|
-
if meta &&
|
|
535
|
-
context =
|
|
534
|
+
if meta && server_context.is_a?(Hash)
|
|
535
|
+
context = server_context.dup
|
|
536
536
|
context[:_meta] = meta
|
|
537
537
|
context
|
|
538
|
-
elsif meta &&
|
|
538
|
+
elsif meta && server_context.nil?
|
|
539
539
|
{ _meta: meta }
|
|
540
540
|
else
|
|
541
|
-
|
|
541
|
+
server_context
|
|
542
542
|
end
|
|
543
543
|
end
|
|
544
544
|
end
|
data/lib/mcp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Model Context Protocol
|
|
@@ -75,7 +75,7 @@ licenses:
|
|
|
75
75
|
- Apache-2.0
|
|
76
76
|
metadata:
|
|
77
77
|
allowed_push_host: https://rubygems.org
|
|
78
|
-
changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.9.
|
|
78
|
+
changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.9.2
|
|
79
79
|
homepage_uri: https://github.com/modelcontextprotocol/ruby-sdk
|
|
80
80
|
source_code_uri: https://github.com/modelcontextprotocol/ruby-sdk
|
|
81
81
|
bug_tracker_uri: https://github.com/modelcontextprotocol/ruby-sdk/issues
|