Class: Rubydex::MCPServer::StdioTransport
- Inherits:
-
Object
- Object
- Rubydex::MCPServer::StdioTransport
- Defined in:
- lib/rubydex/mcp_server/protocol.rb
Instance Method Summary collapse
-
#close ⇒ Object
: -> void.
-
#initialize ⇒ StdioTransport
constructor
: -> void.
-
#open ⇒ Object
: { (Hash | Array?, Hash?) -> void } -> void.
-
#write(response) ⇒ Object
: (Hash | Array?) -> void.
Constructor Details
#initialize ⇒ StdioTransport
: -> void
125 126 127 128 129 130 131 132 |
# File 'lib/rubydex/mcp_server/protocol.rb', line 125 def initialize @input = $stdin @output = $stdout @input.binmode @input.sync = true @output.binmode @output.sync = true end |
Instance Method Details
#close ⇒ Object
: -> void
151 152 153 |
# File 'lib/rubydex/mcp_server/protocol.rb', line 151 def close @output.flush end |
#open ⇒ Object
: { (Hash | Array?, Hash?) -> void } -> void
135 136 137 138 139 140 141 |
# File 'lib/rubydex/mcp_server/protocol.rb', line 135 def open @input.each_line do |line| yield JSON.parse(line, symbolize_names: true) rescue JSON::ParserError yield nil, JSONRPC.error_response(nil, JSONRPC::PARSE_ERROR, "Parse error", data: "Invalid JSON") end end |
#write(response) ⇒ Object
: (Hash | Array?) -> void
144 145 146 147 148 |
# File 'lib/rubydex/mcp_server/protocol.rb', line 144 def write(response) return unless response @output.puts(JSON.generate(response)) end |