@rebasepro/mcp 0.17.3 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,10 +8,14 @@ Model Context Protocol (MCP) server that exposes Rebase schema, database, docume
8
8
  pnpm add @rebasepro/mcp
9
9
  ```
10
10
 
11
+ ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
12
+ `import`. `require()` of it resolves only on Node 22.12+, which supports
13
+ `require(esm)`.
14
+
11
15
  Or run directly:
12
16
 
13
17
  ```bash
14
- npx rebase-mcp
18
+ npx -y @rebasepro/mcp
15
19
  ```
16
20
 
17
21
  ## What This Package Does
@@ -24,9 +28,20 @@ The MCP server supports managing multiple Rebase projects simultaneously. This i
24
28
 
25
29
  - **Registry**: Project configurations are stored in `~/.rebase/projects.json`.
26
30
  - **Auto-Discovery**: If `rebase 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**.
27
- - **Default Project**: If no project registry exists, a default project named `default` is created using `REBASE_PROJECT_DIR` (or current working directory), `REBASE_BASE_URL`, and `REBASE_API_TOKEN`.
28
31
 
29
- A token registered for a project **takes precedence over auto-discovery**. Discovery reads the dev server's *service key*, which is an unscoped admin secret — so if you deliberately register a narrow `rk_live_*` API key for a project, that key is what gets used, even while `rebase dev` is running. Discovery only fills in a token when none is registered.
32
+ ### Which project a run resolves to
33
+
34
+ One precedence, in this order:
35
+
36
+ 1. **The environment block** — `REBASE_PROJECT_DIR`, `REBASE_BASE_URL`, `REBASE_API_TOKEN` / `REBASE_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.
37
+ 2. **The server's working directory**, when it holds a `rebase.json`. `~/.rebase/projects.json` is machine-wide, and a project you are standing in outranks a home-directory cache.
38
+ 3. **The persisted `default`**, when neither of the first two says anything.
39
+
40
+ 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.
41
+
42
+ 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 `rebase 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 disagreement between the two is reported on stderr.
43
+
44
+ `rebase init` writes `"env": { "REBASE_PROJECT_DIR": "." }` into the scaffolded `.mcp.json` — relative to the client's working directory, which for a project-level config file is the project.
30
45
 
31
46
  ## Configuration
32
47
 
@@ -34,9 +49,9 @@ The server reads configuration from environment variables and `.env` files:
34
49
 
35
50
  | Variable | Default | Description |
36
51
  |---|---|---|
37
- | `REBASE_PROJECT_DIR` | `process.cwd()` | Project root directory (fallback if no registry) |
38
- | `REBASE_BASE_URL` | `http://localhost:3001` | Rebase backend URL (fallback if no registry) |
39
- | `REBASE_API_TOKEN` / `REBASE_TOKEN` | (empty) | Auth token for API calls (fallback if no registry) |
52
+ | `REBASE_PROJECT_DIR` | `process.cwd()` | Project root directory (the `rebase.json` directory) |
53
+ | `REBASE_BASE_URL` | `http://localhost:3001` | Rebase backend URL, when discovery finds no dev server |
54
+ | `REBASE_API_TOKEN` / `REBASE_TOKEN` | (empty) | Auth token for API calls |
40
55
  | `REBASE_MCP_ALLOW_REMOTE_WRITES` | `false` | Allow destructive tools to run against non-local targets (see below) |
41
56
 
42
57
  The server attempts to load `.env` from `$REBASE_PROJECT_DIR/.env` or `$REBASE_PROJECT_DIR/app/.env`.
@@ -68,69 +83,105 @@ Rows, user records, storage listings, cron jobs, function responses and CLI outp
68
83
 
69
84
  ## Tools
70
85
 
71
- ### Project Management Tools (6) [NEW]
86
+ <!-- generated: mcp tool tables — pnpm generate:mcp-readme -->
87
+
88
+ 42 tools, in 9 groups. Tools marked ⚠ are refused against a non-local
89
+ target unless `REBASE_MCP_ALLOW_REMOTE_WRITES=true` — see the gate above.
90
+
91
+ ### Schema & database (12)
72
92
 
73
- Manage multiple local projects or remote environments.
93
+ Spawn the Rebase CLI in the active project directory.
74
94
 
75
- | Tool | Required Args | Description |
95
+ | Tool | Required | Description |
76
96
  |---|---|---|
