Module: Portage::Ucp::Client::ToolResult

Defined in:
lib/portage/ucp/client/tool_result.rb

Overview

Normalizes a tools/call JSON-RPC response into either the tool's structuredContent, or a raised ServerError — shared across transports since the loopback transport gets a symbol-keyed response (no JSON round-trip, see Transports::Loopback) while stdio/HTTP get a string-keyed one (real wire JSON, parsed by the mcp gem's client).

Class Method Summary collapse

Class Method Details

.extract(response, symbol_keys:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/portage/ucp/client/tool_result.rb', line 12

def self.extract(response, symbol_keys:)
  result = fetch(response, "result", symbol_keys) || {}
  content = fetch(result, "content", symbol_keys)
  if fetch(result, "isError", symbol_keys)
    body = text(content, symbol_keys: symbol_keys)
    raise ServerError.new(body, payload: parse(body))
  end

  fetch(result, "structuredContent", symbol_keys)
end

.text(content, symbol_keys:) ⇒ Object



23
24
25
# File 'lib/portage/ucp/client/tool_result.rb', line 23

def self.text(content, symbol_keys:)
  Array(content).filter_map { |block| fetch(block, "text", symbol_keys) }.join(" ")
end