Class: Rubyagents::MCP::StdioTransport
- Inherits:
-
Object
- Object
- Rubyagents::MCP::StdioTransport
- Defined in:
- lib/rubyagents/mcp.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(command:) ⇒ StdioTransport
constructor
A new instance of StdioTransport.
- #send_request(request:) ⇒ Object
Constructor Details
#initialize(command:) ⇒ StdioTransport
Returns a new instance of StdioTransport.
9 10 11 12 13 |
# File 'lib/rubyagents/mcp.rb', line 9 def initialize(command:) @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*Array(command)) @request_id = 0 handshake! end |
Instance Method Details
#close ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rubyagents/mcp.rb', line 22 def close @stdin.close unless @stdin.closed? @stdout.close unless @stdout.closed? @stderr.close unless @stderr.closed? @wait_thread.join end |
#send_request(request:) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rubyagents/mcp.rb', line 15 def send_request(request:) @request_id += 1 payload = { jsonrpc: "2.0", id: @request_id }.merge(request) (payload) read_response(@request_id) end |