Class: RailsAiBridge::Tools::GetRoutes

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/get_routes.rb

Overview

MCP tool listing routes with optional controller filter, detail level, and pagination.

Class Method Summary collapse

Methods inherited from BaseTool

cached_context, cached_section, config, rails_app, reset_cache!, text_response

Class Method Details

.call(controller: nil, detail: 'standard', limit: nil, offset: 0, _server_context: nil) ⇒ MCP::Tool::Response

Returns markdown routes output or an error message.

Parameters:

  • controller (String, nil) (defaults to: nil)

    filter by controller path/name

  • detail (String) (defaults to: 'standard')

    +summary+, +standard+, or +full+

  • limit (Integer, nil) (defaults to: nil)

    max routes to include

  • offset (Integer) (defaults to: 0)

    pagination offset

  • _server_context (Object, nil) (defaults to: nil)

    reserved for MCP transport metadata (unused)

Returns:

  • (MCP::Tool::Response)

    markdown routes output or an error message



41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_ai_bridge/tools/get_routes.rb', line 41

def self.call(controller: nil, detail: 'standard', limit: nil, offset: 0, _server_context: nil)
  routes = cached_section(:routes)
  return text_response('Route introspection not available. Add :routes to introspectors.') unless routes
  return text_response("Route introspection failed: #{routes[:error]}") if routes[:error]

  formatter = ResponseFormatter.new(routes, controller: controller, detail: detail, limit: limit, offset: offset)
  return text_response(formatter.filter_error_message) if formatter.filter_error?

  text_response(formatter.format)
end