@rebasepro/mcp 0.25.1 → 0.27.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
@@ -37,7 +37,7 @@ The MCP server supports managing multiple Rebase projects simultaneously. This i
37
37
 
38
38
  One precedence, in this order:
39
39
 
40
- 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.
40
+ 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. 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.
41
41
  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.
42
42
  3. **The persisted `default`**, when neither of the first two says anything.
43
43
 
@@ -55,7 +55,7 @@ The server reads configuration from environment variables and `.env` files:
55
55
  |---|---|---|
56
56
  | `REBASE_PROJECT_DIR` | `process.cwd()` | Project root directory (the `rebase.json` directory) |
57
57
  | `REBASE_BASE_URL` | `http://localhost:3001` | Rebase backend URL, when discovery finds no dev server |
58
- | `REBASE_API_TOKEN` / `REBASE_TOKEN` | (empty) | Auth token for API calls |
58
+ | `REBASE_API_TOKEN` | (empty) | Auth token for API calls to the app. `REBASE_TOKEN` (the CLI's control-plane token) is never sent to the app; the cloud tools pass it to the CLI only |
59
59
  | `REBASE_MCP_ALLOW_REMOTE_WRITES` | `false` | Allow destructive tools to run against non-local targets (see below) |
60
60
 
61
61
  The server attempts to load `.env` from `$REBASE_PROJECT_DIR/.env` or `$REBASE_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.
@@ -66,7 +66,8 @@ The server attempts to load `.env` from `$REBASE_PROJECT_DIR/.env` or `$REBASE_P
66
66
 
67
67
  **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:
68
68
 
69
- - **Not gated — reads:** `rebase_schema_plan`, `rebase_doctor`, `rebase_db_branch_list`, `rebase_db_branch_info`, `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`, `rebase_dev_logs`.
69
+ - **Not gated — reads:** `rebase_schema_plan`, `rebase_doctor`, `rebase_db_branch_list`, `rebase_db_branch_info`, `rebase_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`, `rebase_dev_logs`, and the Rebase Cloud reads `rebase_cloud_status`, `rebase_cloud_logs`, `rebase_cloud_env_list`, `rebase_cloud_deployments_list`.
70
+ - **Not gated — Rebase Cloud writes:** `rebase_cloud_provision`, `rebase_cloud_deploy`, `rebase_cloud_env_set`, `rebase_cloud_rollback`. Provisioning creates a project and links this directory; the others change the linked cloud project, but they spawn `rebase 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.
70
71
  - **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.
71
72
  - **Gated against `DATABASE_URL`:** every other CLI tool — `rebase_db_push`, `rebase_db_migrate`, `rebase_db_branch_create`, `rebase_db_branch_delete`.
72
73
  - **Gated against the project `baseUrl`:** every other SDK tool — `create_document`, `update_document`, `delete_document`, `create_user`, `update_user`, `delete_user`, `rebase_auth_reset_password`, `storage_delete_object`, `cron_trigger_job`, `cron_toggle_job`, `invoke_function`.
@@ -91,10 +92,10 @@ Rows, user records, storage listings, cron jobs, function responses and CLI outp
91
92
 
92
93
  <!-- generated: mcp tool tables — pnpm generate:mcp-readme -->
93
94
 
94
- 42 tools, in 9 groups. Tools marked ⚠ are refused against a non-local
95
+ 53 tools, in 10 groups. Tools marked ⚠ are refused against a non-local
95
96
  target unless `REBASE_MCP_ALLOW_REMOTE_WRITES=true` — see the gate above.
96
97
 
97
- ### Schema & database (12)
98
+ ### Schema & database (13)
98
99
 
99
100
  Spawn the Rebase CLI in the active project directory.
100
101
 
@@ -111,6 +112,7 @@ Spawn the Rebase CLI in the active project directory.
111
112
  | `rebase_db_branch_list` | — | List all database branches (Admins only) |
112
113
  | `rebase_db_branch_delete` ⚠ | `name` | Delete an existing database branch (Admins only) |
113
114
  | `rebase_db_branch_info` | `name` | Show information and status for a database branch (Admins only) |
115
+ | `rebase_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 |
114
116
  | `rebase_db_branch_switch` | — | Point this checkout at a database branch, or back at the main database (Admins only) |
115
117
 
116
118
  ### Schema planning (1)
@@ -174,19 +176,36 @@ CRUD over a collection through `@rebasepro/client`.
174
176
 
175
177
  | Tool | Required | Description |
176
178
  |---|---|---|
177
- | `invoke_function` ⚠ | `name` | Invoke a custom backend Hono function (located in api/functions/:name) |
179
+ | `invoke_function` ⚠ | `name` | Invoke a custom backend Hono function (in backend/functions/<name>.ts, served at /api/functions/<name>) |
178
180
 
179
- ### Project registry (6)
181
+ ### Project registry (7)
180
182
 
181
183
  | Tool | Required | Description |
182
184
  |---|---|---|
183
185
  | `rebase_project_list` | — | List all registered Rebase projects and show which one is active |
184
186
  | `rebase_project_switch` | `name` | Switch the active Rebase project by name |
187
+ | `rebase_project_use_cloud` | `project` | Point the data and admin tools (list_documents, get_document, list_users, list_roles, cron_list_jobs, storage_list_objects…) at a Rebase Cloud project's production backend, by its id, slug or name — any project the signed-in account can reach, linked here or not |
185
188
  | `rebase_project_add` | `name` | Register a new Rebase project |
186
189
  | `rebase_project_remove` | `name` | Remove a registered project from the project registry |
187
190
  | `rebase_project_current` | — | Show details about the currently active Rebase project, including resolved URL and auth status |
188
191
  | `rebase_project_status` | — | Health-check the active project's backend by calling GET /health |
189
192
 
193
+ ### Rebase Cloud (9)
194
+
195
+ Spawn `rebase 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`.
196
+
197
+ | Tool | Required | Description |
198
+ |---|---|---|
199
+ | `rebase_cloud_provision` | — | Give the active project a live backend on Rebase Cloud with no account or signup: provisions a project, sets REBASE_BASE_URL in .env, links the directory and deploys the local collections to it (`rebase cloud init --claim`), then sets REBASE_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 |
200
+ | `rebase_cloud_projects_list` | — | List every Rebase Cloud project the signed-in account can reach, across all its organizations (`rebase cloud projects list --all-orgs`): id, name, slug, host and status |
201
+ | `rebase_cloud_status` | — | Show the Rebase Cloud project this directory is linked to (`rebase cloud status`) |
202
+ | `rebase_cloud_deploy` | — | Deploy this directory to its linked Rebase Cloud project (`rebase cloud deploy`) |
203
+ | `rebase_cloud_logs` | — | Read the linked Rebase Cloud project's log once, the running app's or the latest build's (`rebase cloud logs`) |
204
+ | `rebase_cloud_env_list` | — | List the linked Rebase Cloud project's environment variables, never their values (`rebase cloud env list`) |
205
+ | `rebase_cloud_env_set` | `key`, `value` | Set one environment variable on the linked Rebase Cloud project (`rebase cloud env set KEY --stdin`) |
206
+ | `rebase_cloud_deployments_list` | — | List the linked Rebase Cloud project's recent deployments, newest first (`rebase cloud deployments list`) |
207
+ | `rebase_cloud_rollback` | — | Put a previous successful deployment of the linked Rebase Cloud project back into service (`rebase cloud rollback`) |
208
+
190
209
  <!-- /generated: mcp tool tables -->
191
210
 
192
211
  ---
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The Rebase Cloud tools past provisioning: status, deploy, logs, env,
3
+ * deployment history and rollback.
4
+ *
5
+ * Each one is `rebase cloud <command> --json`, spawned in the active project
6
+ * directory — the same command a person runs, against the project that
7
+ * directory is linked to, with whatever credential the CLI resolves there
8
+ * (`REBASE_TOKEN`, the token `rebase cloud init --claim` stored, or the
9
+ * `rebase cloud login` session). So there is no second implementation to drift
10
+ * and no second authority: the control plane checks the call exactly as it
11
+ * checks the CLI's.
12
+ *
13
+ * This module turns validated tool arguments into that argv and reads the one
14
+ * JSON value the CLI prints back. It holds no I/O; `index.ts` spawns.
15
+ *
16
+ * The arguments are checked against the tool's own advertised `inputSchema`
17
+ * (`validateToolArgs`), so what a client is told it may send and what is
18
+ * accepted are one declaration, and every string that reaches argv either
19
+ * matches a pattern that rules out a flag or rides in a `--flag=value` form
20
+ * that keeps it a value.
21
+ */
22
+ /** One property of a tool's input schema, the subset these tools use. */
23
+ export interface PropertySchema {
24
+ type: "string" | "boolean" | "integer";
25
+ description?: string;
26
+ enum?: string[];
27
+ pattern?: string;
28
+ minLength?: number;
29
+ maxLength?: number;
30
+ minimum?: number;
31
+ maximum?: number;
32
+ }
33
+ /** A tool's input schema, as it is advertised in `tools/list`. */
34
+ export interface ToolInputSchema {
35
+ type: "object";
36
+ properties: Record<string, unknown>;
37
+ required?: string[];
38
+ additionalProperties?: boolean;
39
+ }
40
+ /** A refusal of a tool's arguments: nothing was spawned. */
41
+ export declare class ToolArgumentError extends Error {
42
+ }
43
+ export type ToolArgs = Record<string, string | boolean | number>;
44
+ /**
45
+ * `args` checked against `schema`: unknown keys (under
46
+ * `additionalProperties: false`), missing required keys, wrong types, enums,
47
+ * lengths, patterns and integer bounds are each refused by name.
48
+ */
49
+ export declare function validateToolArgs(toolName: string, schema: ToolInputSchema, args: unknown): ToolArgs;
50
+ /** The names of the tools this module builds calls for. */
51
+ export declare const CLOUD_COMMAND_TOOLS: readonly ["rebase_cloud_status", "rebase_cloud_deploy", "rebase_cloud_logs", "rebase_cloud_env_list", "rebase_cloud_env_set", "rebase_cloud_deployments_list", "rebase_cloud_rollback", "rebase_cloud_projects_list"];
52
+ export type CloudCommandTool = (typeof CLOUD_COMMAND_TOOLS)[number];
53
+ export declare function isCloudCommandTool(name: string): name is CloudCommandTool;
54
+ /** What `rebase_cloud_logs` returns when no `tail` is given. */
55
+ export declare const CLOUD_LOGS_DEFAULT_TAIL = 200;
56
+ /** One spawn of the CLI, ready to run. */
57
+ export interface CloudCall {
58
+ /** After `rebase`. Always ends in a `--json` somewhere. */
59
+ argv: string[];
60
+ /** Written to the child's stdin, then closed. Only `env set` uses it, for the value. */
61
+ stdin?: string;
62
+ /** Never to appear in what the tool returns: a variable's value. */
63
+ secrets: string[];
64
+ /** The command as a person would read it, for messages. */
65
+ command: string;
66
+ /** How many lines of any `logs` in the result to keep. */
67
+ tailLines: number;
68
+ }
69
+ /** `validateToolArgs`, then the argv for that tool. Throws `ToolArgumentError`. */
70
+ export declare function cloudToolCall(name: CloudCommandTool, schema: ToolInputSchema, rawArgs: unknown): CloudCall;
71
+ /** Every secret in `text` replaced. Short values too: a value is never echoed, whatever its length. */
72
+ export declare function redactSecrets(text: string, secrets: string[]): string;
73
+ /**
74
+ * The one JSON value the CLI printed on stdout, or undefined when it printed
75
+ * none. A build tool a deploy runs can write to stdout ahead of it, so when
76
+ * the whole of stdout does not parse, the last object that starts a line and
77
+ * runs to the end is the result.
78
+ */
79
+ export declare function parseCliJson(stdout: string): unknown;
80
+ /** A refusal the CLI printed (`{ error: { code, message, … } }`), or null. */
81
+ export declare function cliRefusal(value: unknown): {
82
+ code: string;
83
+ status: number | null;
84
+ message: string;
85
+ error: Record<string, unknown>;
86
+ } | null;
87
+ /** The last `count` lines of a log, and whether any were dropped. */
88
+ export declare function tailLog(logs: string, count: number): {
89
+ logs: string;
90
+ dropped: number;
91
+ };
92
+ /**
93
+ * A value with every `logs` string in it cut to its last `count` lines: a
94
+ * failed deploy's error carries the whole build log, and a build log has no
95
+ * tail of its own. What was dropped is said beside it.
96
+ */
97
+ export declare function withTailedLogs(value: unknown, count: number): unknown;
98
+ /**
99
+ * The way forward after a refusal this server recognises, or null. Written
100
+ * here, so it is trusted text; the CLI's own message stays fenced as untrusted
101
+ * data beside it.
102
+ */
103
+ export declare function cloudRefusalNext(tool: CloudCommandTool, refusal: {
104
+ code: string;
105
+ status: number | null;
106
+ message: string;
107
+ }): string | null;
108
+ /** What to do with a successful result, as trusted text placed before the fenced data. */
109
+ export declare function cloudSuccessNext(tool: CloudCommandTool, call: CloudCall): string;
110
+ /**
111
+ * What `rebase_cloud_env_set` hands back: the shape of what was stored, from
112
+ * its own arguments and the CLI's booleans — never a value, and nothing the
113
+ * control plane wrote, so it needs no fence.
114
+ */
115
+ export declare function envSetResult(call: CloudCall, value: unknown): Record<string, unknown>;
@@ -0,0 +1,408 @@
1
+ /**
2
+ * The Rebase Cloud tools past provisioning: status, deploy, logs, env,
3
+ * deployment history and rollback.
4
+ *
5
+ * Each one is `rebase cloud <command> --json`, spawned in the active project
6
+ * directory — the same command a person runs, against the project that
7
+ * directory is linked to, with whatever credential the CLI resolves there
8
+ * (`REBASE_TOKEN`, the token `rebase cloud init --claim` stored, or the
9
+ * `rebase cloud login` session). So there is no second implementation to drift
10
+ * and no second authority: the control plane checks the call exactly as it
11
+ * checks the CLI's.
12
+ *
13
+ * This module turns validated tool arguments into that argv and reads the one
14
+ * JSON value the CLI prints back. It holds no I/O; `index.ts` spawns.
15
+ *
16
+ * The arguments are checked against the tool's own advertised `inputSchema`
17
+ * (`validateToolArgs`), so what a client is told it may send and what is
18
+ * accepted are one declaration, and every string that reaches argv either
19
+ * matches a pattern that rules out a flag or rides in a `--flag=value` form
20
+ * that keeps it a value.
21
+ */
22
+ /** A refusal of a tool's arguments: nothing was spawned. */
23
+ export class ToolArgumentError extends Error {
24
+ }
25
+ function isPropertySchema(value) {
26
+ if (typeof value !== "object" || value === null || !("type" in value))
27
+ return false;
28
+ return value.type === "string" || value.type === "boolean" || value.type === "integer";
29
+ }
30
+ /**
31
+ * `args` checked against `schema`: unknown keys (under
32
+ * `additionalProperties: false`), missing required keys, wrong types, enums,
33
+ * lengths, patterns and integer bounds are each refused by name.
34
+ */
35
+ export function validateToolArgs(toolName, schema, args) {
36
+ if (args === undefined || args === null)
37
+ args = {};
38
+ if (typeof args !== "object" || Array.isArray(args)) {
39
+ throw new ToolArgumentError(`${toolName} takes an object of arguments.`);
40
+ }
41
+ const given = args;
42
+ const known = Object.keys(schema.properties);
43
+ if (schema.additionalProperties === false) {
44
+ const unknown = Object.keys(given).filter((key) => !known.includes(key));
45
+ if (unknown.length > 0) {
46
+ throw new ToolArgumentError(`${toolName} does not take ${unknown.map((k) => `\`${k}\``).join(", ")}. ` +
47
+ (known.length ? `It takes: ${known.map((k) => `\`${k}\``).join(", ")}.` : "It takes no arguments."));
48
+ }
49
+ }
50
+ for (const key of schema.required ?? []) {
51
+ if (given[key] === undefined)
52
+ throw new ToolArgumentError(`${toolName} needs \`${key}\`.`);
53
+ }
54
+ const out = {};
55
+ for (const key of known) {
56
+ const value = given[key];
57
+ if (value === undefined)
58
+ continue;
59
+ const prop = schema.properties[key];
60
+ if (!isPropertySchema(prop))
61
+ throw new ToolArgumentError(`${toolName}: \`${key}\` has no usable schema.`);
62
+ const where = `\`${key}\``;
63
+ if (prop.type === "boolean") {
64
+ if (typeof value !== "boolean")
65
+ throw new ToolArgumentError(`${where} must be true or false.`);
66
+ out[key] = value;
67
+ }
68
+ else if (prop.type === "integer") {
69
+ if (typeof value !== "number" || !Number.isInteger(value))
70
+ throw new ToolArgumentError(`${where} must be a whole number.`);
71
+ if (prop.minimum !== undefined && value < prop.minimum)
72
+ throw new ToolArgumentError(`${where} must be at least ${prop.minimum}.`);
73
+ if (prop.maximum !== undefined && value > prop.maximum)
74
+ throw new ToolArgumentError(`${where} must be at most ${prop.maximum}.`);
75
+ out[key] = value;
76
+ }
77
+ else {
78
+ if (typeof value !== "string")
79
+ throw new ToolArgumentError(`${where} must be a string.`);
80
+ if (prop.enum && !prop.enum.includes(value)) {
81
+ throw new ToolArgumentError(`${where} must be one of ${prop.enum.map((v) => `"${v}"`).join(", ")}.`);
82
+ }
83
+ if (prop.minLength !== undefined && value.length < prop.minLength) {
84
+ throw new ToolArgumentError(`${where} must be at least ${prop.minLength} character${prop.minLength === 1 ? "" : "s"}.`);
85
+ }
86
+ if (prop.maxLength !== undefined && value.length > prop.maxLength) {
87
+ throw new ToolArgumentError(`${where} must be at most ${prop.maxLength} characters.`);
88
+ }
89
+ if (prop.pattern !== undefined && !new RegExp(prop.pattern, "u").test(value)) {
90
+ throw new ToolArgumentError(`${where} is not in the accepted form (${prop.pattern}).`);
91
+ }
92
+ out[key] = value;
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+ /** The names of the tools this module builds calls for. */
98
+ export const CLOUD_COMMAND_TOOLS = [
99
+ "rebase_cloud_status",
100
+ "rebase_cloud_deploy",
101
+ "rebase_cloud_logs",
102
+ "rebase_cloud_env_list",
103
+ "rebase_cloud_env_set",
104
+ "rebase_cloud_deployments_list",
105
+ "rebase_cloud_rollback",
106
+ "rebase_cloud_projects_list"
107
+ ];
108
+ export function isCloudCommandTool(name) {
109
+ return CLOUD_COMMAND_TOOLS.includes(name);
110
+ }
111
+ /** What `rebase_cloud_logs` returns when no `tail` is given. */
112
+ export const CLOUD_LOGS_DEFAULT_TAIL = 200;
113
+ /** The runtime-log arguments a build log has no meaning for. */
114
+ const RUNTIME_ONLY_LOG_ARGS = ["since", "grep", "level", "previous"];
115
+ /** `validateToolArgs`, then the argv for that tool. Throws `ToolArgumentError`. */
116
+ export function cloudToolCall(name, schema, rawArgs) {
117
+ const args = validateToolArgs(name, schema, rawArgs);
118
+ const str = (key) => (typeof args[key] === "string" ? args[key] : undefined);
119
+ const num = (key) => (typeof args[key] === "number" ? args[key] : undefined);
120
+ const flag = (key) => args[key] === true;
121
+ switch (name) {
122
+ case "rebase_cloud_status":
123
+ return { argv: ["cloud", "status", "--json"], secrets: [], command: "rebase cloud status", tailLines: CLOUD_LOGS_DEFAULT_TAIL };
124
+ case "rebase_cloud_projects_list":
125
+ return {
126
+ argv: ["cloud", "projects", "list", "--all-orgs", "--json"],
127
+ secrets: [],
128
+ command: "rebase cloud projects list --all-orgs",
129
+ tailLines: CLOUD_LOGS_DEFAULT_TAIL
130
+ };
131
+ case "rebase_cloud_deploy": {
132
+ const argv = ["cloud", "deploy"];
133
+ const app = str("app");
134
+ if (app)
135
+ argv.push(app);
136
+ argv.push("--json");
137
+ if (flag("bundle"))
138
+ argv.push("--bundle");
139
+ const message = str("message");
140
+ if (message !== undefined)
141
+ argv.push(`--message=${message}`);
142
+ if (args.wait === true)
143
+ argv.push("--wait");
144
+ if (args.wait === false) {
145
+ if (num("timeoutSeconds") !== undefined) {
146
+ throw new ToolArgumentError("`timeoutSeconds` bounds the wait, and `wait: false` does not wait. Pass one of them.");
147
+ }
148
+ argv.push("--no-follow");
149
+ }
150
+ const timeout = num("timeoutSeconds");
151
+ if (timeout !== undefined)
152
+ argv.push(`--timeout=${timeout}`);
153
+ const previewName = str("previewName");
154
+ if (previewName !== undefined)
155
+ argv.push(`--preview-name=${previewName}`);
156
+ else if (flag("preview"))
157
+ argv.push("--preview");
158
+ return { argv, secrets: [], command: `rebase cloud deploy${app ? ` ${app}` : ""}`, tailLines: CLOUD_LOGS_DEFAULT_TAIL };
159
+ }
160
+ case "rebase_cloud_logs": {
161
+ const source = str("source") ?? "runtime";
162
+ const tailLines = num("tail") ?? CLOUD_LOGS_DEFAULT_TAIL;
163
+ const argv = ["cloud", "logs"];
164
+ if (source === "runtime") {
165
+ argv.push("--runtime", "--json", `--tail=${tailLines}`);
166
+ const since = str("since");
167
+ if (since !== undefined)
168
+ argv.push(`--since=${since}`);
169
+ const grep = str("grep");
170
+ if (grep !== undefined)
171
+ argv.push(`--grep=${grep}`);
172
+ const level = str("level");
173
+ if (level !== undefined)
174
+ argv.push(`--level=${level}`);
175
+ if (flag("previous"))
176
+ argv.push("--previous");
177
+ }
178
+ else {
179
+ const stray = RUNTIME_ONLY_LOG_ARGS.filter((key) => args[key] !== undefined);
180
+ if (stray.length > 0) {
181
+ throw new ToolArgumentError(`${stray.map((k) => `\`${k}\``).join(", ")} ${stray.length === 1 ? "reads" : "read"} the running app's log, ` +
182
+ "and `source: \"build\"` is the latest build's. Drop them, or use `source: \"runtime\"`.");
183
+ }
184
+ argv.push("--json");
185
+ }
186
+ const preview = str("preview");
187
+ if (preview !== undefined)
188
+ argv.push("--preview", preview);
189
+ return { argv, secrets: [], command: `rebase cloud logs${source === "runtime" ? " --runtime" : ""}`, tailLines };
190
+ }
191
+ case "rebase_cloud_env_list": {
192
+ const argv = ["cloud", "env", "list", "--json"];
193
+ if (flag("preview"))
194
+ argv.push("--preview");
195
+ return { argv, secrets: [], command: "rebase cloud env list", tailLines: CLOUD_LOGS_DEFAULT_TAIL };
196
+ }
197
+ case "rebase_cloud_env_set": {
198
+ const key = str("key") ?? "";
199
+ const value = str("value") ?? "";
200
+ // The value goes through stdin: on argv every process on the
201
+ // machine could read it, and it would be in this server's own
202
+ // spawn arguments.
203
+ const argv = ["cloud", "env", "set", key, "--stdin", "--json"];
204
+ if (flag("secret"))
205
+ argv.push("--secret");
206
+ if (flag("preview"))
207
+ argv.push("--preview");
208
+ return { argv, stdin: value, secrets: value ? [value] : [], command: `rebase cloud env set ${key}`, tailLines: CLOUD_LOGS_DEFAULT_TAIL };
209
+ }
210
+ case "rebase_cloud_deployments_list": {
211
+ const argv = ["cloud", "deployments", "list", "--json"];
212
+ const limit = num("limit");
213
+ if (limit !== undefined)
214
+ argv.push(`--limit=${limit}`);
215
+ return { argv, secrets: [], command: "rebase cloud deployments list", tailLines: CLOUD_LOGS_DEFAULT_TAIL };
216
+ }
217
+ case "rebase_cloud_rollback": {
218
+ const argv = ["cloud", "rollback"];
219
+ const id = str("deploymentId");
220
+ if (id)
221
+ argv.push(id);
222
+ // The tool call is the confirmation: an MCP call has no terminal to
223
+ // prompt on, and the CLI refuses to roll back without one or this.
224
+ argv.push("--yes", "--json");
225
+ return { argv, secrets: [], command: `rebase cloud rollback${id ? ` ${id}` : ""}`, tailLines: CLOUD_LOGS_DEFAULT_TAIL };
226
+ }
227
+ }
228
+ }
229
+ /** Every secret in `text` replaced. Short values too: a value is never echoed, whatever its length. */
230
+ export function redactSecrets(text, secrets) {
231
+ let out = text;
232
+ for (const secret of secrets) {
233
+ if (secret)
234
+ out = out.split(secret).join("[redacted]");
235
+ }
236
+ return out;
237
+ }
238
+ /**
239
+ * The one JSON value the CLI printed on stdout, or undefined when it printed
240
+ * none. A build tool a deploy runs can write to stdout ahead of it, so when
241
+ * the whole of stdout does not parse, the last object that starts a line and
242
+ * runs to the end is the result.
243
+ */
244
+ export function parseCliJson(stdout) {
245
+ const text = stdout.trim();
246
+ if (!text)
247
+ return undefined;
248
+ try {
249
+ return JSON.parse(text);
250
+ }
251
+ catch {
252
+ // fall through to the trailing object
253
+ }
254
+ for (let at = text.lastIndexOf("\n{"); at !== -1; at = text.lastIndexOf("\n{", at - 1)) {
255
+ try {
256
+ return JSON.parse(text.slice(at + 1));
257
+ }
258
+ catch {
259
+ if (at === 0)
260
+ break;
261
+ }
262
+ }
263
+ return undefined;
264
+ }
265
+ /** A refusal the CLI printed (`{ error: { code, message, … } }`), or null. */
266
+ export function cliRefusal(value) {
267
+ if (typeof value !== "object" || value === null || !("error" in value))
268
+ return null;
269
+ const error = value.error;
270
+ if (typeof error !== "object" || error === null)
271
+ return null;
272
+ const record = error;
273
+ return {
274
+ code: typeof record.code === "string" ? record.code : "error",
275
+ status: typeof record.status === "number" ? record.status : null,
276
+ message: typeof record.message === "string" ? record.message : "",
277
+ error: record
278
+ };
279
+ }
280
+ /** The last `count` lines of a log, and whether any were dropped. */
281
+ export function tailLog(logs, count) {
282
+ const lines = logs.replace(/\n$/, "").split("\n");
283
+ if (lines.length <= count)
284
+ return { logs, dropped: 0 };
285
+ return { logs: lines.slice(-count).join("\n"), dropped: lines.length - count };
286
+ }
287
+ /**
288
+ * A value with every `logs` string in it cut to its last `count` lines: a
289
+ * failed deploy's error carries the whole build log, and a build log has no
290
+ * tail of its own. What was dropped is said beside it.
291
+ */
292
+ export function withTailedLogs(value, count) {
293
+ if (typeof value !== "object" || value === null || Array.isArray(value))
294
+ return value;
295
+ const out = {};
296
+ for (const [key, field] of Object.entries(value)) {
297
+ if (key === "logs" && typeof field === "string") {
298
+ const { logs, dropped } = tailLog(field, count);
299
+ out.logs = logs;
300
+ if (dropped > 0)
301
+ out.logsLinesDropped = dropped;
302
+ }
303
+ else if (key === "error") {
304
+ out.error = withTailedLogs(field, count);
305
+ }
306
+ else {
307
+ out[key] = field;
308
+ }
309
+ }
310
+ return out;
311
+ }
312
+ /**
313
+ * The way forward after a refusal this server recognises, or null. Written
314
+ * here, so it is trusted text; the CLI's own message stays fenced as untrusted
315
+ * data beside it.
316
+ */
317
+ export function cloudRefusalNext(tool, refusal) {
318
+ switch (refusal.code) {
319
+ case "no_project":
320
+ return "This directory is not linked to a Rebase Cloud project. rebase_cloud_provision gives it one without an account; " +
321
+ "otherwise ask the user to run `rebase cloud link` (or `rebase cloud projects create --link`) here.";
322
+ case "not_logged_in":
323
+ case "session_expired":
324
+ return "The CLI holds no usable credential for the control plane here. Ask the user to run `rebase cloud login`, " +
325
+ "or to set REBASE_TOKEN (from `rebase cloud tokens create`) in this server's environment.";
326
+ case "token_rejected":
327
+ return "The control plane refused the CLI's token. An unclaimed project's token stops working once it is claimed or expires: " +
328
+ "ask the user to sign in with `rebase cloud login` as the account that claimed it.";
329
+ case "session_required":
330
+ return "This needs a person's signed-in session, and the CLI here holds a token. Ask the user to run it.";
331
+ case "payment_required":
332
+ return "The project's organization has no payment method on file, so nothing was deployed. Only the user can add one: " +
333
+ "`rebase cloud billing setup`.";
334
+ case "managed_project":
335
+ return "This project runs on the managed runtime: call rebase_cloud_deploy again with `bundle: true`. " +
336
+ "Moving it off the managed runtime is the user's decision, and no tool here makes it.";
337
+ case "FRAMEWORK_DOWNGRADE":
338
+ return "The bundle was built on an older framework release than the project runs, so nothing was deployed. " +
339
+ "Run `rebase upgrade` in the project and deploy again. Deploying the older release on purpose is the user's call.";
340
+ case "deploy_failed":
341
+ return "The deploy failed: `reason` and the end of `logs` below say why. Fix it and deploy again; " +
342
+ "rebase_cloud_rollback puts the last good deployment back if production is broken.";
343
+ case "build_time_variable":
344
+ return "Nothing was set: the bundler reads this variable at build time, before project variables are applied. " +
345
+ "It belongs in the build (the shell running the deploy, or the app's .env.production), not here.";
346
+ case "deploy_not_rollbackable":
347
+ case "no_deployments":
348
+ return "Nothing was rolled back. rebase_cloud_deployments_list marks the deployments that can be returned to (`rollbackable: true`).";
349
+ case "already_claimed":
350
+ return "The project was claimed: ask the user to sign in with `rebase cloud login` as the account that claimed it.";
351
+ default:
352
+ break;
353
+ }
354
+ if (tool === "rebase_cloud_env_set" && refusal.code === "usage" && refusal.message.includes("--stdin")) {
355
+ return "This project's rebase CLI predates `env set --stdin`, so the value was not sent. Upgrade @rebasepro/cli in the project " +
356
+ "(this server never puts a value on a command line).";
357
+ }
358
+ if (refusal.status === 403 || refusal.code === "platform_permission_denied") {
359
+ return "The credential the CLI used may not do this on this project. Ask the user; a token from `rebase cloud tokens create` " +
360
+ "can be granted the capability.";
361
+ }
362
+ return null;
363
+ }
364
+ /** What to do with a successful result, as trusted text placed before the fenced data. */
365
+ export function cloudSuccessNext(tool, call) {
366
+ switch (tool) {
367
+ case "rebase_cloud_status":
368
+ return "When `unclaimed` is set, the project is deleted at `unclaimed.expiresAt` unless the user opens `unclaimed.claimUrl` " +
369
+ "and signs in: give them that link. A non-null `blockedOn` names something only the user can do; polling will not change it.";
370
+ case "rebase_cloud_deploy":
371
+ return call.argv.includes("--no-follow")
372
+ ? "The deploy was triggered and not followed. rebase_cloud_status shows when it finishes; rebase_cloud_logs with " +
373
+ "`source: \"build\"` shows its build log."
374
+ : "The deploy finished. `live` says whether the new version answered; rebase_cloud_logs shows what it prints.";
375
+ case "rebase_cloud_logs":
376
+ return call.argv.includes("--runtime")
377
+ ? "Pass `nextSinceTime` back as `since` to read only what came after."
378
+ : "This is the latest deployment's build log.";
379
+ case "rebase_cloud_env_list":
380
+ return "Values are never listed. rebase_cloud_env_set replaces one; a change applies on the next rebase_cloud_deploy.";
381
+ case "rebase_cloud_env_set":
382
+ return "It applies on the next deploy: run rebase_cloud_deploy.";
383
+ case "rebase_cloud_deployments_list":
384
+ return "`rollbackable: true` marks the deployments rebase_cloud_rollback can return to.";
385
+ case "rebase_cloud_rollback":
386
+ return "The rollback is a new deployment. rebase_cloud_status shows when it is live; rebase_cloud_logs with `source: \"build\"` shows its progress.";
387
+ case "rebase_cloud_projects_list":
388
+ return "Every project in every organization the signed-in account belongs to. rebase_project_use_cloud with a project's " +
389
+ "`id` or `slug` points the data and admin tools (list_documents, get_document, list_users, cron_list_jobs…) at its " +
390
+ "production backend, through the console's Studio proxy with the same login: no service key is needed or shown.";
391
+ }
392
+ }
393
+ /**
394
+ * What `rebase_cloud_env_set` hands back: the shape of what was stored, from
395
+ * its own arguments and the CLI's booleans — never a value, and nothing the
396
+ * control plane wrote, so it needs no fence.
397
+ */
398
+ export function envSetResult(call, value) {
399
+ const record = typeof value === "object" && value !== null ? value : {};
400
+ const bool = (key) => (typeof record[key] === "boolean" ? record[key] : null);
401
+ return {
402
+ key: call.argv[3],
403
+ secret: bool("secret"),
404
+ preview: call.argv.includes("--preview"),
405
+ pendingRedeploy: bool("pendingRedeploy")
406
+ };
407
+ }
408
+ //# sourceMappingURL=cloud-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-tools.js","sourceRoot":"","sources":["../src/cloud-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAsBH,4DAA4D;AAC5D,MAAM,OAAO,iBAAkB,SA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