Class: DebugMcp::Tools::RailsRoutes

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/debug_mcp/tools/rails_routes.rb

Class Method Summary collapse

Class Method Details

.call(controller: nil, path: nil, session_id: nil, server_context:) ⇒ Object



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
# File 'lib/debug_mcp/tools/rails_routes.rb', line 39

def call(controller: nil, path: nil, session_id: nil, server_context:)
  client = server_context[:session_manager].client(session_id)
  client.auto_repause!
  RailsHelper.require_rails!(client)

  # Try Base64 script first (better formatting with aligned columns)
  text = fetch_routes_base64(client, controller, path)
  return MCP::Tool::Response.new([{ type: "text", text: text }]) if text

  # Fall back to lightweight approach (works in trap context)
  text = fetch_routes_lightweight(client, controller, path)
  return MCP::Tool::Response.new([{ type: "text", text: text }]) if text

  # Both failed — show clear unavailable message
  text = "Routes: unavailable."
  text += "\n\n#{RailsHelper::TRAP_CONTEXT_HINT}" if RailsHelper.trap_context?(client)
  MCP::Tool::Response.new([{ type: "text", text: text }])
rescue DebugMcp::Error => e
  text = "Error: #{e.message}"
  text += "\n\n#{RailsHelper::TRAP_CONTEXT_HINT}" if begin
    RailsHelper.trap_context?(client)
  rescue StandardError
    false
  end
  MCP::Tool::Response.new([{ type: "text", text: text }])
end