Class: RailsMcp::Tools::QueryRecords

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/rails_mcp/tools/query_records.rb

Class Method Summary collapse

Class Method Details

.call(model:, server_context:, conditions: {}, fields: [], limit: nil, offset: 0, order: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails_mcp/tools/query_records.rb', line 25

def self.call(model:, server_context:, conditions: {}, fields: [], limit: nil, offset: 0, order: nil)
  records = Database::RoleProxy.with_role do
    klass = Database::ModelResolver.resolve(model)
    Database::QueryBuilder.new(
      klass,
      conditions: conditions || {},
      fields: Array(fields),
      limit: limit,
      offset: offset || 0,
      order: order
    ).execute
  end
  MCP::Tool::Response.new([{ type: "text", text: records.to_json }])
end