Postgres for AI coding agents
Xata exposes a CLI, a hosted MCP server, and agent skills. AI coding agents can use any of them to create Postgres branches, run migrations, inspect schema, and work against realistic data without writing to production.Get set up
New to Xata? Hand the setup to your agent: the agent onboarding guide walks it through installing the CLI, creating a project, connecting your app, and trying branching. The Quickstart has a ready-made prompt.Or set up manually
If you do not have a Xata account yet, sign up and create a project first. Install the Xata CLI, authenticate, and link your local repository:xata init writes your organization, project, branch, and database to .xata/ in the current folder so later CLI commands know which project to use.
Connect the Xata MCP server in your agent client. Most clients only need the server URL; OAuth handles the rest:
Choose your integration
Xata CLI
Branches, auth, migrations, clone, stream, and project linking from the terminal.
Xata MCP
Connect through OAuth or an API key. Works with Cursor, Claude Code, VS Code, Codex, OpenCode, Windsurf, Cline, and more.
Agent Skills
Guided workflows for the CLI, HTTP API, and PostgreSQL operations. Available through the MCP server.
Agent guides
Step-by-step setup for Claude Code, Cursor, Codex, Copilot, and other coding agents with isolated branches.
When to use each
- Xata MCP: preferred for agent-native operations. Connect to
https://api.xata.tech/mcpwith OAuth or an API key. Exposes REST API operations, schema inspection, SQL, documentation search, and skills without shelling out to the CLI for every step. - Xata CLI: preferred when the task depends on local machine state: linking the current directory with
xata init, creating branches, running migrations withxata roll, cloning data withxata clone, and scripting in CI. - Agent Skills: use alongside MCP so agents follow Xata-specific procedures for CLI commands, API calls, and PostgreSQL troubleshooting instead of guessing.
- Agent guides: use when you want a concrete workflow for a specific tool: branch connection strings,
.env.localsetup, example prompts, and cleanup steps for that agent.
Working with sensitive data
Anonymized production clones
Give agents realistic schema and data for testing without exposing PII or other sensitive values. Create an anonymized clone as the parent branch before spinning up agent task branches.
Agent directory
Use the guide for your coding agent to create an isolated branch, pass the branch connection string to the agent, and keep schema or data changes scoped to that branch until you review them.Claude Code
Terminal-first workflows for branch-scoped migrations, tests, and database inspection.
Codex
Sandbox-friendly workflows for running tests and edits against a dedicated Xata branch.
Cursor
IDE and background-agent setup with
.env.local connection strings and reviewable schema changes.OpenCode
Provider-agnostic terminal agent workflows using standard Postgres and the Xata CLI.
GitHub Copilot
VS Code and GitHub workflows for per-PR branches and CI-backed database checks.
Windsurf
Cascade and Flow patterns for repeatable branch creation, migration testing, and cleanup.
Cline
Approval-based VS Code workflows with safe terminal commands and branch-scoped credentials.
Devin
Long-running cloud-agent tasks with isolated branches, scoped credentials, and explicit cleanup.
Recommended baseline
- Create or choose a parent branch with the schema and data the agent should use. For sensitive data, start from an anonymized production clone.
- Create a dedicated branch for the agent task.
- Give the agent only the branch connection string or a branch-scoped API key.
- Ask the agent to run migrations, tests, and data changes only against that branch.
- Review code, SQL, schema diffs, and Xata branch state before merging.
- Delete the temporary branch when the task is done.