Class: ActionMCP::Resource

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

Overview

Represents a resource with its metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



5
6
7
# File 'lib/action_mcp/resource.rb', line 5

def description
  @description
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type

Returns:

  • (Object)

    the current value of mime_type



5
6
7
# File 'lib/action_mcp/resource.rb', line 5

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/action_mcp/resource.rb', line 5

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



5
6
7
# File 'lib/action_mcp/resource.rb', line 5

def size
  @size
end

#uriObject (readonly)

Returns the value of attribute uri

Returns:

  • (Object)

    the current value of uri



5
6
7
# File 'lib/action_mcp/resource.rb', line 5

def uri
  @uri
end

Instance Method Details

#to_hHash

Convert the resource to a hash with the keys expected by MCP. Note: The key for mime_type is converted to ‘mimeType’ as specified.

Returns:

  • (Hash)

    A hash representation of the resource.



10
11
12
13
14
15
16
# File 'lib/action_mcp/resource.rb', line 10

def to_h
  hash = { uri: uri, name: name }
  hash[:description] = description if description
  hash[:mimeType]   = mime_type if mime_type
  hash[:size]       = size if size
  hash
end

#to_jsonObject



18
19
20
# File 'lib/action_mcp/resource.rb', line 18

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