Class: MCPClient::Root Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_client/root.rb

Overview

Deprecated.

Roots is deprecated since MCP 2026-07-28 (SEP-2577); earliest removal is the first revision released on or after 2027-07-28. The class keeps working for as long as the feature does, and building one raises no notice — using the list does. Pass directories or files through tool parameters, resource URIs or server configuration instead.

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, meta: nil) ⇒ Root

Create a new Root

Parameters:

  • uri (String) —

    The URI for the root. Per the MCP specification this MUST be a file:// URI ("This MUST be a file:// URI in the current specification" - client/roots.mdx, 2025-11-25)

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

    Optional human-readable name for display purposes

  • meta (Hash, nil) (defaults to: nil) —

    Optional _meta field attached to the root (schema.ts Root._meta)

Raises:

  • (ArgumentError) —

    if uri is not a valid file:// URI or contains '..' path segments



24
25
26
27
28
29
30
31
32
# File 'lib/mcp_client/root.rb', line 24

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 #{meta.class}" if meta && !meta.is_a?(Hash)

  @uri = uri
  @name = name
  @meta = meta
end

Instance Attribute Details

#meta ⇒ Object (readonly)

Returns the value of attribute meta.



15
16
17
# File 'lib/mcp_client/root.rb', line 15

def meta
  @meta
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/mcp_client/root.rb', line 15

def name
  @name
end

#uri ⇒ Object (readonly)

Returns the value of attribute uri.



15
16
17
# File 'lib/mcp_client/root.rb', line 15

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' and '_meta' keys

Returns:

Raises:

  • (ArgumentError) —

    if the uri is missing or not a valid file:// URI



38
39
40
41
42
43
44
# File 'lib/mcp_client/root.rb', line 38

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



62
63
64
65
66
# File 'lib/mcp_client/root.rb', line 62

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

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

#hash ⇒ Object



70
71
72
# File 'lib/mcp_client/root.rb', line 70

def hash
  [uri, name, meta].hash
end

#inspect ⇒ Object



79
80
81
# File 'lib/mcp_client/root.rb', line 79

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

#to_h ⇒ Hash

Convert to JSON-serializable hash

Returns:

  • (Hash)


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

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

Returns:

  • (String)


57
58
59
# File 'lib/mcp_client/root.rb', line 57

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

#to_s ⇒ Object

String representation



75
76
77
# File 'lib/mcp_client/root.rb', line 75

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