On this page

AI agents

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.

#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.

LayerWhat it does
Postgres roleEach 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.
FirewallEvery 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.
ApprovalsDELETE / 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 logEvery statement, its result (ran, blocked, needs approval, error), rows changed and duration, per agent and session.
UndoEvery 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

  1. Studio → AI agents → Agent keys → New agent key. Pick a preset and the tables it may use.
  2. Copy the key (shown once) into your agent: as the MCP token, or as Authorization: Bearer for POST /platform/v1/agent/sql.
  3. 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"}'