Let AI agents work on your database without being able to wreck it: a key per agent with its own Postgres role, a query firewall, human approval for risky statements, a full query log and one-click undo of an agent session.
Agent keys
One key per agent, with its own Postgres role and limits.
Query firewall
What agents may run, checked by the real Postgres parser.
Approvals
Risky statements wait for a person.
Sessions and undo
Revert everything one agent session changed.
MCP and direct connections
Use a key with Claude, ChatGPT, Cursor or psql.
Exposure check
See what anonymous visitors can read and write.
#Why
An AI agent with your database password or service role key can do anything: drop a table, delete every row, read every user's data. Agent keys give each agent exactly what its job needs, and keep a person in the loop for the rest.
| Layer | What it does |
|---|---|
| Postgres role | Each key has its own role with only the grants of its preset and table list. Row Level Security applies. This is enforced by Postgres itself, whatever SQL the agent sends. |
| Firewall | Every statement sent through the API or MCP is parsed with the Postgres parser. Transaction control, SET ROLE, DO, COPY, dynamic SQL, dangerous functions and denied tables are refused with a reason the agent can read. |
| Approvals | DELETE / UPDATE without WHERE, changes to more rows than the key allows, drops, policy and privilege changes return 202 pending_approval until a person approves them. |
| Query log | Every statement, its result (ran, blocked, needs approval, error), rows changed and duration, per agent and session. |
| Undo | Every row an agent changes is recorded with its old and new values, every schema change with its inverse. Revert one session; other people's writes are left alone. |
#Quick start
- Studio → AI agents → Agent keys → New agent key. Pick a preset and the tables it may use.
- Copy the key (shown once) into your agent: as the MCP token, or as
Authorization: BearerforPOST /platform/v1/agent/sql. - Watch Query log, answer Approvals, and use Sessions & undo if something went wrong.
Terminal
curl https://stitchdb.com/platform/v1/agent/sql \
-H "Authorization: Bearer sdb_agt_..." \
-H "X-Stitch-Session: fix-signup-bug" \
-H "Content-Type: application/json" \
-d '{"query": "update profiles set plan = 'pro' where id = 42"}'