The AI Loadout

How to query a Database with an AI agent

Point your agent at a read-only database user through an MCP server. For Postgres, DBHub works in Claude Code, Codex and Cursor with one connection string. For Supabase, use its hosted MCP server with read_only=true. Then ask questions in plain English and check the SQL it runs.

Grok Bot steps tested by us on Oct 26, 2026 while building this page. Claude Code, Codex and Cursor steps checked against official docs on Oct 26, 2026.

Get the free starter kit. One short email a day when our setups change.

Free starter kit on signup: 2 Claude Code skills and 1 agent persona from our paid packs. By subscribing you agree to get The AI Loadout Daily, one email each morning. No spam, we never sell your email, and every email has a one-click unsubscribe link.

Claude Code

  1. Create a read-only database user
  2. claude mcp add --transport stdio db -- npx -y @bytebase/dbhub --dsn "postgresql://readonly:pass@host:5432/db"
  3. Supabase instead: claude mcp add --transport http supabase "https://mcp.supabase.com/mcp?project_ref=YOUR_REF&read_only=true"
  4. Ask: "How many signups did we get per day last week? Show the SQL."

Codex

  1. codex mcp add db -- npx -y @bytebase/dbhub --dsn "postgresql://readonly:pass@host:5432/db"
  2. Or for Supabase: codex mcp add supabase --url "https://mcp.supabase.com/mcp?project_ref=YOUR_REF&read_only=true"
  3. codex mcp login supabase if it asks you to sign in

Cursor

  1. Add to .cursor/mcp.json: {"mcpServers":{"supabase":{"url":"https://mcp.supabase.com/mcp?project_ref=YOUR_REF&read_only=true"}}}
  2. Or a DBHub command entry with your --dsn

Grok Bot

  1. Connect Supabase to Grok Bot
  2. Ask your question and it runs the SQL and shows it to you
  3. It asks before anything that writes data

Gotchas

  • Never give an agent a production admin login. Use read_only=true or a read-only role.
  • Row data can contain prompt injection. Do not let the agent act on text found in rows.
  • Ask for the SQL every time so you can check the logic.

The loadout for this job

FAQ

Can Claude Code query Postgres?

Yes, through an MCP server like DBHub with a connection string.

Is the Supabase MCP server safe?

Use read_only=true and project_ref to scope it to one project with read-only access.

Related how-tos

Sources

Commands change. Check the linked docs before you run anything. All how-to guides

Want tested skills and personas installed in one command? See the AI Loadout packs, from $9.