Class: Mistri::MCP::Wires::Stdio
- Inherits:
-
Object
- Object
- Mistri::MCP::Wires::Stdio
- Defined in:
- lib/mistri/mcp/wires.rb
Overview
Stdio: a spawned child process, one JSON-RPC message per line, with credentials in its environment, as the spec prescribes for local servers. Its stderr stays attached for honest local debugging.
Instance Method Summary collapse
- #call(payload) ⇒ Object
- #close ⇒ Object
-
#initialize(command:, env: {}, read_timeout: 120) ⇒ Stdio
constructor
A new instance of Stdio.
- #notify(payload) ⇒ Object
- #protocol_version=(_version) ⇒ Object
- #refreshable? ⇒ Boolean
- #reset_session ⇒ Object
- #session? ⇒ Boolean
Constructor Details
#initialize(command:, env: {}, read_timeout: 120) ⇒ Stdio
Returns a new instance of Stdio.
75 76 77 78 79 80 |
# File 'lib/mistri/mcp/wires.rb', line 75 def initialize(command:, env: {}, read_timeout: 120) @command = Array(command).map(&:to_s) @env = env.transform_keys(&:to_s).transform_values(&:to_s) @read_timeout = read_timeout @pid = nil end |
Instance Method Details
#call(payload) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/mistri/mcp/wires.rb', line 82 def call(payload) spawn_server unless @pid write(payload) loop do record = read_record yield record break if record.is_a?(Hash) && record["id"] == payload[:id] end nil end |
#close ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/mistri/mcp/wires.rb', line 107 def close return unless @pid [@stdin, @stdout].each { |io| io.close unless io.closed? } terminate @pid = nil end |
#notify(payload) ⇒ Object
93 94 95 96 97 |
# File 'lib/mistri/mcp/wires.rb', line 93 def notify(payload) spawn_server unless @pid write(payload) nil end |
#protocol_version=(_version) ⇒ Object
105 |
# File 'lib/mistri/mcp/wires.rb', line 105 def protocol_version=(_version); end |
#refreshable? ⇒ Boolean
101 |
# File 'lib/mistri/mcp/wires.rb', line 101 def refreshable? = false |
#reset_session ⇒ Object
103 |
# File 'lib/mistri/mcp/wires.rb', line 103 def reset_session = nil |
#session? ⇒ Boolean
99 |
# File 'lib/mistri/mcp/wires.rb', line 99 def session? = false |