Skip to content

AI & Agents

MCP Server

@rebasepro/mcp is a Model Context Protocol server that hands an AI assistant real tools over a Rebase project: read and write rows, manage users, run migrations, invoke functions, drive the dev server.

It speaks MCP over stdio only. There is no port and no listener — the process is exactly as trusted as whatever spawned it, and there is no remote caller to authenticate. That is the safe part. The interesting questions are all about what it does once it is running, and this page answers them before it shows you the config block.

A deployed backend can also serve MCP itself, over HTTP, to the people who use your application. That is a different thing with a different credential model: see The Remote MCP Endpoint.

The server runs from your project: @rebasepro/mcp is a devDependency every rebase init scaffold pins with the CLI, and each block below — the whole integration — starts that copy (pnpm exec rebase-mcp, or npx --no rebase-mcp in an npm project), never a newer one from npm. An older project adds it once, with rebase skills install --mcp or pnpm add -D @rebasepro/mcp.

rebase init writes the block for each agent you pick when it sets up your AI coding agents, keeping any other servers already in the file. rebase init --agent cursor,codex does the same without asking.

Claude Code — .mcp.json at your project root. rebase init writes this file for you:

{
"mcpServers": {
"rebase": {
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "."
}
}
}
}

Cursor — the same shape, in .cursor/mcp.json. Cursor expands ${workspaceFolder} to the project root:

{
"mcpServers": {
"rebase": {
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "${workspaceFolder}"
}
}
}
}

Gemini CLI — .gemini/settings.json, under the same key:

{
"mcpServers": {
"rebase": {
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "."
}
}
}
}

Codex CLI — TOML rather than JSON, in the project’s .codex/config.toml. Codex reads a project config only once you have trusted the project:

[mcp_servers.rebase]
command = "pnpm"
args = ["exec", "rebase-mcp"]
[mcp_servers.rebase.env]
REBASE_PROJECT_DIR = "."

Kiro — .kiro/settings/mcp.json:

{
"mcpServers": {
"rebase": {
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "."
}
}
}
}

GitHub Copilot in VS Code — .vscode/mcp.json, under servers and with an explicit transport:

{
"servers": {
"rebase": {
"type": "stdio",
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "${workspaceFolder}"
}
}
}
}

Windsurf reads MCP servers only from its user-level config, so there is no project file to write. Add the server in its MCP settings as "command": "pnpm", "args": ["--dir", "/absolute/path/to/your/project", "exec", "rebase-mcp"], with that path as REBASE_PROJECT_DIR.

Any MCP client that can spawn a stdio server works; the shape is the same.

REBASE_PROJECT_DIR is the directory containing rebase.json. There is one precedence, and it is the same in every client:

  1. The environment block — REBASE_PROJECT_DIR, REBASE_BASE_URL, REBASE_API_TOKEN. If any of them is set, the default project is rebuilt from them on every start.
  2. The server’s working directory, when it holds a rebase.json. A project you are standing in outranks anything remembered in ~/.rebase/projects.json.
  3. The persisted default in ~/.rebase/projects.json, when neither of the first two says anything.

Auto-discovery from .rebase/state.json fills gaps in all three cases and never overrules a value one of them supplied.

The project-level blocks name the project — ".", the client’s working directory, or the editor’s ${workspaceFolder} — because rule 3 reads a file shared by every project on the machine. A user-level config, such as Windsurf’s, names an absolute path instead.

This is the section to read before pointing an assistant at a database you care about.

The server carries one ambient credential for the whole process. There is no per-tool identity and no read-only mode; every tool uses the same token, and the only switch in the package opts in to more reach rather than less.

Which credential that is, in priority order:

  1. REBASE_API_TOKEN from the environment. REBASE_TOKEN is not read here: it is the CLI’s control-plane token, and it is never sent to the app (the server says so once on stderr when it is the only one set). The cloud tools still pass it to the CLI they spawn, which sends it to the control plane.
  2. REBASE_SERVICE_KEY read out of the project’s .env
  3. The service key auto-discovered from .rebase/state.json while rebase dev is running

2 and 3 are this machine’s dev backend’s key, used only when the target is on loopback. When REBASE_BASE_URL points elsewhere — rebase cloud init --claim writes the cloud project’s address, and no REBASE_API_TOKEN until a deploy succeeds — the server sends no token and says so once on stderr.

A token you register for a project wins over auto-discovery. Discovery only fills a gap.

Register a scoped API key and the two-gate model applies for real. A service key runs with the roles ["service"], which the injected admin policies do not name — so RLS grants it nothing unless one of your own policies says otherwise, and its scopes narrow it further:

rebase api-keys create -n "claude-code" \
--scopes data:read:articles \
--expires-in 30

