@protobase/cli 0.51.3 → 0.52.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/dist/build/app-icons.js +2 -1
- package/dist/build/favicon-file.js +5 -0
- package/dist/build/favicon-ico.js +20 -0
- package/dist/build/favicon.js +1 -2
- package/dist/build/service-worker-code.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +1 -0
- package/dist/dev/entry.js +2 -1
- package/dist/doctor/relation-issues.js +13 -0
- package/dist/doctor/run.js +6 -1
- package/dist/migration/adopt-public-record.js +15 -0
- package/dist/migration/apply-migrations.js +8 -4
- package/dist/migration/load-project.js +1 -0
- package/dist/migration/parts.js +6 -1
- package/dist/project/favicon-link.js +12 -2
- package/dist/project/project-admin.js +1 -0
- package/dist/project/service-worker.js +1 -1
- package/dist/scaffold/plan.d.ts +2 -0
- package/dist/scaffold/plan.js +7 -3
- package/dist/scaffold/protobase-tables.d.ts +1 -1
- package/dist/scaffold/protobase-tables.js +8 -1
- package/dist/scaffold/referenced.d.ts +6 -0
- package/dist/scaffold/referenced.js +38 -0
- package/dist/scaffold/run.js +2 -1
- package/dist/scaffold/tables.d.ts +2 -1
- package/dist/scaffold/tables.js +18 -9
- package/dist/scaffold-api.d.ts +2 -1
- package/dist/scaffold-api.js +2 -1
- package/dist/serve/lifecycle.js +2 -1
- package/dist/serve/static-site.js +3 -0
- package/dist/supabase/dump-phase.js +6 -5
- package/dist/supabase/load-phase.js +5 -6
- package/dist/supabase/platform-schemas.js +42 -0
- package/dist/supabase/project-users.d.ts +10 -0
- package/dist/supabase/project-users.js +38 -0
- package/dist/supabase/report.js +1 -1
- package/dist/supabase/source-facts.js +3 -35
- package/dist/supabase/users-migrations.js +2 -2
- package/package.json +7 -7
- package/skills/protobase/references/features/ai.md +5 -0
- package/skills/protobase/references/features/compatibility.md +1 -1
- package/skills/protobase/references/features/look-and-language.md +1 -1
- package/skills/protobase/references/getting-started.md +5 -3
- package/skills/protobase/references/guides/deploy.md +1 -1
- package/skills/protobase/references/reference/app-identity.md +3 -1
- package/skills/protobase/references/reference/assistant.md +2 -2
- package/skills/protobase/references/reference/cli.md +7 -7
- package/skills/protobase/references/reference/comments.md +2 -0
- package/skills/protobase/references/reference/config/api.md +13 -2
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/mcp.md +43 -10
- package/skills/protobase/references/reference/notifications.md +1 -1
- package/skills/protobase/references/reference/supabase-realtime.md +4 -2
- package/skills/protobase/references/reference/webhooks.md +1 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/supabase/platform-schemas.ts
|
|
2
|
+
/**
|
|
3
|
+
* Schemas of a Supabase database that belong to the platform rather than the app: its services' own (Realtime, Vault,
|
|
4
|
+
* GraphQL, webhooks, migrations, the pooler) and those of its extensions, which the migration makes with them (pgmq's
|
|
5
|
+
* holds only its own tables, but is no member of it). The import leaves them behind.
|
|
6
|
+
*/
|
|
7
|
+
const serviceSchemas = [
|
|
8
|
+
"extensions",
|
|
9
|
+
"graphql",
|
|
10
|
+
"graphql_public",
|
|
11
|
+
"realtime",
|
|
12
|
+
"_realtime",
|
|
13
|
+
"vault",
|
|
14
|
+
"pgsodium",
|
|
15
|
+
"pgsodium_masks",
|
|
16
|
+
"supabase_functions",
|
|
17
|
+
"supabase_migrations",
|
|
18
|
+
"cron",
|
|
19
|
+
"net",
|
|
20
|
+
"pgmq",
|
|
21
|
+
"pgbouncer",
|
|
22
|
+
"_analytics",
|
|
23
|
+
"pgtle"
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Supabase Auth's and Storage's own schemas, which are the platform's too, but the app's tables point at them and its
|
|
27
|
+
* triggers and policies live in them, so the import carries them over; their tables are no resources.
|
|
28
|
+
*/
|
|
29
|
+
const authStorageSchemas = ["auth", "storage"];
|
|
30
|
+
/** What marks a database as Supabase's: its auth, storage and migrations schemas and its roles. */
|
|
31
|
+
const databaseMarkers = async (sql) => {
|
|
32
|
+
const [row] = await sql`
|
|
33
|
+
select
|
|
34
|
+
array(select nspname::text from pg_namespace where nspname in ('auth', 'storage', 'supabase_migrations') order by 1) as schemas,
|
|
35
|
+
array(select rolname::text from pg_roles where rolname in ('anon', 'authenticated', 'service_role', 'supabase_admin') order by 1) as roles
|
|
36
|
+
`;
|
|
37
|
+
return row;
|
|
38
|
+
};
|
|
39
|
+
/** What `markers` lack of a Supabase database, its auth and storage schemas and its own admin role: nothing for one. */
|
|
40
|
+
const missingMarkers = (markers) => [...authStorageSchemas.filter((schema) => !markers.schemas.includes(schema)).map((schema) => `schema ${schema}`), ...markers.roles.includes("supabase_admin") ? [] : ["role supabase_admin"]];
|
|
41
|
+
//#endregion
|
|
42
|
+
export { authStorageSchemas, databaseMarkers, missingMarkers, serviceSchemas };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/supabase/project-users.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Signs the project in `projectDir`, made on a Supabase database, in on Supabase's own auth.users, as `protobase import
|
|
4
|
+
* supabase` does on its copy: points its Better Auth setup at auth.users, removes the migrations of Protobase's own user
|
|
5
|
+
* table, and writes, in `db/migrations`, the columns Better Auth needs on auth.users, Better Auth's tables next to it
|
|
6
|
+
* and the users' accounts with their Supabase passwords and social providers. It only reads the database, which the
|
|
7
|
+
* project's auth keeps a connection pool open on, so the process must end itself.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useSupabaseUsers: (projectDir: string, out: (text: string) => void) => Promise<void>;
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { loadProjectAuth } from "../users/load-auth.js";
|
|
2
|
+
import { writeAuthMigration } from "../auth/write-migration.js";
|
|
3
|
+
import { planAuthConfig } from "./auth-config.js";
|
|
4
|
+
import { writeMigration } from "./migration-files.js";
|
|
5
|
+
import { authStoreMigrations } from "./store-migrations.js";
|
|
6
|
+
import { accountsMigration, usersColumnsMigration } from "./users-migrations.js";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { mkdir, rm } from "node:fs/promises";
|
|
9
|
+
//#region src/supabase/project-users.ts
|
|
10
|
+
/**
|
|
11
|
+
* Signs the project in `projectDir`, made on a Supabase database, in on Supabase's own auth.users, as `protobase import
|
|
12
|
+
* supabase` does on its copy: points its Better Auth setup at auth.users, removes the migrations of Protobase's own user
|
|
13
|
+
* table, and writes, in `db/migrations`, the columns Better Auth needs on auth.users, Better Auth's tables next to it
|
|
14
|
+
* and the users' accounts with their Supabase passwords and social providers. It only reads the database, which the
|
|
15
|
+
* project's auth keeps a connection pool open on, so the process must end itself.
|
|
16
|
+
*/
|
|
17
|
+
const useSupabaseUsers = async (projectDir, out) => {
|
|
18
|
+
const migrationsDir = path.join(projectDir, "db", "migrations");
|
|
19
|
+
const authConfig = await planAuthConfig(projectDir);
|
|
20
|
+
const storeMigrations = await authStoreMigrations(migrationsDir);
|
|
21
|
+
const relative = (to) => path.relative(projectDir, to);
|
|
22
|
+
for (const store of storeMigrations) await rm(path.join(migrationsDir, store));
|
|
23
|
+
await mkdir(migrationsDir, { recursive: true });
|
|
24
|
+
const usersFile = await writeMigration(migrationsDir, "supabase_users", usersColumnsMigration());
|
|
25
|
+
await authConfig.write();
|
|
26
|
+
if (storeMigrations.length > 0) out(`removed ${storeMigrations.length} migrations of Protobase's own user table: auth.users replaces it\n`);
|
|
27
|
+
out(`wrote ${relative(path.join(migrationsDir, usersFile))}, the columns Better Auth needs on auth.users, and pointed ${relative(authConfig.file)} at it\n`);
|
|
28
|
+
const authFile = await writeAuthMigration({
|
|
29
|
+
auth: await loadProjectAuth(projectDir),
|
|
30
|
+
dir: migrationsDir,
|
|
31
|
+
name: "auth"
|
|
32
|
+
});
|
|
33
|
+
if (authFile) out(`wrote ${relative(authFile)}, Better Auth's tables next to auth.users\n`);
|
|
34
|
+
const accountsFile = await writeMigration(migrationsDir, "supabase_accounts", accountsMigration());
|
|
35
|
+
out(`wrote ${relative(path.join(migrationsDir, accountsFile))}, the users' accounts with their Supabase passwords and social providers\n`);
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useSupabaseUsers };
|
package/dist/supabase/report.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { convertedCronJobs } from "./cron-plan.js";
|
|
2
1
|
import { providerFate } from "./identity-providers.js";
|
|
2
|
+
import { convertedCronJobs } from "./cron-plan.js";
|
|
3
3
|
//#region src/supabase/report.ts
|
|
4
4
|
/** Protobase Cloud's Starter plan holds this much data; the import reports a larger database, it does not refuse it. */
|
|
5
5
|
const starterBytes = 524288e3;
|
|
@@ -1,44 +1,12 @@
|
|
|
1
|
+
import { serviceSchemas } from "./platform-schemas.js";
|
|
1
2
|
//#region src/supabase/source-facts.ts
|
|
2
|
-
/**
|
|
3
|
-
* Schemas of a Supabase database that belong to the platform rather than the app: its services' own (Realtime, Vault,
|
|
4
|
-
* GraphQL, webhooks, migrations, the pooler) and those of its extensions, which the migration makes with them (pgmq's
|
|
5
|
-
* holds only its own tables, but is no member of it). auth and storage are the platform's too, but the app's tables
|
|
6
|
-
* point at them and its triggers and policies live in them, so the import carries them over.
|
|
7
|
-
*/
|
|
8
|
-
const platformSchemas = [
|
|
9
|
-
"extensions",
|
|
10
|
-
"graphql",
|
|
11
|
-
"graphql_public",
|
|
12
|
-
"realtime",
|
|
13
|
-
"_realtime",
|
|
14
|
-
"vault",
|
|
15
|
-
"pgsodium",
|
|
16
|
-
"pgsodium_masks",
|
|
17
|
-
"supabase_functions",
|
|
18
|
-
"supabase_migrations",
|
|
19
|
-
"cron",
|
|
20
|
-
"net",
|
|
21
|
-
"pgmq",
|
|
22
|
-
"pgbouncer",
|
|
23
|
-
"_analytics",
|
|
24
|
-
"pgtle"
|
|
25
|
-
];
|
|
26
3
|
/** The tables in auth and storage that record the platform's own migrations, which Protobase never runs. */
|
|
27
4
|
const platformMigrationTables = ["auth.schema_migrations", "storage.migrations"];
|
|
28
|
-
/** What marks a database as Supabase's: its auth, storage and migrations schemas and its roles. */
|
|
29
|
-
const databaseMarkers = async (sql) => {
|
|
30
|
-
const [row] = await sql`
|
|
31
|
-
select
|
|
32
|
-
array(select nspname::text from pg_namespace where nspname in ('auth', 'storage', 'supabase_migrations') order by 1) as schemas,
|
|
33
|
-
array(select rolname::text from pg_roles where rolname in ('anon', 'authenticated', 'service_role', 'supabase_admin') order by 1) as roles
|
|
34
|
-
`;
|
|
35
|
-
return row;
|
|
36
|
-
};
|
|
37
5
|
/** auth, storage and every schema the app made, which the dumps take. */
|
|
38
6
|
const appSchemas = async (sql) => {
|
|
39
7
|
return (await sql`
|
|
40
8
|
select n.nspname as name from pg_namespace n
|
|
41
|
-
where not starts_with(n.nspname, 'pg_') and n.nspname <> 'information_schema' and n.nspname <> all(${
|
|
9
|
+
where not starts_with(n.nspname, 'pg_') and n.nspname <> 'information_schema' and n.nspname <> all(${serviceSchemas})
|
|
42
10
|
and not exists (select 1 from pg_depend d where d.classid = 'pg_namespace'::regclass and d.objid = n.oid and d.deptype = 'e')
|
|
43
11
|
order by 1
|
|
44
12
|
`).map((row) => row.name);
|
|
@@ -190,4 +158,4 @@ const httpTriggers = (sql, schemas) => sql`
|
|
|
190
158
|
order by 1, 2, 3
|
|
191
159
|
`;
|
|
192
160
|
//#endregion
|
|
193
|
-
export { appSchemas, cronJobs, cronTimezone,
|
|
161
|
+
export { appSchemas, cronJobs, cronTimezone, dumpedTables, extensions, httpTriggers, hypertables, pgmqQueues, pgsodiumColumns, platformMigrationTables, realtimeTables, routinesIn, tablesSize, vaultSecretValues, vaultSecrets };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { accountIdSql, accountProviderSql, carriesAccountSql, confirmedOwnerSql } from "./identity-providers.js";
|
|
2
2
|
//#region src/supabase/users-migrations.ts
|
|
3
|
-
/** The
|
|
3
|
+
/** The user columns Better Auth needs that GoTrue's auth.users lacks, empty for now. */
|
|
4
4
|
const usersColumnsMigration = () => `-- The columns Better Auth needs on Supabase's auth.users, written by \`protobase import supabase\`.
|
|
5
5
|
-- Empty until the import's accounts migration fills them from what Supabase recorded; NULL where it recorded nothing.
|
|
6
6
|
alter table auth.users
|
|
@@ -15,7 +15,7 @@ alter table auth.users
|
|
|
15
15
|
-- The value GoTrue writes into every user it makes, for the triggers and policies that read it on new sign-ups.
|
|
16
16
|
alter table auth.users alter column role set default 'authenticated', alter column aud set default 'authenticated';
|
|
17
17
|
`;
|
|
18
|
-
/**
|
|
18
|
+
/** Once auth.users has its rows and Better Auth's tables are planned: the users' columns and accounts. */
|
|
19
19
|
const accountsMigration = () => `-- Supabase's users signing in with Better Auth, written by \`protobase import supabase\` once their rows were loaded.
|
|
20
20
|
|
|
21
21
|
-- The user columns, from what Supabase Auth recorded. A ban lasts until banned_until, as on Supabase: Better Auth lifts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.
|
|
46
|
-
"@protobase/layout": "0.
|
|
47
|
-
"@protobase/query": "0.
|
|
48
|
-
"@protobase/schema": "0.
|
|
49
|
-
"@protobase/server": "0.
|
|
50
|
-
"@protobase/ui": "0.
|
|
45
|
+
"@protobase/config": "0.52.0",
|
|
46
|
+
"@protobase/layout": "0.52.0",
|
|
47
|
+
"@protobase/query": "0.52.0",
|
|
48
|
+
"@protobase/schema": "0.52.0",
|
|
49
|
+
"@protobase/server": "0.52.0",
|
|
50
|
+
"@protobase/ui": "0.52.0",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -10,7 +10,12 @@ Fields and actions filled by a model, the assistant beside the admin, and MCP.
|
|
|
10
10
|
- [Choice of model](../reference/assistant.md#which-backend): The assistant runs on OpenRouter or any OpenAI-compatible endpoint, also a local one.
|
|
11
11
|
- [Assistant tools](../reference/assistant.md#the-apps-own-tools): Your own tools for the assistant, acting on records as the user.
|
|
12
12
|
- [MCP server](../reference/mcp.md#the-tools): AI clients connect to the app over MCP as the signed-in person, and list, find and read records within that person's access, soft-deleted ones too when asked.
|
|
13
|
+
- [MCP counts](../reference/mcp.md#the-tools): AI clients count the records a filter finds, in all or per value of a field such as a status, without reading the records.
|
|
14
|
+
- [MCP result size](../reference/mcp.md#result-size): Every tool result fits what AI clients take, as valid JSON: long values are cut and named, a page holds fewer records, and the client reads the rest in pieces.
|
|
15
|
+
- [MCP app icon](../reference/mcp.md#the-apps-icon): AI clients show the app's own icon beside its name when someone adds its MCP endpoint.
|
|
13
16
|
- [MCP writes](../reference/mcp.md#writes): When turned on, for every resource or only those you list, AI clients create, update and delete records after the person approves each write.
|
|
17
|
+
- [Small MCP write results](../reference/mcp.md#what-a-write-returns): A write over MCP returns the record's key, new ETag, the fields written and the read-only fields that changed, not the whole record; `fields` asks for more.
|
|
14
18
|
- [MCP writes without approval](../reference/mcp.md#writes-without-approval): Roles you name, such as service accounts, write over MCP without being asked to approve each write; everyone else is still asked.
|
|
19
|
+
- [MCP comments](../reference/mcp.md#comments): AI clients read a record's comments, and with MCP writes on add one after the person approves it.
|
|
15
20
|
- [MCP batch writes](../reference/mcp.md#batch-writes): When MCP writes are on, AI clients make many creates, updates and deletes across resources in one transaction, after the person approves the batch.
|
|
16
21
|
- [Connected apps](../reference/auth.md#oauth-for-mcp-clients): People allow an AI client to sign in, and disconnect it later.
|
|
@@ -10,5 +10,5 @@ Apps written for other systems that keep working on Protobase, and moving their
|
|
|
10
10
|
- [Supabase client API](../reference/supabase-rest.md): supabase-js `from()` and `rpc()` calls keep working, under the tables' RLS policies.
|
|
11
11
|
- [Supabase Auth](../reference/auth.md#supabase-js-and-supabasessr): `supabase.auth` and `@supabase/ssr` calls keep working.
|
|
12
12
|
- [Supabase Storage](../reference/supabase-storage.md): supabase-js storage calls keep working, over the app's file storage.
|
|
13
|
-
- [Supabase Realtime](../reference/supabase-realtime.md): Database changes, broadcast and presence through supabase-js channels, private ones authorized by the policies on `realtime.messages`, broadcasts sent from a server without joining a channel, and broadcasts from the database with `realtime.send()` and `realtime.broadcast_changes()
|
|
13
|
+
- [Supabase Realtime](../reference/supabase-realtime.md): Database changes, broadcast and presence through supabase-js channels, private ones authorized by the policies on `realtime.messages`, broadcasts sent from a server without joining a channel, and broadcasts from the database with `realtime.send()` and `realtime.broadcast_changes()`, across [several processes](../reference/supabase-realtime.md#several-processes) serving one app.
|
|
14
14
|
- [Edge Functions](../guides/api-functions.md#functions-moved-from-supabase): Functions moved from Supabase answer at their old addresses.
|
|
@@ -6,7 +6,7 @@ The app's colours, name, icon, language and installation.
|
|
|
6
6
|
|
|
7
7
|
- [Theme](../reference/theme.md): One CSS file sets the app's colours, corners and fonts for light and dark, and keeps working on every release.
|
|
8
8
|
- [Dark mode](../reference/theme.md#light-dark-or-the-system): Each user picks light, dark or the system setting.
|
|
9
|
-
- [App name, icon and colours](../reference/app-identity.md): The app's own name, icon and colours in the sidebar, browser tabs, home-screen icon and mail.
|
|
9
|
+
- [App name, icon and colours](../reference/app-identity.md): The app's own name, icon and colours in the sidebar, browser tabs, `/favicon.ico`, home-screen icon and mail.
|
|
10
10
|
- [Logo and favicon](../reference/theme.md#logo-and-favicon): Your own favicon or logo replaces Protobase's.
|
|
11
11
|
- [English and Dutch](../reference/languages.md): The built-in screens come in English and Dutch, with numbers and dates written to match.
|
|
12
12
|
- [Installable app](../reference/installable-app.md): The admin installs as an app on phones and computers, and says when the server cannot be reached.
|
|
@@ -35,11 +35,11 @@ A scratch app starts without resources, so `protobase doctor` refuses it until i
|
|
|
35
35
|
```sh
|
|
36
36
|
# db/migrations/007_customers.sql: create table customers (id bigint generated always as identity primary key, name text not null);
|
|
37
37
|
bun run db:migrate
|
|
38
|
-
bun run protobase scaffold --ui --yes
|
|
38
|
+
bun run protobase scaffold --ui --yes
|
|
39
39
|
bun run protobase doctor
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
`scaffold` writes `config/customers/data.ts` and `ui.ts` and exports them from `config/index.ts`, where Protobase finds every resource, view and page
|
|
42
|
+
`scaffold` writes `config/customers/data.ts` and `ui.ts` and exports them from `config/index.ts`, where Protobase finds every resource, view and page. `bun run dev` shows the new list at once. The [Data config](reference/data-config.md) and [UI config](reference/ui-config.md) say what else a resource can be.
|
|
43
43
|
|
|
44
44
|
### On an existing database
|
|
45
45
|
|
|
@@ -59,7 +59,9 @@ It connects read-only and names the database and its Postgres version, then asks
|
|
|
59
59
|
|
|
60
60
|
Then it runs that `scaffold` in the project and prints the next steps. Without a terminal it asks nothing: the folder is the database's name, and every table gets a resource and a `ui.ts`. Quote the URL, as a shell reads `?` and `&` in it. `--preset` is refused with a URL: the project starts from scratch.
|
|
61
61
|
|
|
62
|
-
It never writes to the database. The first of the next steps does: `bun run db:migrate` adds the `auth` schema that sign-in keeps its users in, and `
|
|
62
|
+
It never writes to the database. The first of the next steps does: `bun run db:migrate` adds the `auth` schema that sign-in keeps its users in, and the `migrations` schema, where the script records the migrations it applied in `migrations.applied`. A `public.schema_migrations` another migration tool keeps is left as it is.
|
|
63
|
+
|
|
64
|
+
On a Supabase database, which it knows by its `auth` and `storage` schemas and its `supabase_admin` role, as [`import supabase`](reference/cli.md#import-supabase) does, the `auth` schema is Supabase Auth's, not Protobase's. It leaves out `auth`, `storage` and the platform's other schemas, such as `realtime` and `supabase_migrations`, as Supabase's own tables, and signs the project in on Supabase's `auth.users`, as the import does: it points `protobase.config.ts` at `auth.users` and writes migrations in place of those of Protobase's own user table, the columns Better Auth needs on `auth.users`, Better Auth's tables next to it, and each user's account with their Supabase password and social providers. `bun run db:migrate` then applies them, and Supabase's users sign in with their own passwords. <gap>A user who signs up through Supabase Auth after that cannot sign in to the app with their password because carrying later sign-ups over is not implemented.</gap>
|
|
63
65
|
|
|
64
66
|
```sh
|
|
65
67
|
cd shop
|
|
@@ -32,7 +32,7 @@ The host serves `public/` itself and sends only the manifest's `api` paths to th
|
|
|
32
32
|
|
|
33
33
|
## Migrations
|
|
34
34
|
|
|
35
|
-
Serving never changes the database: the bundle carries the project's `db/migrations` as `migrations/`, and the runtime's `migrate <bundle>` applies the pending ones, the app's and the auth schema's, before a new version serves, with no other writes while it runs. It applies them in one transaction behind a lock, recorded in `
|
|
35
|
+
Serving never changes the database: the bundle carries the project's `db/migrations` as `migrations/`, and the runtime's `migrate <bundle>` applies the pending ones, the app's and the auth schema's, before a new version serves, with no other writes while it runs. It applies them in one transaction behind a lock, recorded in `migrations.applied` as the presets' `db:migrate` does, so a database either script migrated is current for the other. A database an earlier version migrated keeps its record in `public.schema_migrations`, which `migrate` copies over the first time; a `public.schema_migrations` of another migration tool, without Protobase's `name` and `applied_at` columns, is never read or written. A file that would end that transaction (`BEGIN`, `COMMIT`, `ROLLBACK`) or cannot run in one (`create index concurrently`) is refused, and a refused or failing file leaves the database unchanged. The runtime refuses to start while the auth store has not applied every auth migration of the new version, which it reads from the store's `auth_migrations` table without comparing its tables (see [migrations](../reference/auth.md#migrations)). [`protobase migration`](../reference/cli.md#migration) writes the files the config's features need, such as the auth and jobs schemas, as the project's own migrations, and [a self-hosted image](#a-self-hosted-image) runs `migrate` as a step of its own before the app starts.
|
|
36
36
|
|
|
37
37
|
## Images
|
|
38
38
|
|
|
@@ -9,7 +9,7 @@ An app looks like its own everywhere from three things in its project: its name,
|
|
|
9
9
|
| What | Where | Used by |
|
|
10
10
|
| --- | --- | --- |
|
|
11
11
|
| Name | `name` in `protobase.config.ts` ([config](config.md)), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the end of every tab title, the installed app's name, the [mobile app](../guides/mobile-app.md)'s name on the phone, passkey and authenticator prompts, auth mail and its sender's name |
|
|
12
|
-
| Icon | `protobase.favicon.svg` at the project's root | the browser tab, the sidebar's logo, the installed app's icon; the [mobile app](../guides/mobile-app.md) shows Protobase's icon instead |
|
|
12
|
+
| Icon | `protobase.favicon.svg` at the project's root | the browser tab, `/favicon.ico`, the sidebar's logo, the installed app's icon, the [MCP endpoint](mcp.md#the-apps-icon)'s icon in AI clients; the [mobile app](../guides/mobile-app.md) shows Protobase's icon instead |
|
|
13
13
|
| Raster icons | optional PNGs beside the SVG, below | the iPhone home screen and Android launchers, which take no SVG |
|
|
14
14
|
| Colours | `themeColor` and `backgroundColor` in `protobase.config.ts` | the installed app's title bar and its start screen |
|
|
15
15
|
|
|
@@ -41,6 +41,8 @@ Some platforms take no SVG, so a project may put PNGs of the same icon beside it
|
|
|
41
41
|
| `protobase.icon-512.png` | 512 × 512 | the web manifest, for Android's install screens |
|
|
42
42
|
| `protobase.icon-maskable.png` | 512 × 512 | the web manifest's maskable icon, which Android crops to its own shape: keep the mark within the middle 80% |
|
|
43
43
|
|
|
44
|
+
The app answers `/favicon.ico`, which browsers and favicon services ask for when they have not read the page, with its icon: the 192 pixel PNG, else the touch icon, else the 512 pixel PNG, else the SVG, each with its own content type. Without a favicon of its own the app answers Protobase's.
|
|
45
|
+
|
|
44
46
|
Each is optional, and none is made from the SVG: without the touch icon an iPhone's home screen shows a picture of the page. `protobase build` copies the ones the project has to the bundle's `public/`, and fails on a file that is no PNG or not its size; `protobase dev` serves them from the project's root.
|
|
45
47
|
|
|
46
48
|
## The colours
|
|
@@ -57,7 +57,7 @@ The model needs tool calling for the queries. A refused key, an exhausted accoun
|
|
|
57
57
|
|
|
58
58
|
It lives at `/api/assistant` on the app's own origin and answers with the user's token like the rest of the API. Its system prompt describes the resources, tables and fields the user can see in `/meta`. It has two tools of its own, and [the app's](#the-apps-own-tools):
|
|
59
59
|
|
|
60
|
-
- **`run_read_only_query`** runs one `SELECT` (or `VALUES`, or a `WITH` query) and shows its rows as a table in the chat. It runs in a `READ ONLY` transaction that is always rolled back, with a statement timeout of 5 seconds and at most 200 rows. Postgres refuses every write inside (`SET TRANSACTION READ WRITE`, writable CTEs, `nextval`, `DO` blocks, functions that write), and settings it changes go with the rollback. The statement runs through the function `query.run_read_only` as the role `<database>_query`, which [`protobase migration`](cli.md#migration) makes: that role may read every column of the resources' tables, `.sensitive()` fields and the [webhook subscriptions'](webhooks.md) signing secrets included, and nothing else: not the auth store, nor a table without a resource. The function opens the statement as a cursor, so only one statement runs, and Postgres refuses a change of role inside it. Numbers other than integers of up to 15 digits come back as their exact text, such as `"12.50"`.
|
|
60
|
+
- **`run_read_only_query`** runs one `SELECT` (or `VALUES`, or a `WITH` query) and shows its rows as a table in the chat. It runs in a `READ ONLY` transaction that is always rolled back, with a statement timeout of 5 seconds and at most 200 rows. Postgres refuses every write inside (`SET TRANSACTION READ WRITE`, writable CTEs, `nextval`, `DO` blocks, functions that write), and settings it changes go with the rollback. The statement runs through the function `query.run_read_only` as the role `<database>_query`, which [`protobase migration`](cli.md#migration) makes: that role may read every column of the resources' tables, `.sensitive()` fields and the [webhook subscriptions'](webhooks.md) signing secrets included, and nothing else: not the auth store, nor a table without a resource. The function opens the statement as a cursor, so only one statement runs, and Postgres refuses a change of role inside it. Numbers other than integers of up to 15 digits come back as their exact text, such as `"12.50"`. The model reads the rows within the [result size](mcp.md#result-size) of MCP's tools, as every built-in tool's result.
|
|
61
61
|
- **`propose_write_query`** never runs on its own. It shows the statement and a summary on a card with **Approve** and **Reject**. Only Approve runs it, as one statement in a read-write transaction; Reject, or no answer within 10 minutes, runs nothing. The model gets the returned rows, or that nothing ran. Statements are `INSERT`, `UPDATE` or `DELETE` with a `RETURNING` clause.
|
|
62
62
|
|
|
63
63
|
Both run **outside Protobase's access rules and tenant scoping**: whoever has the `admin` or `ai` role can read every resource's table, and with approval change everything the app's database role can, since `propose_write_query` still runs as that role. Give the app a database role without superuser rights, and those roles only to people who may see all of the data.
|
|
@@ -68,7 +68,7 @@ Making the query role needs `CREATEROLE` once, for the role that applies the mig
|
|
|
68
68
|
|
|
69
69
|
`assistant/tools.ts` adds tools of the app's own, which the built-in backend offers after its two: its default export is an array of tools, found by that path when the app starts. A tool is `defineTool({ name, description, parameters, run })` from `@protobase/server`: `parameters` is the JSON Schema of its arguments, and `run(args, context)` returns the text the model reads. A name must be 1 to 64 letters, digits, `_` or `-`, and a name taken twice stops the server at startup. A backend elsewhere has its own tools, so the file does nothing there, nor with `assistant: false`. A tool's `annotations` are MCP's tool hints (`readOnlyHint`, `destructiveHint`, ...), which the dock ignores; the same tools can be offered over the app's [MCP endpoint](mcp.md#building-on-it).
|
|
70
70
|
|
|
71
|
-
`context` holds the user's `session`, `locale` (the language they read, `'en'` or `'nl'`, for the texts a tool shows them such as its approvals; set over MCP, absent in the dock), `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `get(resource, key)`, `create(resource, data)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. `get`, `create`, `update` and `delete` each answer `{ record, etag }`, and `list` a page of records. `batch(operations)` runs the operations of a REST [batch write](api.md#batch-writes) in one transaction and answers its `results`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
|
|
71
|
+
`context` holds the user's `session`, `locale` (the language they read, `'en'` or `'nl'`, for the texts a tool shows them such as its approvals; set over MCP, absent in the dock), `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `aggregate(resource, { group_by, filter?, limit?, label? })` with its counts per value as `:aggregate` gives them, `get(resource, key)`, `create(resource, data)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. `get`, `create`, `update` and `delete` each answer `{ record, etag }`, and `list` a page of records. `batch(operations)` runs the operations of a REST [batch write](api.md#batch-writes) in one transaction and answers its `results`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
|
|
72
72
|
|
|
73
73
|
A tool with a [widget](#widget-parts) creates or finds what it is about, shows a widget with its id, and returns the id and the state at that moment:
|
|
74
74
|
|
|
@@ -49,9 +49,9 @@ The serve runtime is bundled by `protobase build-serve` into one JavaScript file
|
|
|
49
49
|
protobase scaffold [connection string | --env VAR] [target] [options]
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Without a connection string or `--env`, the URL is `DATABASE_URL`, from the environment or the nearest `.env` at or above the current directory, as `dev` reads it. `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended.
|
|
52
|
+
Without a connection string or `--env`, the URL is `DATABASE_URL`, from the environment or the nearest `.env` at or above the current directory, as `dev` reads it. `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended. A table that a written one points to with a foreign key is written too, outside the target or excluded, unless it has a resource already, since the app refuses a relation to a resource it does not have; a line names each.
|
|
53
53
|
|
|
54
|
-
Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the auth store, which is the `auth` schema or another schema with the store's `auth_migrations` table, or with Better Auth's `session`, `account` and `verification` tables whose sessions point at a user table (in `public`, only the tables of the store's [migrations](auth.md#migrations) and that user table, whatever it is called),
|
|
54
|
+
Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the auth store, which is the `auth` schema or another schema with the store's `auth_migrations` table, or with Better Auth's `session`, `account` and `verification` tables whose sessions point at a user table (in `public`, only the tables of the store's [migrations](auth.md#migrations) and that user table, whatever it is called), pg-boss's `jobs` schema, and the `migrations` schema whose `applied` table records the migrations applied. A line names each one skipped. The auth store is left out whatever the target names; a target naming the `jobs` or `migrations` schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it, and `dev` and `serve` refuse to start with a resource over the auth store.
|
|
55
55
|
|
|
56
56
|
| Option | Effect |
|
|
57
57
|
| --- | --- |
|
|
@@ -85,7 +85,7 @@ The list `--ui` writes shows five columns at most: the key unless it is a uuid,
|
|
|
85
85
|
- Computed defaults (function, sequence, expression, `GENERATED BY DEFAULT` identity): `.dbDefault()`. It also gets `.readOnly()` when the column is an identity column, a primary-key column, or an audit timestamp (`created_at`, `inserted_at`, `updated_at`, `modified_at`, or the same in camelCase, such as `createdAt`); other computed defaults, such as `order_date DEFAULT current_date`, stay editable. `GENERATED ALWAYS` identity and generated columns are only `.readOnly()`.
|
|
86
86
|
- Leading column of a non-partial index: `.filterable()`; of a btree: also `.sortable()`. Not applied to json.
|
|
87
87
|
- The text field that names a record (`name`, `title`, `number`, `sku`, `email`, `code` or `description`, else the first text field) becomes the resource's `.search(...)` when a non-partial pg_trgm index (`gin_trgm_ops` or `gist_trgm_ops`) serves it, so the [global search](client.md#global-search) finds its records by name. Without one the API would refuse the search, so it is left out; add the index and run `protobase scaffold` on a new resource, or add `.search` by hand.
|
|
88
|
-
- Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning. A view or materialized view is skipped with a warning too, as Postgres knows no key for it: declare a resource over one by hand.
|
|
88
|
+
- Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning. <gap>A table that points to a skipped table without a key cannot start, as writing its foreign key as a plain field instead of a relation is not implemented; `doctor` reports the relation.</gap> A view or materialized view is skipped with a warning too, as Postgres knows no key for it: declare a resource over one by hand.
|
|
89
89
|
- `deleted_at`, `removed_at`, `archived_at` (nullable timestamp/date) become `.softDelete`; `organization_id` and `tenant_id` become `.tenant`.
|
|
90
90
|
- Unique indexes are listed in the doc comment above the resource.
|
|
91
91
|
- Field names are the column names in snake_case; `.column()` is written only when the schema builder's default mapping would not give the column back (always for `hr."EMP_MASTER"`).
|
|
@@ -109,7 +109,7 @@ The URL comes as for [`scaffold`](#scaffold): the connection string, the variabl
|
|
|
109
109
|
|
|
110
110
|
Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config module has them by convention, and checks every exported resource against the database:
|
|
111
111
|
|
|
112
|
-
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index
|
|
112
|
+
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index, relation to a resource the config does not declare
|
|
113
113
|
- error: a read the [scan guard](api.md#safety) refuses, because no index serves a column it filters, sorts, searches or counts by. Doctor reads each table's indexes from the catalog, as the server does, and judges with the scan guard's own rule every read the API takes and the app makes: a filter on each `.filterable()` field, a sort by each `.sortable()` one, `search()` over the search fields, a role's own records (`.owner()`) and the names a relation shows; each view's list in its order and with the filter it opens with, its filter widgets and their counts, its chart, its map, board, calendar and timeline, its card photos, its order by hand, its related sections, galleries and charts, its named lists, its recent records and a saved search's new records; and each block of a [composed page](layouts.md) that lists records, and each `Chart` block's grouped and split fields. Each error is an index to add, with every request that needs it and where it comes from:
|
|
114
114
|
|
|
115
115
|
```
|
|
@@ -513,7 +513,7 @@ For a project with [organizations](auth.md#organizations); `<organization>` is a
|
|
|
513
513
|
protobase migration [--dir db/migrations] [--extend <dir>]
|
|
514
514
|
```
|
|
515
515
|
|
|
516
|
-
Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks` or `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`NNN_webhooks.sql`),
|
|
516
|
+
Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks` or `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`NNN_webhooks.sql`), the [devices and history tables](notifications.md#table-names) of `notifications` (`NNN_notifications.sql`), and the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) (`NNN_realtime_relay.sql`). It compares the database, with the project's migrations applied, with the config (for the auth schema, it reads the store's record of the migrations it applied), merged with those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL`.
|
|
517
517
|
|
|
518
518
|
```sh
|
|
519
519
|
bun run db:migrate # the database at the project's current schema
|
|
@@ -594,10 +594,10 @@ Copies the agent skills of this CLI's version into the current project, or only
|
|
|
594
594
|
```sh
|
|
595
595
|
bun run db:up && bun run --cwd tests/apps/erp db:migrate && bun run --cwd tests/apps/erp db:seed --scale small
|
|
596
596
|
bun run --cwd tests/apps/erp protobase scaffold postgres://protobase:protobase@localhost:55432/protobase \
|
|
597
|
-
--yes --ui --exclude public.
|
|
597
|
+
--yes --ui --exclude public.seed_info
|
|
598
598
|
bun run --cwd tests/apps/erp protobase doctor postgres://protobase:protobase@localhost:55432/protobase
|
|
599
599
|
```
|
|
600
600
|
|
|
601
|
-
The ERP keeps Better Auth's users, sessions and signing keys in the `auth` schema of the same database; scaffold leaves that store out on its own, so they are never exposed through the admin API. `--exclude` leaves out the
|
|
601
|
+
The ERP keeps Better Auth's users, sessions and signing keys in the `auth` schema of the same database; scaffold leaves that store out on its own, so they are never exposed through the admin API. `--exclude` leaves out the seed's own bookkeeping table.
|
|
602
602
|
|
|
603
603
|
The integration test (`packages/cli/tests/scaffold/scaffold.integration.test.ts`) scaffolds into a temp folder and is skipped when the database is unreachable.
|
|
@@ -56,6 +56,8 @@ Whoever may read the record may read its comments and add one: the same tenant,
|
|
|
56
56
|
|
|
57
57
|
`GET /api/v1/{resource}/{key}:comments` reads them newest first, `POST` to the same path adds one, and `GET /api/v1/{resource}/{key}:mentionable?q=` lists whom a comment may mention. See [REST API](api.md#record-comments).
|
|
58
58
|
|
|
59
|
+
An AI client reads and adds them over the app's [MCP endpoint](mcp.md#comments), with `list_comments` and `add_comment`, under the same rules.
|
|
60
|
+
|
|
59
61
|
## Moderation
|
|
60
62
|
|
|
61
63
|
Once a resource takes comments, admins get **Comments** (the built-in resource `record_comments`): every comment of every resource, newest first, filterable by resource, record, author and time. Only the `admin` role reads it, whatever the project's roles say; deleting a comment there is how a wrong or abusive one goes. When a resource with comments has a [tenant](data-config.md#resource), the list is scoped to the caller's tenant.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# API options
|
|
4
4
|
|
|
5
|
-
The config keys of the REST API, its path, keys, CORS, access defaults, query limits, error reporting, write hooks, MCP tools, remote resources and
|
|
5
|
+
The config keys of the REST API, its path, keys, CORS, access defaults, query limits, error reporting, write hooks, MCP tools, remote resources, runtime updates and Realtime across processes, and the files of the API's own hooks.
|
|
6
6
|
|
|
7
7
|
The keys of the API, at the top level of [`protobase.config.ts`](../config.md). The API itself is described in [REST API](../api.md).
|
|
8
8
|
|
|
@@ -115,7 +115,7 @@ export default defineConfig({ writeHooks: ['queue-sent-invoice'] })
|
|
|
115
115
|
## mcpEndpoint
|
|
116
116
|
|
|
117
117
|
- **Type:** `{ sql?: boolean; writes?: boolean | { resources?: string[]; rolesWithoutApproval?: string[] } } | false`
|
|
118
|
-
- **Default:** the read tools only: `list_resources`, `list_records` and `get_record`
|
|
118
|
+
- **Default:** the read tools only: `list_resources`, `list_records`, `count_records` and `get_record`
|
|
119
119
|
|
|
120
120
|
The MCP endpoint's tools; [`auth.mcp`](sign-in.md#authmcp) turns the endpoint on. `sql: true` also offers admins and the `ai` role `run_read_only_query`, which reads the whole database outside the access rules. `writes: true` offers `create_record`, `update_record`, `delete_record` and `batch_write` through the REST API's rules, each approved by the person in their client; `writes.resources` limits them to the resources named, and `writes.rolesWithoutApproval` lets holders of those roles, such as a service account, write without the approval. `false` is for a host that serves its own MCP endpoint at `auth.mcp.path`, in front of this app. See [MCP](../mcp.md#the-tools).
|
|
121
121
|
|
|
@@ -149,6 +149,17 @@ The endpoint that reports the app's runtime version and updates it, such as a ho
|
|
|
149
149
|
export default defineConfig({ runtimeUpdates: false })
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
## realtime
|
|
153
|
+
|
|
154
|
+
- **Type:** `{ processes?: 'one' | 'many' }`
|
|
155
|
+
- **Default:** `{ processes: 'one' }`
|
|
156
|
+
|
|
157
|
+
How [Supabase Realtime](../supabase-realtime.md) is served. With `'one'`, one process serves the app, and broadcasts and presence go between its channels in memory. Set `'many'` when several processes serve the app behind one address: broadcasts and presence then go between the processes through the `realtime_relay` schema of the app's database, which [`protobase migration`](../cli.md#migration) writes and the server checks at start. See [Several processes](../supabase-realtime.md#several-processes).
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
export default defineConfig({ realtime: { processes: 'many' } })
|
|
161
|
+
```
|
|
162
|
+
|
|
152
163
|
## Code of the API
|
|
153
164
|
|
|
154
165
|
Two files of the project's own change what the API does, each its default export, with no key in the config:
|
|
@@ -28,7 +28,7 @@ Each key is described with its type and default in the option pages:
|
|
|
28
28
|
| --- | --- |
|
|
29
29
|
| [App options](config/app.md) | `name`, `url`, `secret`, `previousSecrets`, `locale`, `timezone`, `themeColor`, `backgroundColor`, `mobile` |
|
|
30
30
|
| [Sign-in options](config/sign-in.md) | `auth`, `authenticate`, `signingKeyDays`, `signingKeyGraceDays` |
|
|
31
|
-
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates` |
|
|
31
|
+
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates`, `realtime` |
|
|
32
32
|
| [Admin app options](config/admin-app.md) | `assistant`, `maps`, `plugins` |
|
|
33
33
|
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `notifications` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# MCP
|
|
4
4
|
|
|
5
|
-
The app's MCP endpoint, through which a person's AI client lists resources, finds and reads records, and, when turned on, creates and updates them with that person's access and approval.
|
|
5
|
+
The app's MCP endpoint, through which a person's AI client lists resources, finds and reads records and their comments, and, when turned on, creates and updates them with that person's access and approval.
|
|
6
6
|
|
|
7
7
|
An app can serve an MCP endpoint: a person adds its address to an AI client that speaks MCP, such as a chat assistant or a code editor, signs in on the app and allows the client. The client then works with that person's access: it lists the resources and fields they may read, finds records with the API's filters, sorting and pages, and reads one record.
|
|
8
8
|
|
|
@@ -29,6 +29,10 @@ Give the client the endpoint's address. It finds the app's sign-in from there, o
|
|
|
29
29
|
|
|
30
30
|
Some take the address on the command line instead, as a server with the HTTP transport, and sign in when you first use it.
|
|
31
31
|
|
|
32
|
+
## The app's icon
|
|
33
|
+
|
|
34
|
+
The endpoint names the app's [icon](app-identity.md#the-icons) to the client when it connects (`serverInfo.icons`), at absolute addresses on the app's origin: the project's 192 pixel, touch and 512 pixel PNGs it has, then its `protobase.favicon.svg`, or Protobase's without one. A client that draws server icons shows it beside the app's name. <gap>An app without PNGs of its own cannot offer clients that draw no SVG an icon because PNG versions of Protobase's icon are not implemented.</gap>
|
|
35
|
+
|
|
32
36
|
## The tools
|
|
33
37
|
|
|
34
38
|
Each tool reads as the signed-in person: their role's access rules, row filters, tenant and hidden fields apply as in the [REST API](api.md#access).
|
|
@@ -37,12 +41,30 @@ Each tool reads as the signed-in person: their role's access rules, row filters,
|
|
|
37
41
|
| --- | --- |
|
|
38
42
|
| `list_resources` | The resources the person may read, with their labels, key, whether they soft delete (`soft_delete`) and fields: each field's type, label, enum values, the resource a relation links to, and whether filters and sorts take it. |
|
|
39
43
|
| `list_records` | A page of a resource's records: `filter` in the API's [filter syntax](api.md#filters), `order_by`, `page_size` (20 by default, at most 100) and `page_token`, with `next_page_token` for the next page. `show_deleted: true` also returns soft-deleted records. |
|
|
40
|
-
| `
|
|
44
|
+
| `count_records` | How many records a `filter` finds, without returning them: `{ count }` as the API's `count=exact` counts, or `{ more_than: 10000, estimate }` when more match. With `group_by`, a filterable field, the count per value instead, as [`:aggregate`](api.md#routes) gives it: `{ group_by, groups: [{ value, count }] }`, largest first, adding up to what the filter finds, the first `limit` (100 by default, at most 1,000), with `label` naming a relation's values by a field of the records they link to. A date or timestamp `group_by` counts per day over the last 30 days. `show_deleted: true` also counts soft-deleted records. |
|
|
45
|
+
| `get_record` | One record by its key, with its ETag. A composite key is passed as the values of its fields, in order. `show_deleted: true` also finds a soft-deleted record. With `field`, it reads that one field alone, `max_chars` characters (20,000 by default, at most 30,000) from `offset`, and gives its whole `length` and the `next_offset` to read on from. |
|
|
46
|
+
|
|
47
|
+
`show_deleted` works as the [REST API](api.md#routes)'s: it applies only to a resource with a soft delete, and is refused on any other. <gap>`count_records` cannot count soft-deleted records per value because `:aggregate` does not implement `show_deleted`.</gap> Soft-deleted records come under the same access rules, tenant and hidden fields as the rest, and carry the field their deletion set.
|
|
48
|
+
|
|
49
|
+
### Result size
|
|
50
|
+
|
|
51
|
+
The result of each tool that returns records, and of `run_read_only_query`, stays within 40,000 characters of JSON, below what clients take as one tool result, and stays valid JSON when it is cut. Over that, long text values are cut first, each named in `cut_fields` with its path and full length, such as `{ "field": "items[3].body", "length": 52341 }`. When that is not enough, `list_records` returns fewer records, with the `next_page_token` that goes on after the last one, and `run_read_only_query` fewer rows, marked `truncated`. A `note` then says how to read the rest: `get_record` with `field` and `offset` for a cut field, or `OFFSET` and `substring` in SQL.
|
|
41
52
|
|
|
42
|
-
`
|
|
53
|
+
<gap>`list_resources` and the app's own tools cannot cut a result to the size budget because a budget outside the record and SQL tools is not implemented.</gap> An app with very many resources, or a tool of its own, keeps its results small itself.
|
|
43
54
|
|
|
44
55
|
A refusal, such as a resource the person may not read or a bad filter, comes back to the client as text it can act on, `{ "error": ..., "message": ... }`.
|
|
45
56
|
|
|
57
|
+
### Comments
|
|
58
|
+
|
|
59
|
+
When a resource takes [comments](comments.md), the endpoint also offers `list_comments`, and with [writes](#writes) on, `add_comment`. They go through the same service as the REST API's comments, as the person: whoever may read a record may read its comments and add one, and everyone else gets the same refusal as from `GET` or `POST /api/v1/{resource}/{key}:comments`. An app without a resource with comments offers neither.
|
|
60
|
+
|
|
61
|
+
| Tool | What it does |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `list_comments` | A page of a record's comments, newest first, each as `{ author, created_at, text }`, the author's `name` beside their `id` when the app's auth knows it. `page_size` (20 by default, at most 100) and `page_token`, with `next_page_token` for the next page. |
|
|
64
|
+
| `add_comment` | Adds `text` as the person's comment on one record, and returns it as `list_comments` gives it. |
|
|
65
|
+
|
|
66
|
+
`add_comment` is a write: the person approves each comment first, seeing the record's name and the whole comment, unless they hold one of the [roles without approval](#writes-without-approval). With writes limited to some resources, it comments only on those. A comment it adds mentions nobody, so it sends no emails. An empty comment, one over 10,000 characters, a resource without comments, and a record the person may not read, or one that is soft-deleted, are refused before asking.
|
|
67
|
+
|
|
46
68
|
### SQL for admins
|
|
47
69
|
|
|
48
70
|
`mcpEndpoint.sql` also offers `run_read_only_query`, as in the [assistant](assistant.md#the-built-in-backend), to people with the `admin` or `ai` role:
|
|
@@ -63,8 +85,8 @@ export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { writes: true }
|
|
|
63
85
|
|
|
64
86
|
| Tool | What it does |
|
|
65
87
|
| --- | --- |
|
|
66
|
-
| `create_record` | Creates a record of a resource from `data`, field names to values, and returns
|
|
67
|
-
| `update_record` | Changes the fields in `data` of one record by its key, and returns
|
|
88
|
+
| `create_record` | Creates a record of a resource from `data`, field names to values, and returns its key and ETag with the fields it wrote, see [What a write returns](#what-a-write-returns). |
|
|
89
|
+
| `update_record` | Changes the fields in `data` of one record by its key, and returns its key and new ETag with the fields it set. With the `etag` that `get_record` gave, it fails when someone changed the record since. It does not set the field a soft delete sets: a delete goes through `delete_record`. |
|
|
68
90
|
| `delete_record` | Deletes one record by its key and the `etag` that `get_record` gave, and fails when someone changed the record since. A resource with a [soft delete](data-config.md) keeps the record, deleted; any other loses it for good. |
|
|
69
91
|
| `batch_write` | Creates, updates and deletes records across resources in one transaction, see [Batch writes](#batch-writes). |
|
|
70
92
|
|
|
@@ -82,6 +104,16 @@ mcpEndpoint: { writes: { resources: ['tasks'] } }
|
|
|
82
104
|
|
|
83
105
|
The write tools then name those resources in their descriptions, and refuse a write to any other before asking, with `{ "error": "forbidden", "message": ... }` saying which resources they write; nothing is written. A name the app has no resource for stops the server at startup. The list only narrows the writes: the person's access rules still apply on the listed resources.
|
|
84
106
|
|
|
107
|
+
#### What a write returns
|
|
108
|
+
|
|
109
|
+
A write returns its record small, so changing one field of a large record does not send the whole record back:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{ "key": 42, "etag": "\"7\"", "record": { "status": "done", "updated_at": "2026-10-27T09:00:00Z" } }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`key` is the record's key as the tools take it, the values of its key fields in order when it has several; `etag` is its new ETag, for a later write. `record` holds the fields the write set, as stored, and the [read-only](data-config.md#field-options) fields that changed with it, such as a formula, a rollup or an update time; a create counts every read-only field that has a value. A `fields` argument, a list of field names, adds those fields, and `["*"]` returns the whole record. A field the person may not read stays out, and for a resource they may not read at all the key and the read-only fields stay out too.
|
|
116
|
+
|
|
85
117
|
#### Writes without approval
|
|
86
118
|
|
|
87
119
|
An app that runs service accounts over MCP, such as a backend job or an agent with no person present, names their roles in `mcpEndpoint.writes`:
|
|
@@ -109,9 +141,9 @@ No role is exempt unless named. The roles are checked against the signed-in user
|
|
|
109
141
|
] }
|
|
110
142
|
```
|
|
111
143
|
|
|
112
|
-
An update needs the `etag` the record was read with, or `"*"` for any version; a delete's `etag` is optional, and without one it deletes any version. A create may name itself with `ref`, and a later operation's key or data value `{ "$ref": "<name>" }` is that record's key. The result is `{ "results": [...] }`,
|
|
144
|
+
An update needs the `etag` the record was read with, or `"*"` for any version; a delete's `etag` is optional, and without one it deletes any version. A create may name itself with `ref`, and a later operation's key or data value `{ "$ref": "<name>" }` is that record's key. The result is `{ "results": [...] }`, one per operation in order: a create or an update gives its `op`, `resource`, a create's `ref`, and its record as [a write returns it](#what-a-write-returns), with an operation's own `fields` for more, and a delete `{ "op": "delete", "resource": ..., "deleted": true }`. The read-only fields an update changed are told against the record as read just before the batch runs; an update of a record created in the same batch, by `$ref`, counts every read-only field that has a value.
|
|
113
145
|
|
|
114
|
-
The person approves the batch once, seeing each write in it
|
|
146
|
+
The person approves the batch once, in their language, seeing each write in it named and listed as the approval of a single write names and lists it: `2. Update Task #42 "Fix the sign-in lockout"` with each field it changes, a create with the new record's fields, and a delete saying whether it can be restored. A key or value pointing at a create in the batch is named by that write's number, such as `the Task from write 1`. The first 50 writes are listed and the rest counted. The approval says plainly how many deletes in it cannot be undone, which is every delete on a resource that does not [soft delete](data-config.md#resource), and an update or delete among the listed writes of a record changed since its `etag` is refused before asking.
|
|
115
147
|
|
|
116
148
|
A batch is checked before the person is asked: an operation other than a create, update or delete, a field an operation does not take, an update without an ETag or more than 500 operations come back as `{ "error": "invalid-argument", "message": ... }` naming the operation, and with writes limited to some resources an operation on any other refuses the whole batch. An update does not set the field a soft delete sets, as `update_record` does not: a delete goes through a delete operation. A refusal while it runs, such as an operation the person may not do or a stale ETag, comes back with the REST batch's `operation` (its index), `op` and `resource`. Either way nothing is written.
|
|
117
149
|
|
|
@@ -126,12 +158,13 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
|
|
|
126
158
|
`@protobase/server` exports the pieces the endpoint is made of, for an MCP server of your own with tools of your own:
|
|
127
159
|
|
|
128
160
|
- `mcpHandler({ authenticate, resource, scope, server })`: the endpoint as a fetch handler. It checks the host, admits a valid token (`mcpGate`) and serves the request with the server that `server(session, request)` builds for its caller; `request` is the HTTP request, such as for the language the person reads.
|
|
129
|
-
- `mcpServer({ info, tools, context, report, rolesWithoutApproval, approvals })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`, with the `locale` its approvals are asked in (English when absent): each call gets its own, which asks the client's user, or approves at once when the session's user holds one of `rolesWithoutApproval`. `approvals` is `mcpApprovals()`, built once and passed to every server the endpoint builds: it keeps the approvals asked for until they are answered or expire.
|
|
130
|
-
- `mcpTools({ db, sql, writes })`: the default tools for a session; `writes` is `true`, `false` or `{ resources, rolesWithoutApproval }
|
|
161
|
+
- `mcpServer({ info, tools, context, report, rolesWithoutApproval, approvals })`: an MCP server named by `info`, its `name`, `version` and `icons`, such as `mcpIcons(origin, icons)`, the app's icons on `origin`, and offering [assistant tools](assistant.md#the-apps-own-tools), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`, with the `locale` its approvals are asked in (English when absent): each call gets its own, which asks the client's user, or approves at once when the session's user holds one of `rolesWithoutApproval`. `approvals` is `mcpApprovals()`, built once and passed to every server the endpoint builds: it keeps the approvals asked for until they are answered or expire.
|
|
162
|
+
- `mcpTools({ db, sql, writes, commented })`: the default tools for a session; `writes` is `true`, `false` or `{ resources, rolesWithoutApproval }`, and `commented` names the resources with comments.
|
|
131
163
|
- `readRecordTools()`, or `listResourcesTool()`, `listRecordsTool()` and `getRecordTool()`: the read tools alone; `readOnlyQueryTool(db)` is `run_read_only_query`, and `readWriteQueryTool(db)` proposes one write statement that the user approves before it runs.
|
|
164
|
+
- `commentTools({ commented }, writes)`, or `listCommentsTool({ commented })` and `addCommentTool({ commented, resources })`: the comment tools on the resources named in `commented`, which call the context's `comments`, and `add_comment` only when `writes` is not `false`.
|
|
132
165
|
- `writeRecordTools({ resources })`, or `createRecordTool(...)`, `updateRecordTool(...)` and `deleteRecordTool(...)`: the single write tools alone, on the listed resources or, without `resources`, on any; `batchWriteTool({ resources })` is `batch_write` alone.
|
|
133
166
|
- `mcpGate({ authenticate, resource, scope })`: the token check alone, answering 401 or 403 with a challenge that names the resource's metadata.
|
|
134
|
-
- `mcpToolContext(...)`, `mcpRoutes(app, { path, handler })` and `sessionOf(authInfo)`: the tools' context as the app builds it, the routes with open CORS, and the session a request was admitted with.
|
|
167
|
+
- `mcpToolContext(...)`, with the records' comments as `comments`, `mcpRoutes(app, { path, handler })` and `sessionOf(authInfo)`: the tools' context as the app builds it, the routes with open CORS, and the session a request was admitted with.
|
|
135
168
|
|
|
136
169
|
A host that builds its own server around `createAdmin`, rather than running the project with `protobase dev` or `protobase serve`, can serve its own endpoint at `auth.mcp.path` instead: `mcpEndpoint: false` (`createAdmin`'s `options.mcp`) turns Protobase's off, and the host mounts its own in front of `createAdmin`'s app. The OAuth provider and its discovery stay, and `createAdmin` answers 404 at the path and under it. `protobase dev` and `protobase serve` have no place to mount another endpoint, so in a project served by them `mcpEndpoint: false` only turns the endpoint off.
|
|
137
170
|
|
|
@@ -143,7 +143,7 @@ The paths come from `historyPath('/api')`, `historyPath('/api', 'unread')`, `his
|
|
|
143
143
|
The bell lists notifications only in its panel; there is no page of all notifications.
|
|
144
144
|
:::
|
|
145
145
|
|
|
146
|
-
With notifications on, every signed-in user sees a bell in the top bar with how many of their notifications are unread. Its panel is their inbox: the newest notifications [sent](#sending) with the inbox flag on, never those sent without it, the unread ones in bold, each with how long ago it came. Opening one marks it read and goes to its page
|
|
146
|
+
With notifications on, every signed-in user sees a bell in the top bar with how many of their notifications are unread. Its panel is their inbox: the newest notifications [sent](#sending) with the inbox flag on, never those sent without it, the unread ones in bold, each with how long ago it came. Opening one marks it read and goes to its page in the app, in the same tab: inbox links stay within the app, since the [history](#history) never answers a `url` on another site. A notification without a `url` is not a link. "Mark all as read" marks those the panel shows read, and "Show more" brings older ones.
|
|
147
147
|
|
|
148
148
|
The panel also offers to turn push on for this device, where the device can receive it: a browser with Web Push, when the app has [its keys](#web-push). The browser asks for permission only once the user clicks "Turn on", never when a page loads. Once push is on, the panel says so with a way to turn it off. When the browser blocks notifications, the panel says so and how to allow them again, and offers to turn push on once they are allowed.
|
|
149
149
|
|