Skip to main content

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:
Example for Claude Code:
See MCP Server for setup instructions for Cursor, VS Code, Codex, OpenCode, Windsurf, Cline, and other clients.

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/mcp with 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 with xata roll, cloning data with xata 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.local setup, 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.
  1. Create or choose a parent branch with the schema and data the agent should use. For sensitive data, start from an anonymized production clone.
  2. Create a dedicated branch for the agent task.
  3. Give the agent only the branch connection string or a branch-scoped API key.
  4. Ask the agent to run migrations, tests, and data changes only against that branch.
  5. Review code, SQL, schema diffs, and Xata branch state before merging.
  6. Delete the temporary branch when the task is done.

See also

Agent onboarding

A guide for coding agents to help users get started with Xata, from installing the CLI to a working Postgres branch connected to their app.

Agent Skills

Guided workflows that teach AI coding agents how to operate Xata.

Claude Code

Use Claude Code with isolated Xata branches and branch-scoped Postgres connection strings.

Codex

Use Codex with Xata branches for sandboxed coding sessions and database-aware tests.

Cursor

Use Cursor with Xata branch connection strings for IDE and background-agent workflows.

OpenCode

Use OpenCode with standard Postgres URLs and Xata CLI workflows.

GitHub Copilot

Use GitHub Copilot with Xata per-PR branches and CI-backed database workflows.

Windsurf

Use Windsurf Cascade and Flows with repeatable Xata branch workflows.

Cline

Use Cline with approval-based Xata branch workflows in VS Code.

Devin

Use Devin with temporary Xata branches, scoped credentials, and explicit cleanup.