Class: Hitch::MCP::Result

Inherits:
Object
  • Object
show all
Defined in:
app/models/hitch/mcp/result.rb

Overview

Closed host return value for MCP tool execution. Constructors copy host values so later mutation cannot change the result Hitch validates.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, value, text) ⇒ Result

Returns a new instance of Result.



53
54
55
56
57
58
# File 'app/models/hitch/mcp/result.rb', line 53

def initialize(kind, value, text)
  @kind = kind
  @value = value
  @text = text
  freeze
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



51
52
53
# File 'app/models/hitch/mcp/result.rb', line 51

def kind
  @kind
end

#textObject (readonly)

Returns the value of attribute text.



51
52
53
# File 'app/models/hitch/mcp/result.rb', line 51

def text
  @text
end

#valueObject (readonly)

Returns the value of attribute value.



51
52
53
# File 'app/models/hitch/mcp/result.rb', line 51

def value
  @value
end

Class Method Details

.error(public_message) ⇒ Object



29
30
31
# File 'app/models/hitch/mcp/result.rb', line 29

def error(public_message)
  new(:error, copy_string(public_message), nil)
end

.structured(value, text: nil) ⇒ Object



22
23
24
25
26
27
# File 'app/models/hitch/mcp/result.rb', line 22

def structured(value, text: nil)
  copied_text = text.nil? ? nil : copy_string(text)
  new(:structured, copy_json(value), copied_text)
rescue SystemStackError
  raise ArgumentError, "MCP Result nesting is too deep"
end

.text(value) ⇒ Object



18
19
20
# File 'app/models/hitch/mcp/result.rb', line 18

def text(value)
  new(:text, copy_string(value), nil)
end