Class: RailsVitals::MCP::Tools::GetSchemaContext

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

Constant Summary collapse

TOOL_NAME =
"railsvitals_get_schema_context"
DESCRIPTION =
<<~DESC.strip
  Returns schema context for ActiveRecord models: columns with types, indexes,
  associations, and foreign keys missing an index. Use the models param to scope
  to specific models; omit it to get all models. Use this to understand your data
  model structure and spot missing indexes that could be causing slow queries or
  N+1 patterns.
DESC
INPUT_SCHEMA =
{
  type: "object",
  properties: {
    models: {
      type: "array",
      items: { type: "string" },
      description: "Model names to include (e.g. ['Post', 'User']). Omit to return all models."
    }
  }
}.freeze

Instance Method Summary collapse

Methods inherited from Base

definition, tool_name

Instance Method Details

#call(params) ⇒ Object



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

def call(params)
  requested = Array(params[:models] || params["models"]).map(&:to_s)

  all_models = Analyzers::AssociationMapper.discover_models
  models = requested.empty? ? all_models : filter_models(all_models, requested)

  return no_models_response(requested) if models.empty?

  {
    models_analyzed: models.size,
    models: models.map { |m| serialize_model(m) }
  }
end