Class: RubyLLM::MCP::Native::Transports::Stdio
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Native::Transports::Stdio
- Defined in:
- lib/ruby_llm/mcp/native/transports/stdio.rb
Constant Summary collapse
- DEFAULT_ENV =
Default environment that merges with user-provided env This ensures PATH and other critical env vars are preserved
ENV.to_h.freeze
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#coordinator ⇒ Object
readonly
Returns the value of attribute coordinator.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #close ⇒ Object
-
#initialize(command:, coordinator:, request_timeout:, args: [], env: {}) ⇒ Stdio
constructor
A new instance of Stdio.
- #request(body, wait_for_response: true) ⇒ Object
- #running? ⇒ Boolean
- #set_protocol_version(version) ⇒ Object
- #start ⇒ Object
Methods included from RubyLLM::MCP::Native::Transports::Support::Timeout
Constructor Details
#initialize(command:, coordinator:, request_timeout:, args: [], env: {}) ⇒ Stdio
Returns a new instance of Stdio.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 16 def initialize(command:, coordinator:, request_timeout:, args: [], env: {}) @request_timeout = request_timeout @command = command @coordinator = coordinator @args = args # Merge provided env with default environment (user env takes precedence) @env = DEFAULT_ENV.merge(env || {}) @client_id = SecureRandom.uuid @id_counter = 0 @id_mutex = Mutex.new @pending_requests = {} @pending_mutex = Mutex.new @state_mutex = Mutex.new @running = false @reader_thread = nil @stderr_thread = nil end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
10 11 12 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 10 def command @command end |
#coordinator ⇒ Object (readonly)
Returns the value of attribute coordinator.
10 11 12 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 10 def coordinator @coordinator end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 10 def id @id end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
10 11 12 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 10 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
10 11 12 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 10 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
10 11 12 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 10 def stdout @stdout end |
Instance Method Details
#alive? ⇒ Boolean
46 47 48 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 46 def alive? running? end |
#close ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 63 def close @state_mutex.synchronize do return unless @running @running = false end shutdown_process fail_pending_requests!(RubyLLM::MCP::Errors::TransportError.new(message: "Transport closed")) end |
#request(body, wait_for_response: true) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 35 def request(body, wait_for_response: true) request_id = prepare_request_id(body, wait_for_response) response_queue = register_pending_request(request_id, wait_for_response) send_request(body, request_id) return unless wait_for_response wait_for_request_response(request_id, response_queue) end |
#running? ⇒ Boolean
50 51 52 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 50 def running? @state_mutex.synchronize { @running } end |
#set_protocol_version(version) ⇒ Object
73 74 75 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 73 def set_protocol_version(version) @protocol_version = version end |
#start ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/ruby_llm/mcp/native/transports/stdio.rb', line 54 def start @state_mutex.synchronize do return if @running @running = true end start_process end |