Class: ActionMCP::Content::Resource
- 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
- #annotations ⇒ String? readonly
- #blob ⇒ String? readonly
- #mime_type ⇒ String? readonly
- #text ⇒ String? readonly
- #uri ⇒ String? readonly
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(uri, mime_type = "text/plain", text: nil, blob: nil, annotations: nil) ⇒ Resource
constructor
Initializes a new Resource content.
-
#to_h ⇒ Hash
Returns a hash representation of the resource content.
Methods inherited from Base
Constructor Details
#initialize(uri, mime_type = "text/plain", text: nil, blob: nil, annotations: nil) ⇒ Resource
Initializes a new Resource content.
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
#annotations ⇒ String? (readonly)
12 13 14 |
# File 'lib/action_mcp/content/resource.rb', line 12 def annotations @annotations end |
#blob ⇒ String? (readonly)
12 13 14 |
# File 'lib/action_mcp/content/resource.rb', line 12 def blob @blob end |
#mime_type ⇒ String? (readonly)
12 13 14 |
# File 'lib/action_mcp/content/resource.rb', line 12 def mime_type @mime_type end |
#text ⇒ String? (readonly)
12 13 14 |
# File 'lib/action_mcp/content/resource.rb', line 12 def text @text end |
#uri ⇒ String? (readonly)
12 13 14 |
# File 'lib/action_mcp/content/resource.rb', line 12 def uri @uri end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the resource content. Per MCP spec, embedded resources have type “resource” with a nested resource object.
34 35 36 37 38 39 40 41 |
# File 'lib/action_mcp/content/resource.rb', line 34 def to_h inner = { uri: @uri, mimeType: @mime_type } inner[:text] = @text if @text inner[:blob] = @blob if @blob inner[:annotations] = @annotations if @annotations { type: @type, resource: inner } end |