Class: ActionMCP::Content::ResourceLink

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

Overview

ResourceLink represents a link to a resource that the server is capable of reading. It’s included in a prompt or tool call result. Note: resource links returned by tools are not guaranteed to appear in resources/list requests.

Instance Attribute Summary collapse

Attributes inherited from Base

#annotations, #type

Instance Method Summary collapse

Methods inherited from Base

#to_json

Constructor Details

#initialize(uri, name: nil, description: nil, mime_type: nil, annotations: nil) ⇒ ResourceLink

Initializes a new ResourceLink content.

Parameters:

  • uri (String)

    The URI of the resource.

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

    The name of the resource (optional).

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

    The description of the resource (optional).

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

    The MIME type of the resource (optional).

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

    Optional annotations for the resource link.



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

def initialize(uri, name: nil, description: nil, mime_type: nil, annotations: nil)
  super("resource_link", annotations: annotations)
  @uri = uri
  @name = name
  @description = description
  @mime_type = mime_type
end

Instance Attribute Details

#descriptionString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String, nil)

    The name of the resource (optional).

  • (String, nil)

    The description of the resource (optional).

  • (String, nil)

    The MIME type of the resource (optional).



13
14
15
# File 'lib/action_mcp/content/resource_link.rb', line 13

def description
  @description
end

#mime_typeString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String, nil)

    The name of the resource (optional).

  • (String, nil)

    The description of the resource (optional).

  • (String, nil)

    The MIME type of the resource (optional).



13
14
15
# File 'lib/action_mcp/content/resource_link.rb', line 13

def mime_type
  @mime_type
end

#nameString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String, nil)

    The name of the resource (optional).

  • (String, nil)

    The description of the resource (optional).

  • (String, nil)

    The MIME type of the resource (optional).



13
14
15
# File 'lib/action_mcp/content/resource_link.rb', line 13

def name
  @name
end

#uriString? (readonly)

Returns:

  • (String)

    The URI of the resource.

  • (String, nil)

    The name of the resource (optional).

  • (String, nil)

    The description of the resource (optional).

  • (String, nil)

    The MIME type of the resource (optional).



13
14
15
# File 'lib/action_mcp/content/resource_link.rb', line 13

def uri
  @uri
end

Instance Method Details

#to_hHash

Returns a hash representation of the resource link content.

Returns:

  • (Hash)

    The hash representation of the resource link content.



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

def to_h
  result = super.merge(uri: @uri)
  result[:name] = @name if @name
  result[:description] = @description if @description
  result[:mimeType] = @mime_type if @mime_type
  result
end