CapyDB Docs
Reference

MCP server

@capydb/mcp - let MCP-capable agents manage projects, previews, backups, restores, imports, and run SQL through the CapyDB API.

What it is

@capydb/mcp is the official Model Context Protocol server for CapyDB. It runs over stdio, talks to the control-plane REST API, and gives MCP-capable agents (Claude Code, Claude Desktop, Cursor, anything else speaking MCP) a typed tool surface for projects, preview databases, backups, restores, imports, live SQL, and observability.

Every tool returns structured JSON; API failures surface as MCP tool errors carrying the control plane's error message. Tools that trigger asynchronous jobs return the job to poll with get_job (create_project is the exception: it waits up to 5 minutes for the provision job itself).

Requires Node.js ≥ 22.

Configuration

Environment variableRequiredDefaultDescription
CAPYDB_API_KEYno-Org or project-scoped API key (capy_live_...); overrides everything else when set
CAPYDB_API_URLnohttps://capydb.dev/api/capydbControl-plane base URL

Credentials resolve in order: CAPYDB_API_KEY, then the CapyDB CLI's saved login (the active organization in the shared config file), then a first-run browser device login - the first tool call returns an approval URL, and once approved the minted key is saved back into the CLI config.

A key passed via CAPYDB_API_KEY is read from the environment and never persisted or logged by the server. Keys from the CLI login or the device-login flow are stored locally in the CLI config file (~/Library/Application Support/capydb/config.json on macOS, $XDG_CONFIG_HOME/capydb/config.json on Linux, %AppData%\capydb\config.json on Windows) with 0600 permissions, so the CLI and the MCP server share one credential and one revocation point.

Install

No install step when your client can launch commands - use npx -y @capydb/mcp. For a global binary:

npm install -g @capydb/mcp   # provides the `capydb-mcp` executable
# or: pnpm add -g @capydb/mcp

Claude Code

claude mcp add capydb --env CAPYDB_API_KEY=capy_live_... -- npx -y @capydb/mcp

Omit --env CAPYDB_API_KEY=... to reuse the CLI's saved login or trigger the browser device login on first use.

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "capydb": {
      "command": "npx",
      "args": ["-y", "@capydb/mcp"],
      "env": {
        "CAPYDB_API_KEY": "capy_live_..."
      }
    }
  }
}

Generic MCP client (stdio)

{
  "command": "capydb-mcp",
  "env": {
    "CAPYDB_API_KEY": "capy_live_...",
    "CAPYDB_API_URL": "https://capydb.dev/api/capydb"
  }
}

Tools

ToolWhat it does
list_regionsRegions a project can be placed in - use before create_project, or omit the region to let CapyDB pick.
create_projectCreate a project; waits up to 5 minutes for the provision job. The plan is derived from the organization's billing state.
list_projectsProjects visible to the key with state, plan, region, and storage limits. No credentials.
get_projectOne project by id, including provisioning state and limits. No credentials.
get_connection_stringsA project's pooled (PgBouncer) and direct connection URLs. Output contains live credentials.
create_preview_databaseCreate a preview (empty or clone, optional ttl_hours); poll the returned job with get_job.
list_preview_databasesA project's preview databases with state, source, and TTL expiry.
delete_preview_databasePermanently delete a preview and its role (async job). Not recoverable.
reset_preview_databaseReset a preview to its source state - clone re-clones production, empty wipes clean. Current preview data is lost (async job).
extend_preview_ttlSet a preview's expiry to ttl_hours (1-168) from now - an absolute new TTL, not a delta added to the remaining time.
get_preview_connection_stringsA preview's pooled and direct connection URLs. Output contains live credentials.
create_backupQueue an on-demand backup with an optional label (async job).
list_backupsCompleted backups, including verification state.
restoreRestore a backup (backup_key), restore point (restore_point_id), or PITR timestamp (restore_time) into an existing or new preview. Optional allow_unverified_backup. Cannot overwrite the production database - that path needs explicit human confirmation and is dashboard/CLI only.
import_preflightSynchronously check an external source Postgres database (size, version, extensions) against the project before importing. Changes nothing.
import_databaseImport a live external Postgres database, overwriting the project's production database. Requires confirm: true (set only after the user explicitly approved); run import_preflight first. Dump-file imports need the CLI's capydb import --file.
get_schemaThe complete database schema in one call: schemas, tables, views, columns, constraints, enums, extensions. Prefer over introspecting pg_catalog with run_sql. preview_id introspects a preview instead.
generate_typesGenerate source code from the live schema: TypeScript interfaces (style: capydb or supabase), Zod schemas, or a Drizzle schema. Returns { filename, content }; preview_id generates from a preview. See Type generation.
list_restore_pointsNamed restore points plus the project's PITR window.
create_restore_pointPin an existing backup_key or a PITR timestamp before a risky change. For a fresh backup, run create_backup, wait, and select its key with list_backups first.
delete_restore_pointRetire a restore point once the change it guarded is verified; underlying backups follow normal retention.
run_sqlRun SQL against the live project database via the Studio runner (default 200 rows, max 1000, 15s timeout). Executes writes and DDL too; recorded in SQL history.
list_tablesTables and views in the project database.
get_table_rowsRows from a table (schema, table, optional limit).
get_observabilityLive metrics snapshot: connections, size vs storage limit, active and slowest queries, derived alerts.
get_jobPoll an async job until completed/failed; failed jobs include the error.
list_jobsA project's async jobs, newest first (default 25).

Security

  • Use a project-scoped API key. The agent then can only touch the projects it needs; an org-wide key grants every project in the organization.
  • get_connection_strings and get_preview_connection_strings return URLs with embedded credentials, and they reach the model's context. Only enable this server with agents you trust, and rotate credentials if a key or URL leaks.
  • run_sql is not read-only. Point agents at preview databases for risky experimentation - previews are disposable and resettable by design.
  • The two destructive production paths are gated: import_database refuses to run without confirm: true, and restore only targets previews - production-overwrite restores are deliberately not exposed over MCP.