Class: Parse::Agent::MCPClient::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/parse/agent/mcp_client.rb

Overview

Result of an ask / reply call.

  • text is the LLM's final-turn answer.
  • tool_calls is the ordered list of tools invoked, each with its arguments and the dispatcher's response.
  • transcript is the full message log (useful for debugging).
  • usage is a Usage struct for this single call (sum across all LLM turns the round-trip required).
  • reply(question) continues the conversation that produced this result. Chain freely: mcp.ask("a").reply("b").reply("c").

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



58
59
60
# File 'lib/parse/agent/mcp_client.rb', line 58

def client
  @client
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



58
59
60
# File 'lib/parse/agent/mcp_client.rb', line 58

def text
  @text
end

#tool_callsObject

Returns the value of attribute tool_calls

Returns:

  • (Object)

    the current value of tool_calls



58
59
60
# File 'lib/parse/agent/mcp_client.rb', line 58

def tool_calls
  @tool_calls
end

#transcriptObject

Returns the value of attribute transcript

Returns:

  • (Object)

    the current value of transcript



58
59
60
# File 'lib/parse/agent/mcp_client.rb', line 58

def transcript
  @transcript
end

#usageObject

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



58
59
60
# File 'lib/parse/agent/mcp_client.rb', line 58

def usage
  @usage
end

Instance Method Details

#reply(question) ⇒ Result

Continue this conversation. Equivalent to calling client.ask(question, reset: false).

Parameters:

Returns:



63
64
65
66
# File 'lib/parse/agent/mcp_client.rb', line 63

def reply(question)
  raise "Result has no associated client (constructed outside MCPClient)" unless client
  client.ask(question, reset: false)
end

#to_sObject Also known as: inspect

Pretty-print for IRB: tool trace, answer, then per-call usage line.

Every interpolated part is attacker-influenced. The answer is LLM output that was itself conditioned on tenant rows, and tool arguments can echo stored values. Merely evaluating mcp.ask(...) in IRB writes this string to the terminal, so control sequences are escaped here. text itself is untouched: callers that render into a non-terminal surface still get the exact bytes.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/parse/agent/mcp_client.rb', line 76

def to_s
  parts = []
  if tool_calls.any?
    parts << "─── tool calls (#{tool_calls.size}) ───"
    tool_calls.each_with_index do |tc, i|
      args_str = tc[:arguments].is_a?(Hash) ? tc[:arguments].inspect : tc[:arguments].to_s
      parts << "  #{i + 1}. #{Parse::TerminalSafe.sanitize_line(tc[:name])}" \
               "(#{Parse::TerminalSafe.sanitize_line(args_str)})"
    end
  end
  parts << "─── answer ───"
  parts << Parse::TerminalSafe.sanitize(text)
  parts << "─── usage ───" << "  #{usage}" if usage && usage.total_tokens.positive?
  parts.join("\n")
end