Class: RailsMcpServer::Analyzers::GetSchema

Inherits:
BaseAnalyzer show all
Defined in:
lib/rails-mcp-server/analyzers/get_schema.rb

Constant Summary collapse

FIELD_SEPARATOR =

Tab character for parsing output

"\t"

Instance Method Summary collapse

Instance Method Details

#call(table_name: nil, table_names: nil, detail_level: "full") ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails-mcp-server/analyzers/get_schema.rb', line 7

def call(table_name: nil, table_names: nil, detail_level: "full")
  unless current_project
    message = "No active project. Please switch to a project first."
    log(:warn, message)
    return message
  end

  detail_level = "full" unless %w[tables summary full].include?(detail_level)

  if table_names&.is_a?(Array) && table_names.any?
    invalid_tables = table_names.reject { |t| PathValidator.valid_table_name?(t) }
    if invalid_tables.any?
      return "Invalid table names: #{invalid_tables.join(", ")}. Table names must be alphanumeric with underscores."
    end
    return batch_table_info(table_names)
  end

  if table_name
    unless PathValidator.valid_table_name?(table_name)
      return "Invalid table name: '#{table_name}'. Table names must be alphanumeric with underscores."
    end
    log(:info, "Getting schema for table: #{table_name}")
    return single_table_info(table_name)
  end

  case detail_level
  when "tables"
    tables_list_only
  when "summary"
    tables_with_summary
  when "full"
    full_schema
  end
end