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 variable | Required | Default | Description |
|---|---|---|---|
CAPYDB_API_KEY | no | - | Org or project-scoped API key (capy_live_...); overrides everything else when set |
CAPYDB_API_URL | no | https://capydb.dev/api/capydb | Control-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/mcpClaude Code
claude mcp add capydb --env CAPYDB_API_KEY=capy_live_... -- npx -y @capydb/mcpOmit --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
| Tool | What it does |
|---|---|
list_regions | Regions a project can be placed in - use before create_project, or omit the region to let CapyDB pick. |
create_project | Create a project; waits up to 5 minutes for the provision job. The plan is derived from the organization's billing state. |
list_projects | Projects visible to the key with state, plan, region, and storage limits. No credentials. |
get_project | One project by id, including provisioning state and limits. No credentials. |
get_connection_strings | A project's pooled (PgBouncer) and direct connection URLs. Output contains live credentials. |
create_preview_database | Create a preview (empty or clone, optional ttl_hours); poll the returned job with get_job. |
list_preview_databases | A project's preview databases with state, source, and TTL expiry. |
delete_preview_database | Permanently delete a preview and its role (async job). Not recoverable. |
reset_preview_database | Reset a preview to its source state - clone re-clones production, empty wipes clean. Current preview data is lost (async job). |
extend_preview_ttl | Set 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_strings | A preview's pooled and direct connection URLs. Output contains live credentials. |
create_backup | Queue an on-demand backup with an optional label (async job). |
list_backups | Completed backups, including verification state. |
restore | Restore 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_preflight | Synchronously check an external source Postgres database (size, version, extensions) against the project before importing. Changes nothing. |
import_database | Import 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_schema | The 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_types | Generate 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_points | Named restore points plus the project's PITR window. |
create_restore_point | Pin 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_point | Retire a restore point once the change it guarded is verified; underlying backups follow normal retention. |
run_sql | Run 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_tables | Tables and views in the project database. |
get_table_rows | Rows from a table (schema, table, optional limit). |
get_observability | Live metrics snapshot: connections, size vs storage limit, active and slowest queries, derived alerts. |
get_job | Poll an async job until completed/failed; failed jobs include the error. |
list_jobs | A 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_stringsandget_preview_connection_stringsreturn 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_sqlis 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_databaserefuses to run withoutconfirm: true, andrestoreonly targets previews - production-overwrite restores are deliberately not exposed over MCP.