Class: MCPClient::Root
- Inherits:
-
Object
- Object
- MCPClient::Root
- Defined in:
- lib/mcp_client/root.rb
Overview
Represents an MCP Root - a URI that defines a boundary where servers can operate Roots are declared by clients to inform servers about relevant resources and their locations
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.from_json(json) ⇒ Root
Create a Root from a JSON hash.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Check equality.
- #hash ⇒ Object
-
#initialize(uri:, name: nil, meta: nil) ⇒ Root
constructor
Create a new Root.
- #inspect ⇒ Object
-
#to_h ⇒ Hash
Convert to JSON-serializable hash.
-
#to_json ⇒ String
Convert to JSON string.
-
#to_s ⇒ Object
String representation.
Constructor Details
#initialize(uri:, name: nil, meta: nil) ⇒ Root
Create a new Root
18 19 20 21 22 23 24 25 26 |
# File 'lib/mcp_client/root.rb', line 18 def initialize(uri:, name: nil, meta: nil) validate_uri!(uri) # Root._meta is an object of arbitrary keys per the schema raise ArgumentError, "Root _meta must be a Hash, got #{.class}" if && !.is_a?(Hash) @uri = uri @name = name @meta = end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
9 10 11 |
# File 'lib/mcp_client/root.rb', line 9 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/mcp_client/root.rb', line 9 def name @name end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/mcp_client/root.rb', line 9 def uri @uri end |
Class Method Details
.from_json(json) ⇒ Root
Create a Root from a JSON hash
32 33 34 35 36 37 38 |
# File 'lib/mcp_client/root.rb', line 32 def self.from_json(json) new( uri: json['uri'] || json[:uri], name: json['name'] || json[:name], meta: json['_meta'] || json[:_meta] ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Check equality
56 57 58 59 60 |
# File 'lib/mcp_client/root.rb', line 56 def ==(other) return false unless other.is_a?(Root) uri == other.uri && name == other.name && == other. end |
#hash ⇒ Object
64 65 66 |
# File 'lib/mcp_client/root.rb', line 64 def hash [uri, name, ].hash end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/mcp_client/root.rb', line 73 def inspect "#<MCPClient::Root uri=#{uri.inspect} name=#{name.inspect}>" end |
#to_h ⇒ Hash
Convert to JSON-serializable hash
42 43 44 45 46 47 |
# File 'lib/mcp_client/root.rb', line 42 def to_h result = { 'uri' => @uri } result['name'] = @name if @name result['_meta'] = @meta if @meta result end |
#to_json ⇒ String
Convert to JSON string
51 52 53 |
# File 'lib/mcp_client/root.rb', line 51 def to_json(*) to_h.to_json(*) end |
#to_s ⇒ Object
String representation
69 70 71 |
# File 'lib/mcp_client/root.rb', line 69 def to_s name ? "#{name} (#{uri})" : uri end |