Then hand the resulting rk_live_… key to the server rather than letting it discover a service key:

{
"mcpServers": {
"rebase": {
"command": "pnpm",
"args": ["exec", "rebase-mcp"],
"env": {
"REBASE_PROJECT_DIR": "/absolute/path/to/your/project",
"REBASE_API_TOKEN": "rk_live_..."
}
}
}
}

Two things this does not do, both worth knowing before you rely on it:

  • It does not narrow the CLI tools. rebase_db_push, rebase_db_migrate, rebase_doctor and the branch tools spawn the Rebase CLI, which connects with DATABASE_URL and never sees your token at all. The loopback gate below is the only thing standing in front of those.
  • A key reaches an admin tool only with that tool’s scope. list_users and list_roles need users:read; create_user, update_user, delete_user and rebase_auth_reset_password need users:write; the storage and cron tools need the matching storage:* or cron:* scope; invoke_function needs functions:invoke. Without it the call answers 403 SCOPE_MISSING. Even with users:write, a key cannot change an admin’s account: an admin holds keys:read and keys:write, which no key can, and nobody may manage an account that holds more than they do.

A key created with --roles admin is a different matter: it carries the roles ["service", "admin"], which clears the same default admin policies the service key does. Give it --full-access as well and its reach is the service key’s, less key management. What it adds is that it is revocable, expirable and rate-limited per key, none of which is true of the service key — rotating that means editing .env and restarting the server.

See Agents and MCP Servers for the key-scoping guidance in full.

The reason an admin credential reads everything is the baseline policy Rebase injects into each table, granting the trusted server context and the admin role. A table can opt out of that baseline and take full responsibility for its own RLS:

import { defineTable, col } from "@rebasepro/server/schema";
export const medicalRecords = defineTable("medical_records", {
columns: {
id: col.uuid().primaryKey().defaultRandom(),
patientId: col.text(),
notes: col.text(),
},
// Remove the injected admin/server baseline — nothing is readable
// except what the rules below allow.
defaultPolicies: false,
rls: [
{ operations: ["select", "update"], ownerField: "patientId" },
],
});

Now the only way in is to match patientId. The service key’s uid is the literal string service, so an owner rule never matches it — reads return zero rows and writes are rejected by Postgres. This is the one control that constrains the MCP server’s default credential rather than assuming it away.

Remember that this is a real RLS change, not a documentation one: it takes effect only once rebase schema generate and a migration have applied the policies. See Row-level security.

rebase_project_add accepts any baseUrl, and the CLI tools connect with whatever DATABASE_URL the project declares. The same tool list that edits a scratch database on your laptop can therefore drop production rows, with nothing in between but the assistant’s judgement about which project is active.

Every tool that changes the target environment is refused unless that target is on the loopback interface. The gate is written as a list of what is not gated, so a tool added later arrives protected by default.

  • Not gated — reads: rebase_schema_plan, rebase_doctor, rebase_db_branch_list, rebase_db_branch_info, rebase_db_branch_diff, query_table, get_row, list_users, list_roles, storage_list_objects, storage_get_download_url, cron_list_jobs, cron_get_job, cron_get_job_logs, rebase_dev_logs, and the Rebase Cloud reads rebase_cloud_status, rebase_cloud_logs, rebase_cloud_env_list, rebase_cloud_deployments_list.
  • Not gated — Rebase Cloud writes: rebase_cloud_provision, rebase_cloud_deploy, rebase_cloud_env_set, rebase_cloud_rollback. Provisioning creates a project; the others change a production project. None of them goes through baseUrl or DATABASE_URL, which are all the gate can check. See Rebase Cloud for what stands in front of them.
  • Not gated — local only: rebase_schema_introspect, rebase_db_branch_switch, rebase_schema_generate, rebase_db_generate, rebase_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: the remaining CLI tools — rebase_db_push, rebase_db_migrate, rebase_db_branch_create, rebase_db_branch_delete.
  • Gated against the project baseUrl: the remaining SDK tools — create_row, update_row, delete_row, create_user, update_user, delete_user, rebase_auth_reset_password, storage_delete_object, cron_trigger_job, cron_toggle_job, and 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.

A refusal looks like this:

Error: Refusing to run "delete_row": project "default" points at
https://api.example.com/, which is not local. Set REBASE_MCP_ALLOW_REMOTE_WRITES=true
to allow destructive tools against remote environments.

If no connection string can be resolved at all, the gated DB tools are refused. With no DATABASE_URL, the CLI uses the managed development database, which is the default for a new project, and the gate refuses its four database tools there. The refusal says why and names what works instead. It does not suggest the opt-out:

