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.

Parameters:

  • result_hash (Hash)

    The raw hash returned by the client for a sampling request. Expected keys (MCP spec uses camelCase, we symbolize and underscore internally):

    • 'model' String Name of the model used.
    • 'stopReason' String Reason why generation stopped.
    • 'role' String "user" or "assistant".
    • 'content' Hash The generated content.
      • 'type' String "text" or "image".
      • 'text' String Text content if type is "text".
      • 'data' String Base64 image data if type is "image".
      • 'mimeType' String Mime type if type is "image".


21
22
23
24
25
26
27
28
29
30
# File 'lib/vector_mcp/sampling/result.rb', line 21

def initialize(result_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]
  @content = (@raw_result[:content] || {}).transform_keys(&:to_sym)

  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

Returns True if the content type is 'image'.

Returns:

  • (Boolean)

    True if the content type is 'image'.



38
39
40
# File 'lib/vector_mcp/sampling/result.rb', line 38

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

#image_dataString?

Returns The base64 encoded image data if type is 'image', otherwise nil.

Returns:

  • (String, nil)

    The base64 encoded image data if type is 'image', otherwise nil.



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

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

#image_mime_typeString?

Returns The mime type of the image if type is 'image', otherwise nil.

Returns:

  • (String, nil)

    The mime type of the image if type is 'image', otherwise nil.



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

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

#text?Boolean

Returns True if the content type is 'text'.

Returns:

  • (Boolean)

    True if the content type is 'text'.



33
34
35
# File 'lib/vector_mcp/sampling/result.rb', line 33

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

#text_contentString?

Returns The text content if type is 'text', otherwise nil.

Returns:

  • (String, nil)

    The text content if type is 'text', otherwise nil.



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

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