Class: OpenGemdocs::MCP::Tools

Inherits:
Object
  • Object
show all
Defined in:
lib/open_gemdocs/mcp/tools.rb

Instance Method Summary collapse

Constructor Details

#initializeTools

Returns a new instance of Tools.



10
11
12
13
14
# File 'lib/open_gemdocs/mcp/tools.rb', line 10

def initialize
  # Ensure we can access the Yard module
  require_relative "../yard"
  require_relative "../yard_json_formatter"
end

Instance Method Details

#call(tool_name, arguments) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/open_gemdocs/mcp/tools.rb', line 109

def call(tool_name, arguments)
  case tool_name
  when "search_gems"
    search_gems(arguments["query"])
  when "get_gem_info"
    get_gem_info(arguments["gem_name"])
  when "start_yard_server"
    start_yard_server
  when "stop_yard_server"
    stop_yard_server
  when "get_yard_server_status"
    get_yard_server_status
  when "get_gem_documentation_url"
    get_gem_documentation_url(arguments["gem_name"], arguments["class_name"])
  when "fetch_gem_docs"
    fetch_gem_docs(arguments["gem_name"], arguments["path"])
  else
    {
      "content" => [{
        "type" => "text",
        "text" => "Unknown tool: #{tool_name}"
      }],
      "isError" => true
    }
  end
end

#listObject



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/open_gemdocs/mcp/tools.rb', line 16

def list
  [
    {
      "name" => "search_gems",
      "description" => "Search for installed Ruby gems",
      "inputSchema" => {
        "type" => "object",
        "properties" => {
          "query" => {
            "type" => "string",
            "description" => "Search query for gem names (partial match supported)"
          }
        },
        "required" => ["query"]
      }
    },
    {
      "name" => "get_gem_info",
      "description" => "Get information about a specific gem including version and summary",
      "inputSchema" => {
        "type" => "object",
        "properties" => {
          "gem_name" => {
            "type" => "string",
            "description" => "Exact name of the gem"
          }
        },
        "required" => ["gem_name"]
      }
    },
    {
      "name" => "start_yard_server",
      "description" => "Start the Yard documentation server",
      "inputSchema" => {
        "type" => "object",
        "properties" => {}
      }
    },
    {
      "name" => "stop_yard_server",
      "description" => "Stop the Yard documentation server",
      "inputSchema" => {
        "type" => "object",
        "properties" => {}
      }
    },
    {
      "name" => "get_yard_server_status",
      "description" => "Check if the Yard documentation server is running",
      "inputSchema" => {
        "type" => "object",
        "properties" => {}
      }
    },
    {
      "name" => "get_gem_documentation_url",
      "description" => "Get the local documentation URL for a gem (Note: Use fetch_gem_docs instead to get actual documentation content)",
      "inputSchema" => {
        "type" => "object",
        "properties" => {
          "gem_name" => {
            "type" => "string",
            "description" => "Name of the gem"
          },
          "class_name" => {
            "type" => "string",
            "description" => "Optional: specific class or module name"
          }
        },
        "required" => ["gem_name"]
      }
    },
    {
      "name" => "fetch_gem_docs",
      "description" => "Fetch structured documentation content for a gem or specific class/module. Returns formatted documentation with methods, attributes, parameters, and examples. Use this instead of fetching URLs directly.",
      "inputSchema" => {
        "type" => "object",
        "properties" => {
          "gem_name" => {
            "type" => "string",
            "description" => "Name of the gem"
          },
          "path" => {
            "type" => "string",
            "description" => 'Optional: specific class or module path (e.g., "FactoryBot::Trait" or "ActiveRecord::Base")'
          }
        },
        "required" => ["gem_name"]
      }
    }
  ]
end