Error: Refusing to run "rebase_db_push": project "default" sets no DATABASE_URL, so the
CLI would use the managed development database (PGlite, started by `rebase dev`). You
most likely do not need this tool: the dev server applies the tables in backend/schema to
that database at boot, additively. After changing a table, restart it with
rebase_dev_stop and rebase_dev_start. …

From a terminal, rebase db push and rebase db migrate do run on that database; only the MCP tools are refused.

Only loopback counts as local: localhost, *.localhost, 127.0.0.0/8, ::1 (and 0.0.0.0). Private ranges like 10.x and 192.168.x do not — those are as likely to be a shared staging cluster as a laptop, and treating them as local would wave through exactly the accident the gate exists to stop.

Set REBASE_MCP_ALLOW_REMOTE_WRITES=true to opt out. Setting it globally in your MCP client config removes the gate for every project the server can reach, not just the one you were thinking about.

Rows, user records, storage listings, cron jobs, function responses and CLI output come back wrapped in an explicit envelope:

<<<UNTRUSTED_DATA source="query_table" id="9b2f4c1e-…">>>
[ … rows … ]
<<<END_UNTRUSTED_DATA id="9b2f4c1e-…">>>

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.

The id is minted fresh for every response, after the data was written, and only the end marker carrying it closes the block. Text inside the data that is shaped like a marker is broken with a zero-width space, so a row that prints <<<END_UNTRUSTED_DATA>>> cannot end the envelope early and put what follows it outside.

The remote endpoint fences its tool results the same way and says so to the client; its structuredContent carries the plain result. list_tables and describe_table are the exceptions: only a model reads them, so they are sent once, in the text.

It is a marker, not a sandbox. An assistant holding these tools is only as safe as the content you let it read.

Project configurations are stored in ~/.rebase/projects.json, and the server can hold several at once — useful when you work across local and remote environments. While rebase dev is running, the server reads the active port and service key from .rebase/state.json in the project directory, which is what makes the local case zero-config.

activeProject is machine-wide, and one server is often installed once for the whole machine. So every tool that acts on a project (all but the rebase_project_* registry tools, rebase_cloud_projects_list, rebase_cloud_provision and rebase_dev_logs) resolves its project per call, and takes an optional project: a registered project’s name, or a Rebase Cloud slug or id. The call is checked against the Cloud link (.rebase/cloud.json) of the directory the session works in: the client’s first root, else the server’s working directory.

The call The session’s directory Result
names a project is linked to the same project runs on it
names a project is linked to another project refused, nothing runs
names no project is linked to a project the active one is not refused, nothing runs
names no project is linked; the active project is a local one elsewhere runs on the linked project
names no project is not linked runs on the active project; a write to a Cloud project an earlier session selected needs the project named

A refusal names both projects. rebase_project_current reports the session’s directory and link under session. rebase_cloud_env_set and rebase_cloud_rollback pass the resolved project to the CLI with --project; rebase_cloud_deploy ships the directory it runs in, so it is refused when that directory’s link is another project.

Tokens are stored in that registry in plaintext. It is a file in your home directory holding admin credentials for every project you have registered; treat it accordingly.

Eight tools take an app from this directory to a live backend on Rebase Cloud and keep it running. Each one spawns rebase cloud <command> --json in the active project directory: the same command a person runs, so there is no second implementation to drift from it.

Tool Runs Changes the project
rebase_cloud_provision rebase cloud init --claim Creates one, with no account
rebase_cloud_status rebase cloud status No
rebase_cloud_deploy rebase cloud deploy Yes
rebase_cloud_logs rebase cloud logs [--runtime] No
rebase_cloud_env_list rebase cloud env list No
rebase_cloud_env_set rebase cloud env set KEY --stdin Yes, from the next deploy
rebase_cloud_deployments_list rebase cloud deployments list No
rebase_cloud_rollback rebase cloud rollback --yes Yes
rebase_cloud_projects_list rebase cloud projects list --all-orgs No

The usual agent journey is: rebase_cloud_provision, then give the user the claim URL; rebase_cloud_status to see the project (while it is unclaimed, unclaimed carries the claim URL and when it is deleted); rebase_cloud_deploy after a change; rebase_cloud_logs when something misbehaves; and rebase_cloud_rollback when production is broken.

What they act on. The project the call resolves to, as described in Which project a call acts on: the project argument, checked against the link of the session’s directory, or that link, or the active project. A call that names a project the session’s directory is not linked to is refused before anything is spawned.

Whose authority. Whatever the CLI resolves in that directory: REBASE_TOKEN when it is set, then the token rebase cloud init --claim stored for an unclaimed project, then the rebase cloud login session. In that unclaimed project’s directory, a REBASE_TOKEN that holds no scope on the project is set aside for the project’s own token. The control plane checks each call as it checks the CLI’s, so with a token made by rebase cloud tokens create --can logs an assistant can read logs, and the control plane refuses its deploys, variables and rollbacks. No credential, or a refused one, comes back as an error that says what the user has to do (rebase cloud login, or claiming the project).

