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
- #meta ⇒ 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, meta: 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, meta: nil) ⇒ Resource
Initializes a new Resource content.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/action_mcp/content/resource.rb', line 23 def initialize(uri, mime_type = "text/plain", text: nil, blob: nil, annotations: nil, meta: nil) super("resource", annotations: annotations) @uri = uri @mime_type = mime_type @text = text @blob = blob @annotations = annotations @meta = if .nil? nil elsif .respond_to?(:to_hash) .to_hash elsif .respond_to?(:to_h) .to_h else raise ArgumentError, "meta must respond to :to_hash or :to_h, got: #{.class}" end end |
Instance Attribute Details
#annotations ⇒ String, ... (readonly)
13 14 15 |
# File 'lib/action_mcp/content/resource.rb', line 13 def annotations @annotations end |
#blob ⇒ String, ... (readonly)
13 14 15 |
# File 'lib/action_mcp/content/resource.rb', line 13 def blob @blob end |
#meta ⇒ String, ... (readonly)
13 14 15 |
# File 'lib/action_mcp/content/resource.rb', line 13 def @meta end |
#mime_type ⇒ String, ... (readonly)
13 14 15 |
# File 'lib/action_mcp/content/resource.rb', line 13 def mime_type @mime_type end |
#text ⇒ String, ... (readonly)
13 14 15 |
# File 'lib/action_mcp/content/resource.rb', line 13 def text @text end |
#uri ⇒ String, ... (readonly)
13 14 15 |
# File 'lib/action_mcp/content/resource.rb', line 13 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. ‘meta` is emitted as `_meta` on the inner resource hash (TextResourceContents / BlobResourceContents), not on the outer content envelope.
48 49 50 51 52 53 54 55 56 |
# File 'lib/action_mcp/content/resource.rb', line 48 def to_h inner = { uri: @uri, mimeType: @mime_type } inner[:text] = @text if @text inner[:blob] = @blob if @blob inner[:annotations] = @annotations if @annotations inner[:_meta] = @meta if @meta && !@meta.empty? { type: @type, resource: inner } end |