77
- | `rebase_project_list` | (none) | List all registered projects and show which one is currently active |
78
- | `rebase_project_switch` | `name` | Switch the active project to another registered project |
79
- | `rebase_project_add` | `name` | Register a new project (requires `baseUrl` and optional `projectDir`, `token`/`serviceKey`) |
80
- | `rebase_project_remove` | `name` | Remove a project from the registry (cannot remove the default project) |
81
- | `rebase_project_current` | (none) | Show details of the active project (name, directory, base URL, auth token status) |
82
- | `rebase_project_status` | (none) | Perform a health check on the active project's backend URL |
97
+ | `rebase_schema_generate` | | Generate Drizzle schema from Rebase TypeScript collection definitions |
98
+ | `rebase_db_push` | | Apply the current Drizzle schema directly to the database (development shortcut, skips migration files) |
99
+ | `rebase_schema_introspect` | | Introspect the live database and generate Rebase collection definitions from existing tables |
100
+ | `rebase_db_generate` | | Generate SQL migration files from schema changes (compares current Drizzle schema against the last entity) |
101
+ | `rebase_db_migrate` | | Run all pending SQL migrations against the database |
102
+ | `rebase_generate_sdk` | | Generate a fully-typed JavaScript/TypeScript SDK from collection definitions |
103
+ | `rebase_doctor` | — | Detect schema drift between collection definitions, generated Drizzle schema, and the live PostgreSQL database |
104
+ | `rebase_db_branch_create` ⚠ | `name` | Create a new database branch (Admins only) |
105
+ | `rebase_db_branch_list` | — | List all database branches (Admins only) |
106
+ | `rebase_db_branch_delete` ⚠ | `name` | Delete an existing database branch (Admins only) |
107
+ | `rebase_db_branch_info` | `name` | Show information and status for a database branch (Admins only) |
108
+ | `rebase_db_branch_switch` | — | Point this checkout at a database branch, or back at the main database (Admins only) |
109
+
110
+ ### Schema planning (1)
111
+
112
+ Ask the backend what a change would do. No CLI, no files written.
113
+
114
+ | Tool | Required | Description |
115
+ |---|---|---|
116
+ | `rebase_schema_plan` | `collectionId`, `collection` | Show the SQL a collection change would run, without running any of it |
83
117
 
84
- ### CLI Tools (6)
118
+ ### Documents (5)
85
119
 
86
- Spawn `npx rebase <command>` in the active project directory.
120
+ CRUD over a collection through `@rebasepro/client`.
87
121
 
88
- | Tool | Description |
89
- |---|---|
90
- | `rebase_schema_generate` | Generate Drizzle schema from collection definitions |
91
- | `rebase_db_push` | Apply schema directly to DB (dev shortcut) |
92
- | `rebase_schema_introspect` | Introspect live DB collection definitions |
93
- | `rebase_db_generate` | Generate SQL migration files from schema diff |
94
- | `rebase_db_migrate` | Run pending SQL migrations |
95
- | `rebase_generate_sdk` | Generate typed TypeScript SDK |
122
+ | Tool | Required | Description |
123
+ |---|---|---|
124
+ | `list_documents` | `collection` | List documents from a Rebase collection with optional filtering, sorting, and pagination |
125
+ | `get_document` | `collection`, `id` | Get a single document by ID from a Rebase collection |
126
+ | `create_document` | `collection`, `data` | Create a new document in a Rebase collection |
127
+ | `update_document` | `collection`, `id`, `data` | Update an existing document in a Rebase collection |
128
+ | `delete_document` | `collection`, `id` | Delete a document from a Rebase collection |
129
+
130
+ ### Users & roles (6)
96
131
 
97
- ### Data Tools (5)
132
+ | Tool | Required | Description |
133
+ |---|---|---|
134
+ | `list_users` | — | List all users registered in the Rebase backend, including their roles |
135
+ | `create_user` ⚠ | `email` | Create a new user in the Rebase backend |
136
+ | `update_user` ⚠ | `uid` | Update an existing user (email, display name, roles) |
137
+ | `delete_user` ⚠ | `uid` | Delete a user from the Rebase backend |
138
+ | `list_roles` | — | List all roles defined in the Rebase backend |
139
+ | `rebase_auth_reset_password` ⚠ | `email` | Reset a user's password via the admin API |
98
140
 
99
- CRUD operations via `@rebasepro/client` on the active project.
141
+ ### Dev server (3)
100
142
 
101
- | Tool | Required Args | Description |
143
+ | Tool | Required | Description |
102
144
  |---|---|---|
103
- | `list_documents` | `collection` | List with optional `limit`, `offset`, `orderBy`, `where` |
104
- | `get_document` | `collection`, `id` | Get single document by ID |
105
- | `create_document` | `collection`, `data` | Create a new document |
106
- | `update_document` | `collection`, `id`, `data` | Update existing document |
107
- | `delete_document` | `collection`, `id` | Delete a document |
145
+ | `rebase_dev_start` | | Start the Rebase development server (frontend + backend) |
146
+ | `rebase_dev_logs` | | Read recent output from the running Rebase dev server |
147
+ | `rebase_dev_stop` | | Stop the running Rebase development server |
108
148
 
