Class: LLM::MCP::Pipe

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeLLM::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

#rIO (readonly)

Returns the reader

Returns:

  • (IO)

    Returns the reader



14
15
16
# File 'lib/llm/mcp/pipe.rb', line 14

def r
  @r
end

#wIO (readonly)

Returns the writer

Returns:

  • (IO)

    Returns the writer



19
20
21
# File 'lib/llm/mcp/pipe.rb', line 19

def w
  @w
end

Instance Method Details

#close_writervoid

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_nonblockString

Reads from the reader end without blocking.

Returns:

  • (String)

Raises:

  • (IO::WaitReadable)

    When no data is available to read



33
34
35
# File 'lib/llm/mcp/pipe.rb', line 33

def read_nonblock(...)
  @r.read_nonblock(...)
end

#writeInteger

Writes to the writer.

Returns:

  • (Integer)


40
41
42
# File 'lib/llm/mcp/pipe.rb', line 40

def write(...)
  @w.write(...)
end

#flushvoid

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.

Returns:

  • (Boolean)


54
55
56
# File 'lib/llm/mcp/pipe.rb', line 54

def closed?
  [@r, @w].all?(&:closed?)
end

#closevoid

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_readervoid

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