Class: LittleGhost::MCP::Session
- Inherits:
-
Object
- Object
- LittleGhost::MCP::Session
- Defined in:
- lib/little_ghost/mcp/client.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(client) ⇒ Session
constructor
A new instance of Session.
- #request(context: nil) ⇒ Object
Constructor Details
#initialize(client) ⇒ Session
Returns a new instance of Session.
130 131 132 133 134 135 136 |
# File 'lib/little_ghost/mcp/client.rb', line 130 def initialize(client) @client = client @closed = false @unavailable = false @close_mutex = Mutex.new @request_mutex = Mutex.new if stdio? end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
128 129 130 |
# File 'lib/little_ghost/mcp/client.rb', line 128 def client @client end |
Instance Method Details
#close ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/little_ghost/mcp/client.rb', line 155 def close should_close = @close_mutex.synchronize do next false if @closed @closed = true true end client.transport.close if should_close && client.transport.respond_to?(:close) end |
#request(context: nil) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/little_ghost/mcp/client.rb', line 138 def request(context: nil) ensure_available! return yield unless @request_mutex until @request_mutex.try_lock context&.check! sleep 0.01 end ensure_available! yield rescue ::MCP::CancelledError invalidate! if stdio? raise ensure @request_mutex&.unlock if @request_mutex&.owned? end |