Database access for AI agents
For engineers
Letting coding agents, MCP servers and text-to-SQL features touch databases with scoped roles, limits, branches, audit logs and a way back
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
A text-to-SQL feature only needs to answer sales questions. Which setup is safest?
Check yourself · 2 of 5
What is the main purpose of running an agent's schema change on a database branch first?
Check yourself · 3 of 5
Why can a row returned by a database MCP server be a security risk?
Check yourself · 4 of 5
Which statement should always need a person's approval from an agent?
Check yourself · 5 of 5
Which set of facts makes an agent query log most useful for review?
Topics
- Scoped database roles for agents5 min read · A dedicated role per agent or feature with read-only grants, row-level security, statement_timeout and row limits instead of the app's owner login
- Branch and scratch databases for agent work5 min read · Running agent migrations and experiments on a database branch, a restored copy or a local container before anything reaches production
- Connecting database MCP servers safely5 min read · What Postgres, Supabase and similar MCP servers expose, read-only modes, project scoping, and why query results can carry prompt injection
- Stopping destructive agent database commands5 min read · DROP, TRUNCATE and unscoped DELETE from agents, approval gates, and confirming backups and point-in-time recovery before granting write access
- Auditing the queries agents run5 min read · Logging every agent statement with its role, task and session, using query logs or pgaudit, and reviewing them for reads of sensitive columns
Start here
- PostgreSQL privileges overview (opens in a new tab)DocsFree
GRANT, REVOKE and default privileges: the mechanism that decides what an agent role can touch.
- PostgreSQL: Row security policies (opens in a new tab)DocsFree
How CREATE POLICY limits the rows a role sees, including the owner-bypass rule.
- Supabase: Model Context Protocol (opens in a new tab)DocsFree
The hosted MCP server's project scoping, read-only mode and feature groups.
Helps to know first
110 questions · last verified 2026-12