Class: RubyLLM::MCP::Adapters::MCPTransports::Stdio
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Adapters::MCPTransports::Stdio
- Defined in:
- lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb
Overview
Custom Stdio transport for MCP SDK adapter Wraps the native Stdio transport to provide the interface expected by MCP::Client
Instance Attribute Summary collapse
-
#native_transport ⇒ Object
readonly
Returns the value of attribute native_transport.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(command:, args: [], env: {}, request_timeout: 10_000, protocol_version: RubyLLM::MCP.config.protocol_version, notification_callback: nil) ⇒ Stdio
constructor
rubocop:disable Metrics/ParameterLists.
-
#send_request(request:) ⇒ Hash
Send a JSON-RPC request and return the response This is the interface expected by MCP::Client.
- #start ⇒ Object
Constructor Details
#initialize(command:, args: [], env: {}, request_timeout: 10_000, protocol_version: RubyLLM::MCP.config.protocol_version, notification_callback: nil) ⇒ Stdio
rubocop:disable Metrics/ParameterLists
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb', line 9 def initialize(command:, args: [], env: {}, request_timeout: 10_000, # rubocop:disable Metrics/ParameterLists protocol_version: RubyLLM::MCP.config.protocol_version, notification_callback: nil) # Create a minimal coordinator-like object for the native transport @coordinator = CoordinatorStub.new( protocol_version: protocol_version, notification_callback: notification_callback ) @native_transport = RubyLLM::MCP::Native::Transports::Stdio.new( command: command, args: args, env: env, coordinator: @coordinator, request_timeout: request_timeout ) @coordinator.transport = @native_transport end |
Instance Attribute Details
#native_transport ⇒ Object (readonly)
Returns the value of attribute native_transport.
7 8 9 |
# File 'lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb', line 7 def native_transport @native_transport end |
Instance Method Details
#close ⇒ Object
32 33 34 |
# File 'lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb', line 32 def close @native_transport.close end |
#send_request(request:) ⇒ Hash
Send a JSON-RPC request and return the response This is the interface expected by MCP::Client
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb', line 41 def send_request(request:) start unless @native_transport.alive? unless request["id"] || request[:id] request["id"] = SecureRandom.uuid end result = @native_transport.request(request, wait_for_response: true) if result.is_a?(RubyLLM::MCP::Result) result.response else result end end |
#start ⇒ Object
28 29 30 |
# File 'lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb', line 28 def start @native_transport.start end |