Class: MCPClient::Root

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, name: nil) ⇒ Root

Create a new Root

Parameters:

  • uri (String)

    The URI for the root (typically file:// URI)

  • name (String, nil) (defaults to: nil)

    Optional human-readable name for display purposes



12
13
14
15
# File 'lib/mcp_client/root.rb', line 12

def initialize(uri:, name: nil)
  @uri = uri
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/mcp_client/root.rb', line 7

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/mcp_client/root.rb', line 7

def uri
  @uri
end

Class Method Details

.from_json(json) ⇒ Root

Create a Root from a JSON hash

Parameters:

  • json (Hash)

    The JSON hash with ‘uri’ and optional ‘name’ keys

Returns:



20
21
22
23
24
25
# File 'lib/mcp_client/root.rb', line 20

def self.from_json(json)
  new(
    uri: json['uri'] || json[:uri],
    name: json['name'] || json[:name]
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Check equality



42
43
44
45
46
# File 'lib/mcp_client/root.rb', line 42

def ==(other)
  return false unless other.is_a?(Root)

  uri == other.uri && name == other.name
end

#hashObject



50
51
52
# File 'lib/mcp_client/root.rb', line 50

def hash
  [uri, name].hash
end

#inspectObject



59
60
61
# File 'lib/mcp_client/root.rb', line 59

def inspect
  "#<MCPClient::Root uri=#{uri.inspect} name=#{name.inspect}>"
end

#to_hHash

Convert to JSON-serializable hash

Returns:

  • (Hash)


29
30
31
32
33
# File 'lib/mcp_client/root.rb', line 29

def to_h
  result = { 'uri' => @uri }
  result['name'] = @name if @name
  result
end

#to_jsonString

Convert to JSON string

Returns:

  • (String)


37
38
39
# File 'lib/mcp_client/root.rb', line 37

def to_json(*)
  to_h.to_json(*)
end

#to_sObject

String representation



55
56
57
# File 'lib/mcp_client/root.rb', line 55

def to_s
  name ? "#{name} (#{uri})" : uri
end