Class: ActionMCP::Content::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/action_mcp/content/resource.rb

Overview

Resource content references a server-managed resource. It includes a URI, MIME type, and optionally text content or a base64-encoded blob.

Instance Attribute Summary collapse

Attributes inherited from Base

#type

Instance Method Summary collapse

Methods inherited from Base

#to_json

Constructor Details

#initialize(uri, mime_type = "text/plain", text: nil, blob: nil, annotations: nil) ⇒ Resource

Initializes a new Resource content.

Parameters:

  • uri (String)

    The URI of the resource.

  • mime_type (String) (defaults to: "text/plain")

    The MIME type of the resource.

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

    The text content of the resource (optional).

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

    The base64-encoded blob of the resource (optional).

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

    Optional annotations for the resource.



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

def initialize(uri, mime_type = "text/plain", text: nil, blob: nil, annotations: nil)
  super("resource", annotations: annotations)
  @uri = uri
  @mime_type = mime_type
  @text = text
  @blob = blob
  @annotations = annotations
end

Instance Attribute Details

#annotationsString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String)

    The MIME type of the resource.

  • (String, nil)

    The text content of the resource (optional).

  • (String, nil)

    The base64-encoded blob of the resource (optional).



12
13
14
# File 'lib/action_mcp/content/resource.rb', line 12

def annotations
  @annotations
end

#blobString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String)

    The MIME type of the resource.

  • (String, nil)

    The text content of the resource (optional).

  • (String, nil)

    The base64-encoded blob of the resource (optional).



12
13
14
# File 'lib/action_mcp/content/resource.rb', line 12

def blob
  @blob
end

#mime_typeString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String)

    The MIME type of the resource.

  • (String, nil)

    The text content of the resource (optional).

  • (String, nil)

    The base64-encoded blob of the resource (optional).



12
13
14
# File 'lib/action_mcp/content/resource.rb', line 12

def mime_type
  @mime_type
end

#textString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String)

    The MIME type of the resource.

  • (String, nil)

    The text content of the resource (optional).

  • (String, nil)

    The base64-encoded blob of the resource (optional).



12
13
14
# File 'lib/action_mcp/content/resource.rb', line 12

def text
  @text
end

#uriString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String)

    The MIME type of the resource.

  • (String, nil)

    The text content of the resource (optional).

  • (String, nil)

    The base64-encoded blob of the resource (optional).



12
13
14
# File 'lib/action_mcp/content/resource.rb', line 12

def uri
  @uri
end

Instance Method Details

#to_hHash

Returns a hash representation of the resource content.

Returns:

  • (Hash)

    The hash representation of the resource content.



33
34
35
36
37
38
# File 'lib/action_mcp/content/resource.rb', line 33

def to_h
  resource_data = super.merge(uri: @uri, mimeType: @mime_type)
  resource_data[:text] = @text if @text
  resource_data[:blob] = @blob if @blob
  resource_data
end