mcp 0.9.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea7153eeac471b5934dcca889a340ae7f484c71ddbf7a3d2f0fde8471857c91f
4
- data.tar.gz: d2a84adc151f14fac5cb610daf215dac48e92f91bc83aae3ba403160b3fff44f
3
+ metadata.gz: a0f26c1a29af5a799a750d9ad00a224f39d24638a9ad267a540313f06da674ed
4
+ data.tar.gz: d340e2c1f6492f74a28c6dabc6a04575285269e13a2352e3f747195d4dac1527
5
5
  SHA512:
6
- metadata.gz: 48340be2274f11fb80abfa55fc9cb63f921db503eaa1b6d262c6b90c36a751dd38cb84e6c38ddc7b05a22d1d3f75ddde8da3ddceafcce0a94986baaae8db019d
7
- data.tar.gz: 6459cc62430d03d2c137315a37cfe18d415c1bb66da15909e9ee96df82e5b13665b89f3acb409ded744346fba1ba1c69551945db45b261eddfb2597583d61d55
6
+ metadata.gz: 7f428407e35305f1cb5a087bd7abb708df12d17abe6cb66f335c8dc2d82d1020407942dd36ad3cb200377e7d60783d87a72bab765b202ae8426cb267f5d3f46a
7
+ data.tar.gz: 49d835de35b9c6c124d99ffe82561a5f7554901d43971afbb82adfb31fe13d0d6d1b6782d460d9b861b6924cc43705266cb09e5de3afd9249b7caa68634fff63
@@ -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
@@ -305,6 +306,14 @@ module MCP
305
306
  [404, { "Content-Type" => "application/json" }, [{ error: "Session not found" }.to_json]]
306
307
  end
307
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
+
308
317
  def setup_sse_stream(session_id)
309
318
  body = create_sse_body(session_id)
310
319
 
@@ -319,17 +328,22 @@ module MCP
319
328
 
320
329
  def create_sse_body(session_id)
321
330
  proc do |stream|
322
- store_stream_for_session(session_id, stream)
323
- start_keepalive_thread(session_id)
331
+ stored = store_stream_for_session(session_id, stream)
332
+ start_keepalive_thread(session_id) if stored
324
333
  end
325
334
  end
326
335
 
327
336
  def store_stream_for_session(session_id, stream)
328
337
  @mutex.synchronize do
329
- if @sessions[session_id]
330
- @sessions[session_id][:stream] = stream
338
+ session = @sessions[session_id]
339
+ if session && !session[:stream]
340
+ session[:stream] = stream
331
341
  else
342
+ # Either session was removed, or another request already established a stream.
332
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
333
347
  end
334
348
  end
335
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 && @server_context.is_a?(Hash)
535
- context = @server_context.dup
534
+ if meta && server_context.is_a?(Hash)
535
+ context = server_context.dup
536
536
  context[:_meta] = meta
537
537
  context
538
- elsif meta && @server_context.nil?
538
+ elsif meta && server_context.nil?
539
539
  { _meta: meta }
540
540
  else
541
- @server_context
541
+ server_context
542
542
  end
543
543
  end
544
544
  end
data/lib/mcp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MCP
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.2"
5
5
  end
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.1
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.1
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