Class: Rubydex::MCPServer::GetDescendantsTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rubydex/mcp_server/tools/get_descendants_tool.rb

Constant Summary

Constants inherited from BaseTool

BaseTool::DEFAULT_LIMIT

Instance Method Summary collapse

Methods inherited from BaseTool

#declaration_kind, #display_location, #document_for_path, #file_path_for_uri, #format_path, #initialize, #lookup_declaration, #paginate, #response

Methods inherited from Tool

description, inherited, input_schema, to_h, tool_name, tools_by_name

Constructor Details

This class inherits a constructor from Rubydex::MCPServer::BaseTool

Instance Method Details

#call(name:, limit: nil, offset: nil) ⇒ Object

: (name: String, ?limit: Integer, ?offset: Integer) -> Tool::Response



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rubydex/mcp_server/tools/get_descendants_tool.rb', line 18

def call(name:, limit: nil, offset: nil)
  declaration = lookup_declaration(name)

  case declaration
  when Error
    response(declaration)
  when Rubydex::Namespace
    page, total = paginate(declaration.descendants, offset, limit, 500)
    descendants = page.map do |descendant|
      {
        name: descendant.name,
        kind: declaration_kind(descendant),
      }
    end

    response(name: declaration.name, descendants: descendants, total: total)
  else
    response(
      Error.new(
        "invalid_kind",
        "'#{name}' is not a class or module (it is a #{declaration_kind(declaration)})",
        "get_descendants only works on classes and modules, not methods or constants",
      ),
    )
  end
end