Class: RubyLLM::MCP::Content

Inherits:
Content
  • Object
show all
Defined in:
lib/ruby_llm/mcp/content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, attachments: nil) ⇒ Content

rubocop:disable Lint/MissingSuper



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_llm/mcp/content.rb', line 8

def initialize(text: nil, attachments: nil) # rubocop:disable Lint/MissingSuper
  @text = text
  @attachments = []

  # Handle MCP::Attachment objects directly without processing
  if attachments.is_a?(Array) && attachments.all? { |a| a.is_a?(MCP::Attachment) }
    @attachments = attachments
  elsif attachments
    # Let parent class process other types of attachments
    process_attachments(attachments)
  end
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



6
7
8
# File 'lib/ruby_llm/mcp/content.rb', line 6

def attachments
  @attachments
end

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/ruby_llm/mcp/content.rb', line 6

def content
  @content
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/ruby_llm/mcp/content.rb', line 6

def text
  @text
end

Instance Method Details

#to_sObject

This is a workaround to allow the content object to be passed as the tool call to return audio or image attachments.



23
24
25
# File 'lib/ruby_llm/mcp/content.rb', line 23

def to_s
  text.to_s
end