Class: TalkToYourApp::Plugins::Db::Plugin
- Inherits:
-
TalkToYourApp::Plugin
- Object
- TalkToYourApp::Plugin
- TalkToYourApp::Plugins::Db::Plugin
- Defined in:
- lib/talk_to_your_app/plugins/db/plugin.rb
Overview
The DB plugin: SQL plus schema introspection against an operator-wired
connection (config.plugin :db, connection: :read). Wired to a :reading
connection (the default role) it is read-only — Rails' write prevention
plus the DB role reject writes. Wired to a :writing connection it can
execute writes; that is a deliberate, documented opt-in (see README).
Class Method Summary collapse
-
.describe_tool(tool_class) ⇒ Object
When wired to a writable connection, advertise that on the db.query tool so an MCP client can tell a write-capable deployment apart from a read-only one.
-
.validate_enablement!(options) ⇒ Object
The DB plugin needs a real connection —
connection: falseis invalid.
Methods inherited from TalkToYourApp::Plugin
log_level, requires_gem, tools, wired_spec
Class Method Details
.describe_tool(tool_class) ⇒ Object
When wired to a writable connection, advertise that on the db.query tool so an MCP client can tell a write-capable deployment apart from a read-only one. Returns nil (use the tool's own description) otherwise.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/talk_to_your_app/plugins/db/plugin.rb', line 58 def self.describe_tool(tool_class) return unless tool_class == Tools::Query conn = TalkToYourApp.configuration.enabled_plugins.dig(:db, :connection) return unless conn && TalkToYourApp::ConnectionRegistry.registered?(conn) return if TalkToYourApp::ConnectionRegistry.fetch(conn).reading? "Run a SQL query and return the rows. This connection is WRITABLE — " \ "UPDATE/INSERT/DELETE/DDL statements will execute." end |
.validate_enablement!(options) ⇒ Object
The DB plugin needs a real connection — connection: false is invalid.
Branch on the wired role: a :reading connection keeps the read-only
guarantee (boot silently); a :writing connection enables writes through
db.query — permitted, but warned loudly. The warning is detection/audit
only; the real safeguard is that the operator had to both declare a
role: :writing connection and wire it here.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/talk_to_your_app/plugins/db/plugin.rb', line 44 def self.validate_enablement!() unless [:connection] raise TalkToYourApp::ConfigurationError, "talk_to_your_app: the DB plugin requires a real connection — " \ "`config.plugin :db, connection: :your_connection`. `connection: false` is not valid." end spec = wired_spec() # nil for an unregistered name (ConnectionRegistry.validate! owns that) warn_writable(spec.name) if spec && !spec.reading? end |