Module: ActionMCP::Renderable

Included in:
Capability
Defined in:
lib/action_mcp/renderable.rb

Overview

Module for rendering content.

Instance Method Summary collapse

Instance Method Details

#render(text: nil, audio: nil, image: nil, resource: nil, mime_type: nil, blob: nil) ⇒ Content::Text, ...

Renders content for Model Context Protocol responses.

Examples:

Render text content

render(text: "Hello, world!")

Parameters:

  • text (String, nil) (defaults to: nil)

    Text content to render

  • audio (String, nil) (defaults to: nil)

    Audio content to render

  • image (String, nil) (defaults to: nil)

    Image content to render

  • resource (String, nil) (defaults to: nil)

    URI for resource content

  • mime_type (String, nil) (defaults to: nil)

    MIME type for audio, image, or resource content

  • blob (String, nil) (defaults to: nil)

    Binary data for resource content

Returns:

Raises:

  • (ArgumentError)

    If no valid content parameters are provided



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/action_mcp/renderable.rb', line 23

def render(text: nil, audio: nil, image: nil, resource: nil, mime_type: nil, blob: nil)
  if resource && mime_type
    Content::Resource.new(resource, mime_type, text: text, blob: blob, annotations: nil)
  elsif text
    Content::Text.new(text, annotations: nil)
  elsif audio && mime_type
    Content::Audio.new(audio, mime_type, annotations: nil)
  elsif image && mime_type
    Content::Image.new(image, mime_type, annotations: nil)
  else
    raise ArgumentError, "No content to render"
  end
end

Renders a resource link for Model Context Protocol responses.

Examples:

Render a resource link

render_resource_link(uri: "file:///path/to/file.txt", name: "Example File")

Parameters:

  • uri (String)

    The URI of the resource

  • name (String, nil) (defaults to: nil)

    Optional name for the resource

  • description (String, nil) (defaults to: nil)

    Optional description

  • mime_type (String, nil) (defaults to: nil)

    Optional MIME type

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

    Optional annotations

Returns:



50
51
52
53
# File 'lib/action_mcp/renderable.rb', line 50

def render_resource_link(uri:, name: nil, description: nil, mime_type: nil, annotations: nil)
  Content::ResourceLink.new(uri, name: name, description: description,
                                 mime_type: mime_type, annotations: annotations)
end