109
- ### Admin Tools (6)
149
+ ### Storage (3)
150
+
151
+ | Tool | Required | Description |
152
+ |---|---|---|
153
+ | `storage_list_objects` | — | List files/objects stored in Rebase storage |
154
+ | `storage_delete_object` ⚠ | `key` | Delete an object/file from Rebase storage |
155
+ | `storage_get_download_url` | `key` | Mint a temporary signed download URL for a file in Rebase storage |
110
156
 
111
- User and role management.
157
+ ### Cron (5)
112
158
 
113
- | Tool | Required Args | Description |
159
+ | Tool | Required | Description |
114
160
  |---|---|---|
115
- | `list_users` | (none) | List all users with roles |
116
- | `create_user` | `email` | Create user (optional: `displayName`, `password`, `roles`) |
117
- | `update_user` | `userId` | Update user (optional: `email`, `displayName`, `roles`) |
118
- | `delete_user` | `userId` | Delete a user |
119
- | `list_roles` | (none) | List all defined roles |
120
- | `rebase_auth_reset_password` | `email` | Reset a user's password using the admin API (optional: `password`) |
161
+ | `cron_list_jobs` | | List all scheduled cron jobs and their configuration status |
162
+ | `cron_get_job` | `jobId` | Get status and details of a specific scheduled cron job |
163
+ | `cron_trigger_job` | `jobId` | Manually trigger a cron job run immediately |
164
+ | `cron_get_job_logs` | `jobId` | Read execution logs for a specific cron job |
165
+ | `cron_toggle_job` | `jobId`, `enabled` | Enable or disable a scheduled cron job |
121
166
 
122
- > [!NOTE]
123
- > `rebase_auth_reset_password` now calls the running admin endpoint instead of performing direct database queries. This makes it compatible with both local development and remote servers.
167
+ ### Functions (1)
124
168
 
125
- ### Dev Server Tools (3)
169
+ | Tool | Required | Description |
170
+ |---|---|---|
171
+ | `invoke_function` ⚠ | `name` | Invoke a custom backend Hono function (located in api/functions/:name) |
126
172
 
127
- Manage the local development server.
173
+ ### Project registry (6)
128
174
 
129
- | Tool | Description |
130
- |---|---|
131
- | `rebase_dev_start` | Start `pnpm run dev` in the `app/` directory |
132
- | `rebase_dev_logs` | Read recent output (default: 50 lines, max buffer: 500) |
133
- | `rebase_dev_stop` | Send SIGTERM to the dev server process |
175
+ | Tool | Required | Description |
176
+ |---|---|---|
177
+ | `rebase_project_list` | | List all registered Rebase projects and show which one is active |
178
+ | `rebase_project_switch` | `name` | Switch the active Rebase project by name |
179
+ | `rebase_project_add` | `name` | Register a new Rebase project |
180
+ | `rebase_project_remove` | `name` | Remove a registered project from the project registry |
181
+ | `rebase_project_current` | — | Show details about the currently active Rebase project, including resolved URL and auth status |
182
+ | `rebase_project_status` | — | Health-check the active project's backend by calling GET /health |
183
+
184
+ <!-- /generated: mcp tool tables -->
134
185
 
135
186
  ---
136
187
 
