Class: ActionMCP::Content::Base
- Inherits:
-
Object
- Object
- ActionMCP::Content::Base
- Defined in:
- lib/action_mcp/content.rb,
lib/action_mcp/content/base.rb
Overview
Base class for all content types, supporting annotations.
Direct Known Subclasses
Instance Attribute Summary collapse
- #annotations ⇒ Symbol, ... readonly
- #type ⇒ Symbol, ... readonly
Instance Method Summary collapse
-
#initialize(type, annotations: nil) ⇒ Base
constructor
Initializes a new content base.
-
#to_h ⇒ Hash
Returns a hash representation of the base content.
-
#to_json ⇒ String
Returns a JSON representation of the content.
Constructor Details
#initialize(type, annotations: nil) ⇒ Base
Initializes a new content base.
16 17 18 19 |
# File 'lib/action_mcp/content.rb', line 16 def initialize(type, annotations: nil) @type = type @annotations = annotations end |
Instance Attribute Details
#annotations ⇒ Symbol, ... (readonly)
10 11 12 |
# File 'lib/action_mcp/content.rb', line 10 def annotations @annotations end |
#type ⇒ Symbol, ... (readonly)
10 11 12 |
# File 'lib/action_mcp/content.rb', line 10 def type @type end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the base content.
24 25 26 27 28 |
# File 'lib/action_mcp/content.rb', line 24 def to_h h = { type: @type } h[:annotations] = @annotations if @annotations h end |
#to_json ⇒ String
Returns a JSON representation of the content.
33 34 35 |
# File 'lib/action_mcp/content.rb', line 33 def to_json(*) MultiJson.dump(to_h, *) end |