Class: RubyLLM::MCP::Roots

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/mcp/roots.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: [], adapter: nil) ⇒ Roots

Returns a new instance of Roots.



8
9
10
11
# File 'lib/ruby_llm/mcp/roots.rb', line 8

def initialize(paths: [], adapter: nil)
  @paths = paths
  @adapter = adapter
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



6
7
8
# File 'lib/ruby_llm/mcp/roots.rb', line 6

def paths
  @paths
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/ruby_llm/mcp/roots.rb', line 13

def active?
  @paths.any?
end

#add(path) ⇒ Object



17
18
19
20
# File 'lib/ruby_llm/mcp/roots.rb', line 17

def add(path)
  @paths << path
  @adapter.roots_list_change_notification
end

#remove(path) ⇒ Object



22
23
24
25
# File 'lib/ruby_llm/mcp/roots.rb', line 22

def remove(path)
  @paths.delete(path)
  @adapter.roots_list_change_notification
end

#to_hObject



38
39
40
41
42
# File 'lib/ruby_llm/mcp/roots.rb', line 38

def to_h
  {
    paths: to_request
  }
end

#to_requestObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_llm/mcp/roots.rb', line 27

def to_request
  @paths.map do |path|
    name = File.basename(path, ".*")

    {
      uri: "file://#{path}",
      name: name
    }
  end
end