# @corabase/mcp Model Context Protocol (MCP) server that exposes the schema, database, document CRUD, user management, and dev server tools of [Corabase](https://corabase.dev), the open-source Postgres BaaS to AI assistants. ## Installation ```bash pnpm add -D @corabase/mcp ``` A project made by `cora init` already has it, pinned to the CLI's version: the server drives the project's own CLI and calls its own backend, so it should be the same release as both. ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with `import`. It needs Node `>=22.22.0` (its `engines` floor), where `require()` of it resolves too: Node has supported `require(esm)` since 22.12. Run the project's copy: ```bash pnpm exec corabase-mcp ``` ## What This Package Does `@corabase/mcp` implements the [Model Context Protocol](https://modelcontextprotocol.io) over stdio, allowing AI assistants (Gemini, Claude, Cursor, etc.) to interact with a Corabase project. It provides tools and exposes collection definitions and generated schemas as MCP resources. It has native support for managing multiple local and remote projects. It also serves the 24 Corabase agent skills (from `@corabase/agent-skills`) over the MCP skills extension (`io.modelcontextprotocol/skills`). A client on protocol revision 2026-07-28 or later lists them and loads one when it needs it; Claude Code names them `/rebase:rebase-tables` and so on. The server speaks 2026-07-28 and the 2025 revisions over stdio. ## Multi-Project Support The MCP server supports managing multiple Corabase projects simultaneously. This is ideal when working in an IDE with multiple open workspaces or when interacting with both local development servers and remote staging/production environments. - **Registry**: Project configurations are stored in `~/.rebase/projects.json`. - **Auto-Discovery**: If `cora dev` is running locally, the MCP server automatically discovers the active development port and service key from `.rebase/state.json` inside the project directory, giving you **zero-config local development**. ### Which project a run resolves to One precedence, in this order: 1. **The environment block** — `CORABASE_PROJECT_DIR`, `CORABASE_BASE_URL`, `CORABASE_API_TOKEN`. If any of them is set, the `default` project is rebuilt from them on **every** start. The rebuild is whole-entry: a token registered against the old `projectDir` is dropped rather than carried into a directory it was never issued for. 2. **The server's working directory**, when it holds a `corabase.json`. `~/.rebase/projects.json` is machine-wide, and a project you are standing in outranks a home-directory cache. 3. **The persisted `default`**, when neither of the first two says anything. A `default` derived from 1 or 2 is never written back to the registry: it is recomputed at every start, and persisting it would put one project's directory, backend URL and dev service key in the file every other project on the machine reads. Auto-discovery fills gaps in all three cases and **never overrules** a value one of them supplied — not the token and not the `baseUrl`. Discovery reads the dev server's *service key*, which is an unscoped admin secret, so a narrow `rk_live_*` key you registered is what gets used even while `cora dev` is running; likewise a project registered against `https://staging.example.com` stays there rather than being silently redirected to the local dev port. A `baseUrl` disagreement between the two is reported on stderr. Filling a gap is not: with no token registered, the SDK tools run on the discovered service key — full admin — and nothing says so. `cora init` writes `"env": { "CORABASE_PROJECT_DIR": "." }` into the scaffolded `.mcp.json` — relative to the client's working directory, which for a project-level config file is the project. ## Configuration The server reads configuration from environment variables and `.env` files: | Variable | Default | Description | |---|---|---| | `CORABASE_PROJECT_DIR` | `process.cwd()` | Project root directory (the `corabase.json` directory) | | `CORABASE_BASE_URL` | `http://localhost:3001` | Corabase backend URL, when discovery finds no dev server | | `CORABASE_API_TOKEN` | (empty) | Auth token for API calls to the app. `CORABASE_TOKEN` (the CLI's control-plane token) is never sent to the app; the cloud tools pass it to the CLI only | | `CORABASE_MCP_ALLOW_REMOTE_WRITES` | `false` | Allow destructive tools to run against non-local targets (see below) | The server attempts to load `.env` from `$CORABASE_PROJECT_DIR/.env` or `$CORABASE_PROJECT_DIR/app/.env`. Those values configure the server itself. They are not passed on to the CLI or the dev server it spawns: those read the active project's own `.env`, and a variable handed down would outrank it, and the branch the checkout is switched to, as if you had exported it in your shell. ## Destructive-Tool Safety Gate `corabase_project_add` accepts any `baseUrl`, and the CLI tools connect with whatever `DATABASE_URL` the project's `.env` declares. That means the same tool list that edits a scratch database on your laptop can drop production rows — with nothing in between but the assistant's judgement about which project is currently active. **Every tool that changes the target environment is refused unless that target is on the loopback interface.** The gate is a list of what is *not* gated, so a newly added tool is protected by default: - **Not gated — reads:** `corabase_schema_plan`, `corabase_doctor`, `corabase_db_branch_list`, `corabase_db_branch_info`, `corabase_db_branch_diff`, `list_documents`, `get_document`, `list_users`, `list_roles`, `storage_list_objects`, `storage_get_download_url`, `cron_list_jobs`, `cron_get_job`, `cron_get_job_logs`, `corabase_dev_logs`, and the Corabase Cloud reads `corabase_cloud_status`, `corabase_cloud_logs`, `corabase_cloud_env_list`, `corabase_cloud_deployments_list`. - **Not gated — Corabase Cloud writes:** `corabase_cloud_provision`, `corabase_cloud_deploy`, `corabase_cloud_env_set`, `corabase_cloud_rollback`. Provisioning creates a project and links this directory; the others change the linked cloud project, but they spawn `cora cloud`, which acts on the project `.rebase/cloud.json` links with the CLI's own credential and the control plane's own permission checks; they never use `baseUrl` or `DATABASE_URL`, which is all the gate can check. - **Not gated — local only:** `corabase_schema_introspect`, `corabase_db_branch_switch`, `corabase_schema_generate`, `corabase_db_generate`, `corabase_generate_sdk`, the dev-server tools, and the project-registry tools. These write local files or local state and have no remote target to check. - **Gated against `DATABASE_URL`:** every other CLI tool — `corabase_db_push`, `corabase_db_migrate`, `corabase_db_branch_create`, `corabase_db_branch_delete`. - **Gated against the project `baseUrl`:** every other SDK tool — `create_document`, `update_document`, `delete_document`, `create_user`, `update_user`, `delete_user`, `corabase_auth_reset_password`, `storage_delete_object`, `cron_trigger_job`, `cron_toggle_job`, `invoke_function`. The two targets are not interchangeable: CLI tools never see `baseUrl`, so a localhost backend sitting next to a production `DATABASE_URL` is checked against the database, not the backend. `create_user` and `update_user` set `roles`, so they can mint an admin; `invoke_function` calls any function with any HTTP method; `cron_toggle_job` disables a scheduled backup silently. None of those is recoverable in the sense "additive" suggests, which is why the list is now the other way round. The `DATABASE_URL` the gate checks is resolved the way the spawned CLI resolves it. A `DATABASE_URL` exported in the shell the server was started from wins outright. Otherwise the gate reads every `DATABASE_URL` and `ADMIN_CONNECTION_STRING` (the fallback the branch commands accept) in `/.env`, `/backend/.env`, `DOTENV_CONFIG_PATH` and the parent directory's `.env`, parsing each file with dotenv as the CLI does, and refuses if **any** of them is remote. **If no connection string can be resolved at all, the DB tools are refused**: an unverifiable target is not a safe one, and the child does its own resolution from files this process may not see. Only loopback (`localhost` and `*.localhost`, `127.0.0.0/8`, `::1`, `0.0.0.0`) counts as local — private ranges like `10.x` and `192.168.x` do not, since those are as likely to be a shared staging cluster as a laptop. Set `CORABASE_MCP_ALLOW_REMOTE_WRITES=true` to opt out. The branch tools (`corabase_db_branch_*`) also require an admin, checked through `GET /auth/me` — which answers a signed-in user's access token only, so with a service key (including the one discovery supplies) or an `rk_live_*` API key every branch tool fails with "Admin authorization failed". ## Untrusted Data Marking Rows, user records, storage listings, cron jobs, function responses and CLI output are returned inside an explicit `<<>>` envelope. Anything stored in your database was written by somebody, and it arrives on the same channel as the tool contract the assistant is following; the envelope tells the model to treat it as inert content rather than instructions. It is a marker, not a sandbox — an assistant with these tools is only as safe as the content you let it read. --- ## Tools 53 tools, in 10 groups. Tools marked ⚠ are refused against a non-local target unless `CORABASE_MCP_ALLOW_REMOTE_WRITES=true` — see the gate above. ### Schema & database (13) Spawn the Corabase CLI in the active project directory. | Tool | Required | Description | |---|---|---| | `corabase_schema_generate` | — | Generate the Drizzle schema (schema.generated.ts) from the project's table definitions in backend/schema | | `corabase_db_push` ⚠ | — | Apply the current Drizzle schema directly to the database (development shortcut, skips migration files) | | `corabase_schema_introspect` | — | Read the live database and write a defineTable definition into backend/schema for each table it holds (tables without row-level security are refused) | | `corabase_db_generate` | — | Generate SQL migration files from schema changes (compares current Drizzle schema against the last entity) | | `corabase_db_migrate` ⚠ | — | Run all pending SQL migrations against the database | | `corabase_generate_sdk` | — | Generate a fully-typed JavaScript/TypeScript SDK from the project's table definitions | | `corabase_doctor` | — | Detect schema drift between the table definitions in backend/schema, the generated Drizzle schema, and the live PostgreSQL database | | `corabase_db_branch_create` ⚠ | `name` | Create a new database branch (Admins only) | | `corabase_db_branch_list` | — | List all database branches (Admins only) | | `corabase_db_branch_delete` ⚠ | `name` | Delete an existing database branch (Admins only) | | `corabase_db_branch_info` | `name` | Show information and status for a database branch (Admins only) | | `corabase_db_branch_diff` | `name` | Show what a database branch changed against the database it was made from (Admins only): added, dropped and altered tables, columns, constraints, indexes, triggers, RLS policies, enum types, views and functions as SQL, and per table the rows the branch inserted, updated and deleted, matched by primary key, with sample rows | | `corabase_db_branch_switch` | — | Point this checkout at a database branch, or back at the main database (Admins only) | ### Schema planning (1) Ask the backend what a change would do. No CLI, no files written. | Tool | Required | Description | |---|---|---| | `corabase_schema_plan` | `patches` | Show the SQL a change to the project's tables would run, without running any of it | ### Rows (5) Read and write the rows of a table through `@corabase/client` (`data.table(slug)`). | Tool | Required | Description | |---|---|---| | `query_table` | `table` | Read rows from a table of the project's Postgres database, with optional filtering, sorting and paging, as the SDK's `data.table(name).find()` does | | `get_row` | `table`, `id` | Read one row of a table by its id | | `create_row` ⚠ | `table`, `data` | Add a row to a table | | `update_row` ⚠ | `table`, `id`, `data` | Change columns on an existing row of a table; only the columns given are touched | | `delete_row` ⚠ | `table`, `id` | Delete a row of a table by its id | ### Users & roles (6) | Tool | Required | Description | |---|---|---| | `list_users` | — | List all users registered in the Corabase backend, including their roles | | `create_user` ⚠ | `email` | Create a new user in the Corabase backend | | `update_user` ⚠ | `uid` | Update an existing user (email, display name, roles) | | `delete_user` ⚠ | `uid` | Delete a user from the Corabase backend | | `list_roles` | — | List all roles defined in the Corabase backend | | `corabase_auth_reset_password` ⚠ | `email` | Reset a user's password via the admin API | ### Dev server (3) | Tool | Required | Description | |---|---|---| | `corabase_dev_start` | — | Start the Corabase development server (frontend + backend) | | `corabase_dev_logs` | — | Read recent output from the running Corabase dev server | | `corabase_dev_stop` | — | Stop the running Corabase development server | ### Storage (3) | Tool | Required | Description | |---|---|---| | `storage_list_objects` | — | List files/objects stored in Corabase storage | | `storage_delete_object` ⚠ | `key` | Delete an object/file from Corabase storage | | `storage_get_download_url` | `key` | Mint a temporary signed download URL for a file in Corabase storage | ### Cron (5) | Tool | Required | Description | |---|---|---| | `cron_list_jobs` | — | List all scheduled cron jobs and their configuration status | | `cron_get_job` | `jobId` | Get status and details of a specific scheduled cron job | | `cron_trigger_job` ⚠ | `jobId` | Manually trigger a cron job run immediately | | `cron_get_job_logs` | `jobId` | Read execution logs for a specific cron job | | `cron_toggle_job` ⚠ | `jobId`, `enabled` | Enable or disable a scheduled cron job | ### Functions (1) | Tool | Required | Description | |---|---|---| | `invoke_function` ⚠ | `name` | Invoke a custom backend Hono function (in backend/functions/.ts, served at /api/functions/) | ### Project registry (7) | Tool | Required | Description | |---|---|---| | `corabase_project_list` | — | List all registered Corabase projects and show which one is active | | `corabase_project_switch` | `name` | Switch the active Corabase project by name | | `corabase_project_use_cloud` | `project` | Point the data and admin tools (query_table, get_row, list_users, list_roles, cron_list_jobs, storage_list_objects…) at a Corabase Cloud project's production backend, by its id, slug or name — any project the signed-in account can reach, linked here or not | | `corabase_project_add` | `name` | Register a new Corabase project | | `corabase_project_remove` | `name` | Remove a registered project from the project registry | | `corabase_project_current` | — | Show details about the currently active Corabase project, including resolved URL and auth status | | `corabase_project_status` | — | Health-check the active project's backend by calling GET /health | ### Corabase Cloud (9) Spawn `cora cloud … --json` in the active project directory, against the project it is linked to, with the CLI's own credential. Provisioning creates a project; deploy, env set and rollback change the linked one. The loopback gate does not apply to them, because they never use `baseUrl` or `DATABASE_URL`. | Tool | Required | Description | |---|---|---| | `corabase_cloud_provision` | — | Give the active project a live backend on Corabase Cloud with no account or signup: provisions a project, sets CORABASE_BASE_URL in .env, links the directory and deploys the local backend to it (`cora cloud init --claim`), then sets CORABASE_API_TOKEN in .env: a key the deployed app accepts, for reading and writing data through its row-level security, expiring with the claim window | | `corabase_cloud_projects_list` | — | List every Corabase Cloud project the signed-in account can reach, across all its organizations (`cora cloud projects list --all-orgs`): id, name, slug, host and status | | `corabase_cloud_status` | — | Show the Corabase Cloud project this directory is linked to (`cora cloud status`) | | `corabase_cloud_deploy` | — | Deploy this directory to its linked Corabase Cloud project (`cora cloud deploy`) | | `corabase_cloud_logs` | — | Read the linked Corabase Cloud project's log once, the running app's or the latest build's (`cora cloud logs`) | | `corabase_cloud_env_list` | — | List the linked Corabase Cloud project's environment variables, never their values (`cora cloud env list`) | | `corabase_cloud_env_set` | `key`, `value` | Set one environment variable on the linked Corabase Cloud project (`cora cloud env set KEY --stdin`) | | `corabase_cloud_deployments_list` | — | List the linked Corabase Cloud project's recent deployments, newest first (`cora cloud deployments list`) | | `corabase_cloud_rollback` | — | Put a previous successful deployment of the linked Corabase Cloud project back into service (`cora cloud rollback`) | --- ## Resources The server exposes MCP resources for AI context: | URI | Description | |---|---| | `corabase://tables/{name}` | TypeScript source of a table definition (`defineTable`) | | `corabase://schema` | Generated Drizzle schema (`schema.generated.ts`) | Table files are the modules of the schema directory, its `index.ts` aside: the `tables` key of the backend app in `corabase.json`, `backend/schema` by default, under the active project directory or its `app/`. ## Quick Start Add to your AI assistant's MCP config (e.g. `.gemini/settings.json`): ```json { "mcpServers": { "corabase": { "command": "pnpm", "args": ["--dir", "/path/to/your/project", "exec", "corabase-mcp"], "env": { "CORABASE_PROJECT_DIR": "/path/to/your/project" } } } } ``` ## MCP Registry A stable release publishes this server to the [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.corabase/corabase` — the listing MCP clients read when they offer an install. Two files carry that identity, and they must agree: | | | |---|---| | `package.json` → `mcpName` | the ownership proof, read out of the **published npm tarball** | | `server.json` | the manifest: the same name, the version, and the npm package to install | Neither is edited by hand on a release. `publishable-packages.mjs --set-version` writes the version into `server.json` alongside every `package.json`, and `pnpm check:publishable-set` refuses a tree where the two disagree — the registry validates a publish by downloading the tarball the manifest names, so a manifest left behind fails the release at its last step, once npm can no longer be rewritten. The stable publish workflow pushes the registry entry itself, after npm, the tag and the fleet image, on the OIDC token it already holds for npm provenance. A hand-run `release.sh` cannot — the login is a device-code flow — so it prints the command to finish the job: ```bash mcp-publisher login github && mcp-publisher publish ``` Install `mcp-publisher` with `brew install mcp-publisher`, and check a manifest without publishing anything using `mcp-publisher validate`. ## Related Packages - `@corabase/client` — Used internally for data and admin API calls