Why the loopback gate does not apply. The gate checks the app’s baseUrl and the CLI’s DATABASE_URL; these tools use neither. After rebase_cloud_provision, REBASE_BASE_URL points at the new cloud project, so gating on it would refuse the very deploy the journey needs. Provisioning itself only creates: it touches no existing app or database, and the CLI still refuses it in a directory that is already linked. A deploy, a variable and a rollback each change production. What stands in front of them is the credential above, your MCP client’s tool approval, and confirm: true: rebase_cloud_deploy to production, rebase_cloud_env_set in production, rebase_cloud_rollback and rebase_cloud_provision answer what they would do and do nothing until a call repeats the same arguments with confirm: true, which the assistant sends only after the user agrees. A preview deploy and a preview variable need none. To keep an assistant from changing a cloud project, set REBASE_TOKEN in the server’s environment to a token without the deploy and env capabilities.

Reading any of your projects. The tools above act on the linked project. To read another one’s data — any project in any organization the signed-in account belongs to, linked here or not — rebase_cloud_projects_list lists them and rebase_project_use_cloud (with an id, slug or name) points the data and admin tools at it: query_table, get_row, list_users, list_roles, cron_list_jobs, storage_list_objects. Those calls go through the console’s Studio proxy, bearing the CLI’s own credential (rebase cloud access-token, read per call and never stored); the control plane checks the person’s access and attaches the project’s service key on its side, so no key reaches the machine. A project with Studio switched off is refused, and the switch says so. It is a remote target like any other, so tools that change data stay refused there unless REBASE_MCP_ALLOW_REMOTE_WRITES is set; rebase_project_switch goes back.

Each tool is a snapshot:

  • rebase_cloud_logs never follows. Its result carries nextSinceTime; pass it back as since to read what came after. It returns the last 200 lines unless tail says otherwise. source: "build" returns the latest build log instead.
  • rebase_cloud_deploy follows the deployment to the end and checks that the new version answers. wait: false returns as soon as the deployment is triggered. It never ejects a project from the managed runtime, deploys an older framework release, or skips the build checks: those are the user’s decisions, and a refusal that needs one says so.
  • rebase_cloud_rollback passes --yes once the call carries confirm: true (below), since there is no terminal to ask at.

rebase_cloud_env_set writes the value to the CLI’s standard input, so it is never on a command line where ps would show it, and the value is cut out of anything the tool returns. Its result says what was stored (the key, whether it is secret, whether a redeploy is pending), never the value. rebase_cloud_env_list lists keys only. A CLI older than env set --stdin is refused with a message to upgrade it; the value is not sent another way.

Results come back in the untrusted-data envelope, behind one line from the server on what to do next. A refusal is a tool error that carries the CLI’s code, such as no_project, token_rejected, managed_project or deploy_failed. When the server recognises the code, it adds the next step, then the CLI’s own message. Every tool checks its arguments against the schema it advertises before anything is spawned, and refuses an argument it does not declare.

53 tools, in ten groups: schema and database, schema planning, documents, users and roles, storage, cron, functions, the dev server, the project registry and Rebase Cloud. Each one, with what it needs and whether the gate refuses it against a non-local target, is in the MCP tool reference.

Beyond tools, the server exposes MCP resources so a client can pull project context without spending a tool call:

URI Description
rebase://tables/{name} TypeScript source of a table definition (defineTable)
rebase://schema The 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 rebase.json, backend/schema by default, under the active project directory or its app/.

rebase://schema is listed only if the generated schema exists. findBackendDir looks for backend/ and then app/backend/ under the active project directory, and reads src/schema.generated.ts from whichever it finds — so both the scaffolded layout and this monorepo’s work, and a project laid out a third way, or one that has not run rebase schema generate yet, simply will not see the resource offered.

The server also serves the 24 Rebase agent skills through the MCP skills extension. A client on protocol revision 2026-07-28 or later loads one when it needs it. In Claude Code they are /rebase:rebase-tables and so on. Without @rebasepro/agent-skills, the server starts without them and says so on stderr.

A deployed backend can also serve MCP itself, at /mcp, to the people who use your application, each connecting as themselves under their own row-level security. That has its own page: The Remote MCP Endpoint.

  • Point the server at a local project and leave REBASE_MCP_ALLOW_REMOTE_WRITES unset. The gate is the single most valuable thing in the package.
  • For anything remote, register a scoped rk_ API key rather than letting discovery hand over a service key.
  • Check rebase_project_current when output looks wrong. The active project is sticky and lives outside your repo.
  • Treat ~/.rebase/projects.json as a secrets file.