Class: VectorMCP::Sampling::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/vector_mcp/sampling/result.rb

Overview

Represents the result of a sampling request returned by an MCP client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result_hash) ⇒ Result

Initializes a new Sampling::Result.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vector_mcp/sampling/result.rb', line 21

def initialize(result_hash)
  # Handle malformed or nil result_hash
  raise ArgumentError, "Sampling result must be a Hash, got #{result_hash.class}: #{result_hash.inspect}" unless result_hash.is_a?(Hash)

  @raw_result = result_hash.transform_keys { |k| k.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym }

  @model = @raw_result[:model]
  @stop_reason = @raw_result[:stop_reason]
  @role = @raw_result[:role]

  # Safe content processing for malformed responses
  content_raw = @raw_result[:content]
  @content = if content_raw.is_a?(Hash)
               content_raw.transform_keys(&:to_sym)
             else
               {}
             end

  validate!
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/vector_mcp/sampling/result.rb', line 7

def content
  @content
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/vector_mcp/sampling/result.rb', line 7

def model
  @model
end

#raw_resultObject (readonly)

Returns the value of attribute raw_result.



7
8
9
# File 'lib/vector_mcp/sampling/result.rb', line 7

def raw_result
  @raw_result
end

#roleObject (readonly)

Returns the value of attribute role.



7
8
9
# File 'lib/vector_mcp/sampling/result.rb', line 7

def role
  @role
end

#stop_reasonObject (readonly)

Returns the value of attribute stop_reason.



7
8
9
# File 'lib/vector_mcp/sampling/result.rb', line 7

def stop_reason
  @stop_reason
end

Instance Method Details

#image?Boolean



48
49
50
# File 'lib/vector_mcp/sampling/result.rb', line 48

def image?
  @content[:type] == "image"
end

#image_dataString?



58
59
60
# File 'lib/vector_mcp/sampling/result.rb', line 58

def image_data
  image? ? @content[:data] : nil
end

#image_mime_typeString?



63
64
65
# File 'lib/vector_mcp/sampling/result.rb', line 63

def image_mime_type
  image? ? @content[:mime_type] : nil
end

#text?Boolean



43
44
45
# File 'lib/vector_mcp/sampling/result.rb', line 43

def text?
  @content[:type] == "text"
end

#text_contentString?



53
54
55
# File 'lib/vector_mcp/sampling/result.rb', line 53

def text_content
  text? ? @content[:text] : nil
end