Class: RailsAiBridge::Tools::GetSchema

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

Overview

MCP tool returning database schema tables, columns, indexes, and foreign keys.

Class Method Summary collapse

Methods inherited from BaseTool

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

Class Method Details

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

Returns schema markdown/JSON or an error message.

Parameters:

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

    when set, return full detail for that table only

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

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

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

    max tables (or rows) depending on formatter defaults

  • offset (Integer) (defaults to: 0)

    pagination offset for table listings

  • format (String) (defaults to: 'markdown')

    +markdown+ or +json+

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

    reserved for MCP transport metadata (unused)

Returns:

  • (MCP::Tool::Response)

    schema markdown/JSON or an error message



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rails_ai_bridge/tools/get_schema.rb', line 53

def self.call(table: nil, detail: 'standard', limit: nil, offset: 0, format: 'markdown', _server_context: nil)
  schema = cached_section(:schema)
  return text_response('Schema introspection not available. Add :schema to introspectors.') unless schema
  return text_response("Schema introspection not available: #{schema[:error]}") if schema[:error]

  formatter = ResponseFormatter.new(schema, table: table, detail: detail, limit: limit, offset: offset,
                                            format: format)
  return text_response(formatter.table_not_found_message) if formatter.table_not_found?

  text_response(formatter.format)
end