Class: RailsVitals::MCP::Tools::GetScore

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

Constant Summary collapse

TOOL_NAME =
"railsvitals_get_score"
DESCRIPTION =
<<~DESC.strip
  Returns the composite health score for the Rails app based on recent requests
  recorded by RailsVitals. Includes a grade, per-component score breakdown
  (query count and N+1 patterns), penalty details, and a projected score that
  shows how much improvement fixing all N+1 patterns would yield.
  Call this first to get a high-level diagnosis before drilling into specifics.
DESC
INPUT_SCHEMA =
{
  type: "object",
  properties: {}
}.freeze
WEIGHTS =
Scorers::CompositeScorer::WEIGHTS

Instance Method Summary collapse

Methods included from Calculable

#average, #percentage

Methods inherited from Base

definition, tool_name

Instance Method Details

#call(_params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_vitals/mcp/tools/get_score.rb', line 23

def call(_params)
  records = RailsVitals.store.all

  return no_data_response if records.empty?

  overall_score = average(records, :score)

  {
    overall_score: overall_score,
    grade: grade_for(overall_score),
    color: color_for(overall_score),
    requests_analyzed: records.size,
    score_breakdown: build_score_breakdown(records),
    penalties: build_penalties(records),
    projected_score_if_n1_fixed: projected_score(records)
  }
end