@@ -154,7 +205,7 @@ Add to your AI assistant's MCP config (e.g. `.gemini/settings.json`):
154
205
  "mcpServers": {
155
206
  "rebase": {
156
207
  "command": "npx",
157
- "args": ["rebase-mcp"],
208
+ "args": ["-y", "@rebasepro/mcp"],
158
209
  "env": {
159
210
  "REBASE_PROJECT_DIR": "/path/to/your/project"
160
211
  }
package/dist/index.d.ts CHANGED
@@ -43,6 +43,49 @@ export interface ProjectConfig {
43
43
  /** ISO timestamp when the project was registered. */
44
44
  addedAt: string;
45
45
  }
46
+ /**
47
+ * Read `.rebase/state.json` from a project directory to auto-discover
48
+ * a running dev server's URL and service key.
49
+ */
50
+ declare function readDevState(projectDir: string): {
51
+ baseUrl: string;
52
+ serviceKey?: string;
53
+ pid?: number;
54
+ } | null;
55
+ /**
56
+ * Try to auto-discover the backend from `.rebase/state.json` in the project dir.
57
+ * Updates the project config in the registry if a running server is found.
58
+ *
59
+ * Discovery fills gaps. It never overrules what the operator wrote down —
60
+ * neither the token nor the URL. Overruling the URL was worse than overruling
61
+ * the token: a project registered against staging or production had its
62
+ * `baseUrl` replaced by `http://localhost:<devport>` for as long as
63
+ * `rebase dev` happened to be running in that directory, and every tool then
64
+ * delivered that project's `rk_live_` key to the local backend. The registered
65
+ * value is the deliberate one; the state file is a convenience.
66
+ *
67
+ * @param devState - Injected for tests; read from the project dir by default.
68
+ */
69
+ export declare function autoDiscoverLocal(project: ProjectConfig, devState?: ReturnType<typeof readDevState> | undefined): ProjectConfig;
70
+ /**
71
+ * The env vars that describe a `default` project, or `null` when the client
72
+ * declared none of them.
73
+ *
74
+ * `ENV_PROJECT_DIR` cannot answer this on its own: it falls back to
75
+ * `process.cwd()`, so it is always truthy and "was it set?" has to be asked of
76
+ * `process.env` directly.
77
+ */
78
+ export declare function envDeclaredProject(env?: NodeJS.ProcessEnv): {
79
+ projectDir?: string;
80
+ baseUrl?: string;
81
+ token?: string;
82
+ } | null;
83
+ /**
84
+ * Where a project points when nobody said and no dev server is running.
85
+ * The last resort, applied after discovery — never written into the registry,
86
+ * because a stored value would then outrank the dev server discovery is for.
87
+ */
88
+ export declare const DEFAULT_BASE_URL = "http://localhost:3001";
46
89
  /**
47
90
  * Tools that only read from the target environment.
48
91
  *
@@ -187,6 +230,21 @@ interface ToolDef {
187
230
  };
188
231
  }
189
232
  export declare const ALL_TOOLS: ToolDef[];
233
+ /** The last `count` lines of a blob of output, without its trailing blank. */
234
+ export declare function lastLines(text: string, count: number): string;
235
+ /**
236
+ * A dev server this process did not spawn, named rather than denied.
237
+ *
238
+ * `devProcess` is only the child `rebase_dev_start` made, so "Dev server is not
239
+ * running." was what `rebase_dev_logs` and `rebase_dev_stop` answered while one
240
+ * was running in a terminal — in the same session where
241
+ * `rebase_project_current` was reporting that server's URL, discovered from the
242
+ * same `.rebase/state.json` these two never read. The output belongs to the
243
+ * terminal that started it, and so does the decision to stop it.
244
+ *
245
+ * @returns The sentence to answer with, or `null` when nothing is running.
246
+ */
247
+ export declare function describeForeignDevServer(action: "logs" | "stop", state?: ReturnType<typeof readDevState> | undefined): string | null;
190
248
  /**
191
249
  * Wrap content that came out of the target environment in an explicit
192
250
  * untrusted-data envelope.
@@ -201,6 +259,20 @@ export declare const ALL_TOOLS: ToolDef[];
201
259
  * all is below the floor.
202
260
  */
203
261
  export declare function untrustedEnvelope(source: string, body: string): string;
262
+ /**
263
+ * A tool error with the two facts a caller needs to act on it.
264
+ *
265
+ * `fetch failed` is what Node says when nothing is listening, and on its own it
266
+ * is the least useful sentence in this file: it names no host, no port and no
267
+ * next step. The agent's actual situation — nine times out of ten — is that
268
+ * `rebase dev` is not running, and it holds the tool that starts it.
269
+ *
270
+ * The URL matters as much as the remedy. The active project is sticky and lives
271
+ * outside the repository, so "which backend did it even try?" is a real
272
+ * question, and answering it is how somebody notices they are pointed at the
273
+ * wrong project rather than at a stopped one.
274
+ */
275
+ export declare function explainToolError(err: unknown, baseUrl?: string, toolName?: string): string;
204
276
  /**
205
277
  * Where a project's backend lives, across the two layouts that exist.
206
278
  *
@@ -228,5 +300,15 @@ export declare function findBackendDir(projectDir?: string): string | null;
228
300
  * tool call.
229
301
  */
230
302
  export declare function findDevDir(projectDir?: string): string;
303
+ /**
304
+ * `--help` and `--version`, answered before anything connects.
305
+ *
306
+ * A stdio MCP server run by hand is the normal way to check that a config block
307
+ * works, and this one answered `--version` by opening a transport and waiting
308
+ * for a client that was never coming — a hang with no output, which reads as a
309
+ * broken install rather than as a server doing exactly what it was told.
310
+ *
311
+ * @returns true when the process has answered and should exit.
312
+ */
313
+ export declare function answerCliFlags(argv?: string[]): boolean;
231
314
  export {};
232
- //# sourceMappingURL=index.d.ts.map