Class: ExplainBaseTool

Inherits:
FastMcp::Tool
  • Object
show all
Defined in:
lib/rails-pg-extras-mcp.rb

Direct Known Subclasses

ExplainAnalyzeTool, ExplainTool

Constant Summary collapse

DENYLIST =
%w[
  delete,
  insert,
  update,
  truncate,
  drop,
  alter,
  create,
  grant,
  begin,
  commit,
  ;
]

Instance Method Summary collapse

Instance Method Details

#call(query:) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rails-pg-extras-mcp.rb', line 86

def call(query:)
  connection = RailsPgExtras.connection

  if DENYLIST.any? { |deny| query.downcase.include?(deny) }
    raise "This query is not allowed. It contains a denied keyword. Denylist: #{DENYLIST.join(", ")}"
  end

  connection.execute("BEGIN")
  result = connection.execute("#{query}")
  connection.execute("ROLLBACK")

  result.to_a
end