Class: ModelContextProtocol::Server::StdioTransport::RequestStore
- Inherits:
-
Object
- Object
- ModelContextProtocol::Server::StdioTransport::RequestStore
- Defined in:
- lib/model_context_protocol/server/stdio_transport/request_store.rb
Overview
Thread-safe in-memory storage for tracking active requests and their cancellation status. This store is used by StdioTransport to manage request lifecycle and handle cancellation.
Instance Method Summary collapse
-
#cancelled?(jsonrpc_request_id) ⇒ Boolean
Check if a request has been cancelled.
-
#initialize ⇒ RequestStore
constructor
A new instance of RequestStore.
-
#mark_cancelled(jsonrpc_request_id) ⇒ Boolean
Mark a request as cancelled.
-
#register_request(jsonrpc_request_id, thread = Thread.current) ⇒ void
Register a new request with its associated thread.
-
#unregister_request(jsonrpc_request_id) ⇒ Hash?
Unregister a request (typically called when request completes).
Constructor Details
#initialize ⇒ RequestStore
Returns a new instance of RequestStore.
6 7 8 9 |
# File 'lib/model_context_protocol/server/stdio_transport/request_store.rb', line 6 def initialize @mutex = Mutex.new @requests = {} end |
Instance Method Details
#cancelled?(jsonrpc_request_id) ⇒ Boolean
Check if a request has been cancelled
44 45 46 47 48 |
# File 'lib/model_context_protocol/server/stdio_transport/request_store.rb', line 44 def cancelled?(jsonrpc_request_id) @mutex.synchronize do @requests[jsonrpc_request_id]&.fetch(:cancelled, false) || false end end |
#mark_cancelled(jsonrpc_request_id) ⇒ Boolean
Mark a request as cancelled
30 31 32 33 34 35 36 37 38 |
# File 'lib/model_context_protocol/server/stdio_transport/request_store.rb', line 30 def mark_cancelled(jsonrpc_request_id) @mutex.synchronize do if (request = @requests[jsonrpc_request_id]) request[:cancelled] = true return true end false end end |
#register_request(jsonrpc_request_id, thread = Thread.current) ⇒ void
This method returns an undefined value.
Register a new request with its associated thread
16 17 18 19 20 21 22 23 24 |
# File 'lib/model_context_protocol/server/stdio_transport/request_store.rb', line 16 def register_request(jsonrpc_request_id, thread = Thread.current) @mutex.synchronize do @requests[jsonrpc_request_id] = { thread:, cancelled: false, started_at: Time.now } end end |
#unregister_request(jsonrpc_request_id) ⇒ Hash?
Unregister a request (typically called when request completes)
54 55 56 57 58 |
# File 'lib/model_context_protocol/server/stdio_transport/request_store.rb', line 54 def unregister_request(jsonrpc_request_id) @mutex.synchronize do @requests.delete(jsonrpc_request_id) end end |