Class: MCPClient::ResourceContent
- Inherits:
-
Object
- Object
- MCPClient::ResourceContent
- Defined in:
- lib/mcp_client/resource_content.rb
Overview
Representation of MCP resource content Resources can contain either text or binary data
Instance Attribute Summary collapse
-
#annotations ⇒ Hash?
readonly
Optional annotations that provide hints to clients.
-
#blob ⇒ String?
readonly
Base64-encoded binary content (mutually exclusive with text).
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#mime_type ⇒ String?
readonly
Optional MIME type.
-
#name ⇒ String
readonly
The name of the resource.
-
#text ⇒ String?
readonly
Text content (mutually exclusive with blob).
-
#title ⇒ String?
readonly
Optional human-readable name for display purposes.
-
#uri ⇒ String
readonly
Unique identifier for the resource.
Class Method Summary collapse
-
.from_json(data) ⇒ MCPClient::ResourceContent
Create a ResourceContent instance from JSON data.
Instance Method Summary collapse
-
#binary? ⇒ Boolean
Check if content is binary.
-
#content ⇒ String
Get the content (text or decoded blob).
-
#initialize(uri:, name:, title: nil, mime_type: nil, text: nil, blob: nil, annotations: nil, meta: nil) ⇒ ResourceContent
constructor
Initialize resource content.
-
#text? ⇒ Boolean
Check if content is text.
Constructor Details
#initialize(uri:, name:, title: nil, mime_type: nil, text: nil, blob: nil, annotations: nil, meta: nil) ⇒ ResourceContent
Initialize resource content
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mcp_client/resource_content.rb', line 34 def initialize(uri:, name:, title: nil, mime_type: nil, text: nil, blob: nil, annotations: nil, meta: nil) raise ArgumentError, 'ResourceContent cannot have both text and blob' if text && blob raise ArgumentError, 'ResourceContent must have either text or blob' if !text && !blob @uri = uri @name = name @title = title @mime_type = mime_type @text = text @blob = blob @annotations = annotations @meta = end |
Instance Attribute Details
#annotations ⇒ Hash? (readonly)
Returns optional annotations that provide hints to clients.
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#blob ⇒ String? (readonly)
Returns base64-encoded binary content (mutually exclusive with text).
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#mime_type ⇒ String? (readonly)
Returns optional MIME type.
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#name ⇒ String (readonly)
Returns the name of the resource.
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#text ⇒ String? (readonly)
Returns text content (mutually exclusive with blob).
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#title ⇒ String? (readonly)
Returns optional human-readable name for display purposes.
23 |
# File 'lib/mcp_client/resource_content.rb', line 23 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#uri ⇒ String (readonly)
Returns unique identifier for the resource.
23 24 25 |
# File 'lib/mcp_client/resource_content.rb', line 23 def uri @uri end |
Class Method Details
.from_json(data) ⇒ MCPClient::ResourceContent
Create a ResourceContent instance from JSON data
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mcp_client/resource_content.rb', line 51 def self.from_json(data) new( uri: data['uri'], name: data['name'], title: data['title'], mime_type: data['mimeType'], text: data['text'], blob: data['blob'], annotations: data['annotations'], meta: data['_meta'] ) end |
Instance Method Details
#binary? ⇒ Boolean
Check if content is binary
72 73 74 |
# File 'lib/mcp_client/resource_content.rb', line 72 def binary? !@blob.nil? end |
#content ⇒ String
Get the content (text or decoded blob)
78 79 80 81 82 83 |
# File 'lib/mcp_client/resource_content.rb', line 78 def content return @text if text? require 'base64' Base64.decode64(@blob) end |
#text? ⇒ Boolean
Check if content is text
66 67 68 |
# File 'lib/mcp_client/resource_content.rb', line 66 def text? !@text.nil? end |