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 ⇒ Object
readonly
Returns the value of attribute annotations.
-
#blob ⇒ String?
readonly
Base64-encoded binary content (mutually exclusive with text).
-
#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) ⇒ 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) ⇒ ResourceContent
Initialize resource content
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mcp_client/resource_content.rb', line 31 def initialize(uri:, name:, title: nil, mime_type: nil, text: nil, blob: nil, annotations: 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 ⇒ Object (readonly)
Returns the value of attribute annotations.
21 |
# File 'lib/mcp_client/resource_content.rb', line 21 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations |
#blob ⇒ String? (readonly)
Returns base64-encoded binary content (mutually exclusive with text).
21 |
# File 'lib/mcp_client/resource_content.rb', line 21 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations |
#mime_type ⇒ String? (readonly)
Returns optional MIME type.
21 |
# File 'lib/mcp_client/resource_content.rb', line 21 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations |
#name ⇒ String (readonly)
Returns the name of the resource.
21 |
# File 'lib/mcp_client/resource_content.rb', line 21 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations |
#text ⇒ String? (readonly)
Returns text content (mutually exclusive with blob).
21 |
# File 'lib/mcp_client/resource_content.rb', line 21 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations |
#title ⇒ String? (readonly)
Returns optional human-readable name for display purposes.
21 |
# File 'lib/mcp_client/resource_content.rb', line 21 attr_reader :uri, :name, :title, :mime_type, :text, :blob, :annotations |
#uri ⇒ String (readonly)
Returns unique identifier for the resource.
21 22 23 |
# File 'lib/mcp_client/resource_content.rb', line 21 def uri @uri end |
Class Method Details
.from_json(data) ⇒ MCPClient::ResourceContent
Create a ResourceContent instance from JSON data
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mcp_client/resource_content.rb', line 47 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'] ) end |
Instance Method Details
#binary? ⇒ Boolean
Check if content is binary
67 68 69 |
# File 'lib/mcp_client/resource_content.rb', line 67 def binary? !@blob.nil? end |
#content ⇒ String
Get the content (text or decoded blob)
73 74 75 76 77 78 |
# File 'lib/mcp_client/resource_content.rb', line 73 def content return @text if text? require 'base64' Base64.decode64(@blob) end |
#text? ⇒ Boolean
Check if content is text
61 62 63 |
# File 'lib/mcp_client/resource_content.rb', line 61 def text? !@text.nil? end |