Class: RailsVitals::MCP::Tools::GetRequestLog

Inherits:
Base
  • Object
show all
Defined in:
lib/rails_vitals/mcp/tools/get_request_log.rb

Constant Summary collapse

TOOL_NAME =
"railsvitals_get_request_log"
DEFAULT_LIMIT =
20
DESCRIPTION =
<<~DESC.strip
  Returns recent requests recorded by RailsVitals, ordered most recent first.
  Each entry includes endpoint, health score, query count, total DB time, N+1
  pattern count, and request duration. Use the controller param to scope results
  to a specific controller. Use this to spot whether problems are consistent or
  intermittent and to identify which requests to investigate further.
DESC
INPUT_SCHEMA =
{
  type: "object",
  properties: {
    controller: {
      type: "string",
      description: "Filter by controller name (case-insensitive, partial match). 'Feed' matches FeedController."
    },
    limit: {
      type: "integer",
      description: "Maximum number of requests to return, most recent first. Defaults to 20."
    }
  }
}.freeze

Instance Method Summary collapse

Methods inherited from Base

definition, tool_name

Instance Method Details

#call(params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rails_vitals/mcp/tools/get_request_log.rb', line 30

def call(params)
  records = RailsVitals.store.all
  return no_data_response if records.empty?

  controller_filter = params[:controller] || params["controller"]
  limit = (params[:limit] || params["limit"] || DEFAULT_LIMIT).to_i

  filtered = filter_records(records, controller_filter)
  return no_match_response(controller_filter) if filtered.empty?

  shown = filtered.last(limit).reverse

  {
    total_requests: filtered.size,
    shown: shown.size,
    controller_filter: controller_filter,
    requests: shown.map { |r| serialize(r) }
  }
end