Class: Rigor::MCP::Loop
- Inherits:
-
Object
- Object
- Rigor::MCP::Loop
- Defined in:
- lib/rigor/mcp/loop.rb
Overview
Reads newline-delimited JSON-RPC 2.0 messages from ‘input`, dispatches each to `server`, and writes responses to `output`. Runs until input reaches EOF (the client closes the connection).
Instance Method Summary collapse
-
#initialize(input:, output:, server:) ⇒ Loop
constructor
A new instance of Loop.
- #run ⇒ Object
Constructor Details
#initialize(input:, output:, server:) ⇒ Loop
Returns a new instance of Loop.
11 12 13 14 15 |
# File 'lib/rigor/mcp/loop.rb', line 11 def initialize(input:, output:, server:) @input = input @output = output @server = server end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rigor/mcp/loop.rb', line 17 def run @input.each_line do |raw| line = raw.chomp next if line.empty? begin request = JSON.parse(line) rescue JSON::ParserError => e write_response({ "jsonrpc" => "2.0", "id" => nil, "error" => { "code" => -32_700, "message" => "Parse error: #{e.}" } }) next end response = @server.handle(request) write_response(response) if response end end |