Class: RailsAiBridge::Tools::GetModelDetails

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

Overview

MCP tool returning ActiveRecord model metadata, optional non-AR +app/models+ listings, and configurable list detail for all models.

Class Method Summary collapse

Methods inherited from BaseTool

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

Class Method Details

.call(model: nil, detail: 'standard', _server_context: nil) ⇒ MCP::Tool::Response

Returns Markdown for one model or for a full listing.

Reads +:models+ and, when present, +:non_ar_models+ from BaseTool.cached_section. When +model+ matches a non-AR entry and not an ActiveRecord key, returns a short POJO summary.

Parameters:

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

    ActiveRecord class name for full detail via ModelDetails::SingleModelFormatter; omit to list all ActiveRecord models with +detail+.

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

    +summary+, +standard+, or +full+ when listing (ignored when +model+ is set)

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

    reserved for MCP transport metadata (unused)

Returns:

  • (MCP::Tool::Response)

    Markdown body or an error string wrapped for the MCP client



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

def self.call(model: nil, detail: 'standard', _server_context: nil)
  models = cached_section(:models)
  return text_response('Model introspection not available. Add :models to introspectors.') unless models
  return text_response("Model introspection failed: #{models[:error]}") if models[:error]

  non_ar = cached_section(:non_ar_models)
  formatter = ResponseFormatter.new(models, model: model, detail: detail, non_ar_models: non_ar)
  return text_response(formatter.model_not_found_message) if formatter.model_not_found?
  return text_response(formatter.model_error_message) if formatter.model_error?

  text_response(formatter.format)
end