Class: ActionMCP::Content::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mcp/content.rb,
lib/action_mcp/content/base.rb

Overview

Base class for all content types, supporting annotations.

Direct Known Subclasses

Audio, Image, Resource, ResourceLink, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, annotations: nil) ⇒ Base

Initializes a new content base.

Parameters:

  • type (String)

    The type of the content (e.g., “text”, “image”, etc.)

  • annotations (Hash, nil) (defaults to: nil)

    Optional annotations for the content.



16
17
18
19
# File 'lib/action_mcp/content.rb', line 16

def initialize(type, annotations: nil)
  @type = type
  @annotations = annotations
end

Instance Attribute Details

#annotationsSymbol, ... (readonly)

Returns:

  • (Symbol)

    The type of content.

  • (Hash, nil)

    Optional annotations for the content.



10
11
12
# File 'lib/action_mcp/content.rb', line 10

def annotations
  @annotations
end

#typeSymbol, ... (readonly)

Returns:

  • (Symbol)

    The type of content.

  • (Hash, nil)

    Optional annotations for the content.



10
11
12
# File 'lib/action_mcp/content.rb', line 10

def type
  @type
end

Instance Method Details

#to_hHash

Returns a hash representation of the base content.

Returns:

  • (Hash)

    The hash representation of the base content.



24
25
26
27
28
# File 'lib/action_mcp/content.rb', line 24

def to_h
  h = { type: @type }
  h[:annotations] = @annotations if @annotations
  h
end

#to_jsonString

Returns a JSON representation of the content.

Returns:

  • (String)

    The JSON representation.



33
34
35
# File 'lib/action_mcp/content.rb', line 33

def to_json(*)
  MultiJson.dump(to_h, *)
end