Class: RubyLLM::MCP::Result
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Result
- Defined in:
- lib/ruby_llm/mcp/result.rb
Constant Summary collapse
- REQUEST_METHODS =
{ ping: "ping", roots: "roots/list", sampling: "sampling/createMessage", elicitation: "elicitation/create" }.freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#next_cursor ⇒ Object
readonly
Returns the value of attribute next_cursor.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#result ⇒ Object
(also: #value)
readonly
Returns the value of attribute result.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #execution_error? ⇒ Boolean
-
#initialize(response, session_id: nil) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #matching_id?(request_id) ⇒ Boolean
- #next_cursor? ⇒ Boolean
- #notification ⇒ Object
- #notification? ⇒ Boolean
- #raise_error! ⇒ Object
- #request? ⇒ Boolean
- #response? ⇒ Boolean
- #success? ⇒ Boolean
- #to_error ⇒ Object
- #to_s ⇒ Object
- #tool_success? ⇒ Boolean
Constructor Details
#initialize(response, session_id: nil) ⇒ Result
Returns a new instance of Result.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_llm/mcp/result.rb', line 24 def initialize(response, session_id: nil) @response = response @session_id = session_id @id = response["id"] @method = response["method"] @result = response["result"] || {} @params = response["params"] || {} @error = response["error"] || {} @result_is_error = response.dig("result", "isError") || false @next_cursor = response.dig("result", "nextCursor") # Track whether result/error keys exist (for JSON-RPC detection) @has_result = response.key?("result") @has_error = response.key?("error") end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def error @error end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def id @id end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def method @method end |
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def next_cursor @next_cursor end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def response @response end |
#result ⇒ Object (readonly) Also known as: value
Returns the value of attribute result.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def result @result end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
15 16 17 |
# File 'lib/ruby_llm/mcp/result.rb', line 15 def session_id @session_id end |
Instance Method Details
#error? ⇒ Boolean
95 96 97 |
# File 'lib/ruby_llm/mcp/result.rb', line 95 def error? !@error.empty? end |
#execution_error? ⇒ Boolean
57 58 59 |
# File 'lib/ruby_llm/mcp/result.rb', line 57 def execution_error? @result_is_error end |
#inspect ⇒ Object
103 104 105 |
# File 'lib/ruby_llm/mcp/result.rb', line 103 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} id: #{@id}, result: #{@result}, error: #{@error}, method: #{@method}, params: #{@params}>" # rubocop:disable Layout/LineLength end |
#matching_id?(request_id) ⇒ Boolean
67 68 69 |
# File 'lib/ruby_llm/mcp/result.rb', line 67 def matching_id?(request_id) @id&.to_s == request_id.to_s end |
#next_cursor? ⇒ Boolean
75 76 77 |
# File 'lib/ruby_llm/mcp/result.rb', line 75 def next_cursor? !@next_cursor.nil? end |
#notification ⇒ Object
49 50 51 |
# File 'lib/ruby_llm/mcp/result.rb', line 49 def notification Notification.new(@response) end |
#notification? ⇒ Boolean
71 72 73 |
# File 'lib/ruby_llm/mcp/result.rb', line 71 def notification? @id.nil? && !@method.nil? end |
#raise_error! ⇒ Object
61 62 63 64 65 |
# File 'lib/ruby_llm/mcp/result.rb', line 61 def raise_error! error = to_error = "Response error: #{error}" raise Errors::ResponseError.new(message: , error: error) end |
#request? ⇒ Boolean
79 80 81 |
# File 'lib/ruby_llm/mcp/result.rb', line 79 def request? !@id.nil? && !@method.nil? end |
#response? ⇒ Boolean
83 84 85 |
# File 'lib/ruby_llm/mcp/result.rb', line 83 def response? !@id.nil? && @method.nil? && (@has_result || @has_error) end |
#success? ⇒ Boolean
87 88 89 |
# File 'lib/ruby_llm/mcp/result.rb', line 87 def success? @has_result end |
#to_error ⇒ Object
53 54 55 |
# File 'lib/ruby_llm/mcp/result.rb', line 53 def to_error Error.new(@error) end |
#to_s ⇒ Object
99 100 101 |
# File 'lib/ruby_llm/mcp/result.rb', line 99 def to_s inspect end |
#tool_success? ⇒ Boolean
91 92 93 |
# File 'lib/ruby_llm/mcp/result.rb', line 91 def tool_success? success? && !@result_is_error end |