Class: Rubydex::MCPServer::GetDeclarationTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rubydex/mcp_server/tools/get_declaration_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:) ⇒ Object

: (name: String) -> Tool::Response



16
17
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubydex/mcp_server/tools/get_declaration_tool.rb', line 16

def call(name:)
  declaration = lookup_declaration(name)

  case declaration
  when Error
    response(declaration)
  else
    definitions = declaration.definitions.map do |definition|
      display_location(definition.location).merge(
        comments: definition.comments.map do |comment|
          comment.string.delete_prefix("# ")
        end,
      )
    end

    ancestors = if declaration.is_a?(Rubydex::Namespace)
      declaration.ancestors.map do |ancestor|
        {
          name: ancestor.name,
          kind: declaration_kind(ancestor),
        }
      end
    else
      []
    end

    members = if declaration.is_a?(Rubydex::Namespace)
      declaration.members.map do |member|
        payload = {
          name: member.name,
          kind: declaration_kind(member),
        }

        definition = member.definitions.first
        payload[:location] = display_location(definition.location) if definition
        payload
      end
    else
      []
    end

    response(
      name: declaration.name,
      kind: declaration_kind(declaration),
      definitions: definitions,
      ancestors: ancestors,
      members: members,
    )
  end
end