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.
-
#initialize_copy(source) ⇒ void
A copy that shares nothing mutable with the original (cached contents are handed out as copies, so a caller's edits stay its own).
-
#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
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mcp_client/resource_content.rb', line 36 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 = end |
Instance Attribute Details
#annotations ⇒ Hash? (readonly)
Returns optional annotations that provide hints to clients.
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#blob ⇒ String? (readonly)
Returns base64-encoded binary content (mutually exclusive with text).
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#mime_type ⇒ String? (readonly)
Returns optional MIME type.
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#name ⇒ String (readonly)
Returns the name of the resource.
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#text ⇒ String? (readonly)
Returns text content (mutually exclusive with blob).
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#title ⇒ String? (readonly)
Returns optional human-readable name for display purposes.
25 |
# File 'lib/mcp_client/resource_content.rb', line 25 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations, :meta |
#uri ⇒ String (readonly)
Returns unique identifier for the resource.
25 26 27 |
# File 'lib/mcp_client/resource_content.rb', line 25 def uri @uri end |
Class Method Details
.from_json(data) ⇒ MCPClient::ResourceContent
Create a ResourceContent instance from JSON data
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mcp_client/resource_content.rb', line 71 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
92 93 94 |
# File 'lib/mcp_client/resource_content.rb', line 92 def binary? !@blob.nil? end |
#content ⇒ String
Get the content (text or decoded blob)
98 99 100 101 102 103 |
# File 'lib/mcp_client/resource_content.rb', line 98 def content return @text if text? require 'base64' Base64.decode64(@blob) end |
#initialize_copy(source) ⇒ void
This method returns an undefined value.
A copy that shares nothing mutable with the original (cached contents are handed out as copies, so a caller's edits stay its own).
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mcp_client/resource_content.rb', line 54 def initialize_copy(source) super @uri = source.uri.dup if source.uri @name = source.name.dup if source.name @title = source.title.dup if source.title @mime_type = source.mime_type.dup if source.mime_type @text = source.text.dup if source.text @blob = source.blob.dup if source.blob # Iterative: peer-supplied annotations or _meta may be nested deeper # than the Ruby stack allows. @annotations = MCPClient::DeepCopy.copy(source.annotations) = MCPClient::DeepCopy.copy(source.) end |
#text? ⇒ Boolean
Check if content is text
86 87 88 |
# File 'lib/mcp_client/resource_content.rb', line 86 def text? !@text.nil? end |