@protobase/cli 0.35.0 → 0.37.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/cli/package.js +1 -1
- package/package.json +6 -6
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/reference/assistant.md +2 -2
- package/skills/protobase/references/reference/auth.md +1 -1
- package/skills/protobase/references/reference/data-config.md +3 -1
- package/skills/protobase/references/reference/mcp.md +99 -0
- package/skills/protobase/references/reference/webhooks.md +2 -2
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.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": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.
|
|
40
|
-
"@protobase/query": "0.
|
|
41
|
-
"@protobase/schema": "0.
|
|
42
|
-
"@protobase/server": "0.
|
|
43
|
-
"@protobase/ui": "0.
|
|
39
|
+
"@protobase/layout": "0.37.0",
|
|
40
|
+
"@protobase/query": "0.37.0",
|
|
41
|
+
"@protobase/schema": "0.37.0",
|
|
42
|
+
"@protobase/server": "0.37.0",
|
|
43
|
+
"@protobase/ui": "0.37.0",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -92,6 +92,7 @@ Reference:
|
|
|
92
92
|
- When changing the user menu → read [User menu](references/reference/user-menu.md)
|
|
93
93
|
- When adding tabs along the bottom of a phone → read [Bottom bar](references/reference/bottom-bar.md)
|
|
94
94
|
- When configuring the chat beside the admin → read [Assistant](references/reference/assistant.md)
|
|
95
|
+
- When letting AI clients read the app's data over MCP, or building an MCP server of your own → read [MCP](references/reference/mcp.md)
|
|
95
96
|
- When looking for a command or its options → read [CLI](references/reference/cli.md)
|
|
96
97
|
- When asking how Protobase is versioned and which bundles a runtime runs → read [Versioning](references/reference/versioning.md)
|
|
97
98
|
- When looking for an export of `@protobase/schema` → read the [API reference](https://docs.protobase.net/api/schema/)
|
|
@@ -64,9 +64,9 @@ Both run as the app's database role, **outside Protobase's access rules and tena
|
|
|
64
64
|
|
|
65
65
|
### The app's own tools
|
|
66
66
|
|
|
67
|
-
`options.assistant.tools` adds tools of the app's own, which the built-in backend offers after its two. 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 option does nothing there.
|
|
67
|
+
`options.assistant.tools` adds tools of the app's own, which the built-in backend offers after its two. 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 option does nothing there. 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)).
|
|
68
68
|
|
|
69
|
-
`context` holds the user's `session`, `show(part)` to add a part to the answer, `approve(request)` for an approval card, and `records`: `get(resource, key)`, `create(resource, data)` and `update(resource, key, data, { etag? })` (without an ETag it updates any version) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. Each answers `{ record, etag }`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
|
|
69
|
+
`context` holds the user's `session`, `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)` and `update(resource, key, data, { etag? })` (without an ETag it updates any version) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. Each answers `{ record, etag }`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
|
|
70
70
|
|
|
71
71
|
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:
|
|
72
72
|
|
|
@@ -509,7 +509,7 @@ It is signed with the same keys and carries the same claims as a token from `/ap
|
|
|
509
509
|
|
|
510
510
|
## OAuth for MCP clients
|
|
511
511
|
|
|
512
|
-
With `mcp`, the app is an OAuth provider for MCP clients, such as AI assistants and code editors that speak MCP: a person adds the app's MCP address to the client, the client registers itself, the person signs in on the app's own pages and allows it on the connect page, and the client gets tokens that act as that person.
|
|
512
|
+
With `mcp`, the app is an OAuth provider for MCP clients, such as AI assistants and code editors that speak MCP: a person adds the app's MCP address to the client, the client registers itself, the person signs in on the app's own pages and allows it on the connect page, and the client gets tokens that act as that person. What the client can do with them is in [MCP](mcp.md)).
|
|
513
513
|
|
|
514
514
|
```ts
|
|
515
515
|
createAuth({ ..., mcp: true })
|
|
@@ -206,6 +206,8 @@ iban: f.text().sensitive().access({ read: roles.can('screening.read') }),
|
|
|
206
206
|
|
|
207
207
|
A sensitive field cannot be `.filterable()`, `.sortable()`, aliased, searched, or the key, tenant, owner or soft delete field, and a view may only put it in a record page section: in a list, filter, chart, sidebar, title, recent-record group or action it would always be empty, so the config fails to load.
|
|
208
208
|
|
|
209
|
+
A [webhook subscription](webhooks.md)) delivering `as` a role runs that role's access rules on a captured change, which holds no sensitive field. A rule or row filter that reads one there throws, and the change is kept as failed for that subscription instead of delivered, so decide that access on a field that is not sensitive. A rule that reads the field before it checks the role, such as `record.api_secret == null || ctx.user.roles.includes('admin')`, fails even for `as: { roles: ['admin'] }`: check the role first, as in `ctx.user.roles.includes('admin') || ...`.
|
|
210
|
+
|
|
209
211
|
## Encrypted fields
|
|
210
212
|
|
|
211
213
|
An encrypted field is a [sensitive field](#sensitive-fields) whose value the server encrypts before it reaches the database, so a dump, a backup, a replica, a realtime subscriber or anyone running SQL sees only ciphertext. Only its reveal decrypts it, for a caller who may read the record and the field, and every reveal is audited. Every API write encrypts it: the record form, REST, batches, imports, [public forms](forms.md)) and `records` in [API functions](../guides/api-functions.md)). The [Supabase-compatible REST API](supabase-rest.md#encrypted-fields)) refuses to write or filter it.
|
|
@@ -218,7 +220,7 @@ It takes `f.text()` only, and cannot be `.readOnly()` or have a `.dbDefault()`.
|
|
|
218
220
|
|
|
219
221
|
**Write it only through the API.** SQL of your own, in an API function's `db`, a write hook's transaction or the assistant's approved changes, stores the value unencrypted, and its reveal then fails until [`protobase encryption apply`](cli.md#encryption-apply)) encrypts it.
|
|
220
222
|
|
|
221
|
-
**Your code never sees the stored value, only whether it is set.** Access rules cannot filter on it: a rule that returns a filter on it fails the request. Record rules, validators and write hooks get a stored record with a set value as `encrypted` (exported from `@protobase/schema`) and an empty one as `null`. Check whether it is set with `== null`; the marker is never equal to anything, so a rule comparing it with a constant decides as if it held another value, and reading it as text throws.
|
|
223
|
+
**Your code never sees the stored value, only whether it is set.** Access rules cannot filter on it: a rule that returns a filter on it fails the request. Record rules, validators and write hooks get a stored record with a set value as `encrypted` (exported from `@protobase/schema`) and an empty one as `null`. Check whether it is set with `== null`; the marker is never equal to anything, so a rule comparing it with a constant decides as if it held another value, and reading it as text throws. A [webhook subscription's access check](#sensitive-fields) cannot know whether it is set, as for every sensitive field. Rules and validators see the plaintext only where a write gives it, so a validator written this way checks each value written and leaves a stored one alone:
|
|
222
224
|
|
|
223
225
|
```ts
|
|
224
226
|
.validate((r) => (typeof r.iban === 'string' && !r.iban.startsWith('NL') ? [{ field: 'iban', message: 'A Dutch IBAN' }] : undefined))
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/mcp.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# MCP
|
|
4
|
+
|
|
5
|
+
The app's MCP endpoint, through which a person's AI client lists resources and finds and reads records with that person's access.
|
|
6
|
+
|
|
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
|
+
|
|
9
|
+
## Turning it on
|
|
10
|
+
|
|
11
|
+
One option of `createAuth` turns it on:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
createAuth({ ..., mcp: true })
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Run `protobase auth migration` after turning it on, for the OAuth tables. The endpoint is `https://<app>/api/mcp`, or the path `mcp.path` names. How clients register, how people sign in and allow them, and how they disconnect them is in [OAuth for MCP clients](auth.md#oauth-for-mcp-clients)).
|
|
18
|
+
|
|
19
|
+
## Connecting a client
|
|
20
|
+
|
|
21
|
+
Give the client the endpoint's address. It finds the app's sign-in from there, opens it in the browser, and the person signs in and allows it on the app's connect page.
|
|
22
|
+
|
|
23
|
+
- A chat assistant usually takes a remote MCP server, or custom connector, in its settings: add one with the address.
|
|
24
|
+
- A code editor or agent usually reads its MCP servers from a JSON file, in this shape or close to it:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{ "mcpServers": { "my-app": { "url": "https://my-app.example.com/api/mcp" } } }
|
|
28
|
+
```
|
|
29
|
+
|
|
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
|
+
|
|
32
|
+
## The tools
|
|
33
|
+
|
|
34
|
+
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)).
|
|
35
|
+
|
|
36
|
+
| Tool | What it does |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `list_resources` | The resources the person may read, with their labels, key and fields: each field's type, label, enum values, the resource a relation links to, and whether filters and sorts take it. |
|
|
39
|
+
| `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. |
|
|
40
|
+
| `get_record` | One record by its key, with its ETag. A composite key is passed as the values of its fields, in order. |
|
|
41
|
+
|
|
42
|
+
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": ... }`.
|
|
43
|
+
|
|
44
|
+
### SQL for admins
|
|
45
|
+
|
|
46
|
+
`createAdmin`'s `options.mcp.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:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
createAdmin({ ..., auth, options: { mcp: { sql: true } } })
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
It runs one `SELECT` in a read-only transaction, as the app's database role, **outside the access rules and tenant scoping**: whoever has one of those roles reads the whole database through it. Give those roles only to people who may see all of the data.
|
|
53
|
+
|
|
54
|
+
## Browsers and hosts
|
|
55
|
+
|
|
56
|
+
A client in a browser may call the endpoint from any origin: it sends its token, never cookies. A request addressed to another host than the app's `baseURL` is refused, against DNS rebinding.
|
|
57
|
+
|
|
58
|
+
The endpoint serves each request on its own, without an MCP session: a `GET` or `DELETE` answers 405.
|
|
59
|
+
|
|
60
|
+
## Building on it
|
|
61
|
+
|
|
62
|
+
`@protobase/server` exports the pieces the endpoint is made of, for an MCP server of your own with tools of your own:
|
|
63
|
+
|
|
64
|
+
- `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)` builds for its caller.
|
|
65
|
+
- `mcpServer({ info, tools, context, report })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools)), each with its JSON Schema and its `annotations`, MCP's tool hints.
|
|
66
|
+
- `mcpTools({ db, sql })`: the default tools for a session.
|
|
67
|
+
- `mcpGate({ authenticate, resource, scope })`: the token check alone, answering 401 or 403 with a challenge that names the resource's metadata.
|
|
68
|
+
- `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.
|
|
69
|
+
|
|
70
|
+
A tool of your own goes on the server `server` returns, with the context its tools get:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { defineTool, mcpHandler, mcpServer, type Session, type ToolContext } from '@protobase/server'
|
|
74
|
+
|
|
75
|
+
const ping = defineTool({
|
|
76
|
+
name: 'ping',
|
|
77
|
+
description: 'Answers pong.',
|
|
78
|
+
parameters: { type: 'object', properties: {} },
|
|
79
|
+
annotations: { readOnlyHint: true },
|
|
80
|
+
run: async () => 'pong',
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const context = (session: Session): ToolContext => ({
|
|
84
|
+
session,
|
|
85
|
+
records: myRecords(session),
|
|
86
|
+
resources: async () => ({ models: [], views: [] }),
|
|
87
|
+
show: () => {},
|
|
88
|
+
approve: () => Promise.reject(new Error('Not implemented: this server asks for no approval')),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const handler = mcpHandler({
|
|
92
|
+
authenticate: authenticate.forAudience(auth.mcp.resource),
|
|
93
|
+
resource: auth.mcp.resource,
|
|
94
|
+
scope: auth.mcp.scope,
|
|
95
|
+
server: (session) => mcpServer({ info: { name: 'My app', version: '1.0.0' }, tools: [ping], context: context(session), report: console.error }),
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`mcpServer` returns the SDK's `McpServer`, so `registerTool` on it adds a tool written against the SDK directly.
|
|
@@ -54,7 +54,7 @@ export const rushOrders = subscription('rushOrders', {
|
|
|
54
54
|
| --- | --- |
|
|
55
55
|
| `events` | Event names (`orders.created`), every event of a resource (`orders.*`), or all of them (`*`). Each must match a declared event. |
|
|
56
56
|
| `when` | A filter on the record after the change, or before it for a delete, in the language of access rules. |
|
|
57
|
-
| `as: { roles }` | Delivers as these roles: only records they may read, and only fields they may read. Without it, every record and every field but the sensitive ones. |
|
|
57
|
+
| `as: { roles }` | Delivers as these roles: only records they may read, and only fields they may read. Without it, every record and every field but the sensitive ones. Their access rules cannot read a sensitive field, which a captured change does not hold: a change they would need one for is kept as failed. Check the role before such a field, as in `ctx.user.roles.includes('admin') \|\| record.api_secret == null`, or decide on a field that is not sensitive (see [Sensitive fields](data-config.md#sensitive-fields))). |
|
|
58
58
|
| `tenant` | Only events of this tenant's records. |
|
|
59
59
|
| `payload` | `thin` leaves `after` and `before` out, for a receiver that reads the record through the API. Default `full`. |
|
|
60
60
|
| `ordered` | One delivery at a time per record, in commit order. Default false. |
|
|
@@ -96,7 +96,7 @@ A function target is called as the subscription's `as`, so `context.caller()` an
|
|
|
96
96
|
- **After the last try** the job is kept as failed, on the [failed jobs page](jobs.md#failed-jobs-page)), where it can be retried.
|
|
97
97
|
- **Ordered subscriptions** get no first try from the dispatch job: a `webhooks.deliver-ordered` job delivers a record's events of one dispatch in order, retried with doubling waits from 5 s up to a day, 10 tries. Meanwhile the record's later events to that subscription wait. A retry sends again the events of that job that went through before the one that failed.
|
|
98
98
|
- **At least once:** a process that stops after delivering but before recording it delivers again when the dispatch job is retried, under the same `webhook-id`.
|
|
99
|
-
- **Event code that throws**, such as a `match` that reads a field it did not expect to be empty, a subscription's `when` or an access rule of its `as` roles, keeps that change as a failed `webhooks.dispatch-change` job on the failed jobs page, naming the event or subscription and the error, and dispatch moves on to later changes. Retry it once the code is fixed to deliver the change's events. A database error instead fails the whole dispatch job, which is retried.
|
|
99
|
+
- **Event code that throws**, such as a `match` that reads a field it did not expect to be empty, a subscription's `when` or an access rule of its `as` roles, keeps that change as a failed `webhooks.dispatch-change` job on the failed jobs page, naming the event or subscription and the error, and dispatch moves on to later changes. Retry it once the code is fixed to deliver the change's events. An access rule of `as` roles keeps the change as failed for that subscription only: the other subscriptions still receive it, and the retry delivers it to that subscription alone. A database error instead fails the whole dispatch job, which is retried.
|
|
100
100
|
|
|
101
101
|
Every outcome is a line in the server log, such as `webhook newOrdersToSlack orders.created evt_48211_created delivered (200)`.
|
|
102
102
|
|