Repository navigation
Show and tell: End-to-End Walkthrough — Hardening Database MCP Connectors Against Hallucinated LLM Mutations #4385
Replies: 2 comments
|
The connector allows |
|
@wilsonccccc Excellent and critical question — this hits the exact boundary where application-level inspection ends and database engine enforcement must take over. 1. The Side-Effecting Function / UDF ThreatYou are completely right: in PostgreSQL, a query like Because an application-level token/regex scanner only inspects query tokens and does not have access to PostgreSQL's system catalogs (to know whether a function's volatility is 2. Runtime Read-Only Transaction EnforcementTo address this, our layered architecture pairs token inspection with runtime engine enforcement:
When 3. Why Keep Application-Level Token Inspection?If
I've also updated our setup guide and walkthrough example (examples/SAFE_POSTGRES_MCP_WALKTHROUGH.md) to make |
Uh oh!
There was an error while loading. Please reload this page.
Disclosure: Maintainer of MCP Production Kit (listed in
docs/frameworks.mdvia PR #4192). Posting in Show and tell to share a practical implementation walkthrough for safely connecting AI coding agents (Claude Desktop, Cursor, Cline) to relational databases without exposing production systems to destructive mutations.The Problem: Why Toy Database Tools Are Risky
Most basic MCP database tools pass raw SQL directly from the LLM prompt to the database driver. If the connection possesses write permissions, a prompt injection or hallucination can execute
DROP TABLE,DELETE, or chained SQL statements with zero application-layer defense.Relying solely on database credentials can also fail if the connection string uses a service-role or shared credential. A defense-in-depth architecture requires both least-privilege database roles and application-level query validation.
End-to-End Practical Walkthrough
We created a runnable verification script (examples/secure_database_agent_walkthrough.ts) demonstrating four critical guardrails:
(Note: This is an application-level token & regex sanitization guardrail, not a full SQL AST compiler, and is designed to work alongside PostgreSQL
GRANT SELECTand read-only roles).Free Open-Source Core vs. Turnkey Commercial Add-on
stdio+ Node.js HTTP/SSEstdio+ Node.js HTTP/SSEpostgres_connector.tswith 12 security unit testscloudflare_worker.ts)Questions & Objections for Discussion
We would love to gather real-world developer perspectives:
All reactions