Class: LLM::MCP::Pipe
- Inherits:
-
Object
- Object
- LLM::MCP::Pipe
- Defined in:
- lib/llm/mcp/pipe.rb
Overview
The LLM::MCP::Pipe class wraps a pair of IO objects created by IO.pipe. It is used by LLM::MCP::Transport::Stdio to manage the stdin, stdout, and stderr streams of an MCP process through one small interface.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#close_writer ⇒
void
Closes the writer.
-
#read_nonblock ⇒
String
Reads from the reader end without blocking.
-
#write ⇒
Integer
Writes to the writer.
-
#flush ⇒
void
Flushes the writer.
-
#closed? ⇒
Boolean
Returns true when both ends are closed.
-
#close ⇒
void
Closes both ends of the pipe.
-
#close_reader ⇒
void
Closes the reader.
-
#initialize ⇒
LLM::MCP::Pipe constructor
Returns a new pipe.
Constructor Details
#initialize ⇒ LLM::MCP::Pipe
Returns a new pipe.
24 25 26 |
# File 'lib/llm/mcp/pipe.rb', line 24 def initialize @r, @w = IO.pipe end |
Instance Attribute Details
#r ⇒ IO (readonly)
Returns the reader
14 15 16 |
# File 'lib/llm/mcp/pipe.rb', line 14 def r @r end |
#w ⇒ IO (readonly)
Returns the writer
19 20 21 |
# File 'lib/llm/mcp/pipe.rb', line 19 def w @w end |
Instance Method Details
#close_writer ⇒ void
This method returns an undefined value.
Closes the writer.
77 78 79 80 |
# File 'lib/llm/mcp/pipe.rb', line 77 def close_writer @w.close rescue IOError end |
#read_nonblock ⇒ String
Reads from the reader end without blocking.
33 34 35 |
# File 'lib/llm/mcp/pipe.rb', line 33 def read_nonblock(...) @r.read_nonblock(...) end |
#write ⇒ Integer
Writes to the writer.
40 41 42 |
# File 'lib/llm/mcp/pipe.rb', line 40 def write(...) @w.write(...) end |
#flush ⇒ void
This method returns an undefined value.
Flushes the writer.
47 48 49 |
# File 'lib/llm/mcp/pipe.rb', line 47 def flush @w.flush end |
#closed? ⇒ Boolean
Returns true when both ends are closed.
54 55 56 |
# File 'lib/llm/mcp/pipe.rb', line 54 def closed? [@r, @w].all?(&:closed?) end |
#close ⇒ void
This method returns an undefined value.
Closes both ends of the pipe.
61 62 63 64 |
# File 'lib/llm/mcp/pipe.rb', line 61 def close [@r, @w].each(&:close) rescue IOError end |
#close_reader ⇒ void
This method returns an undefined value.
Closes the reader.
69 70 71 72 |
# File 'lib/llm/mcp/pipe.rb', line 69 def close_reader @r.close rescue IOError end |