@protobase/cli 0.42.0 → 0.43.1
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
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.1",
|
|
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.43.1",
|
|
40
|
+
"@protobase/query": "0.43.1",
|
|
41
|
+
"@protobase/schema": "0.43.1",
|
|
42
|
+
"@protobase/server": "0.43.1",
|
|
43
|
+
"@protobase/ui": "0.43.1",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -9,7 +9,8 @@ Fields and actions filled by a model, the assistant beside the admin, and MCP.
|
|
|
9
9
|
- [Assistant](../reference/assistant.md): A chat beside the admin that answers questions about the app, reads its data and proposes changes for approval.
|
|
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
|
-
- [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.
|
|
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
13
|
- [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.
|
|
14
14
|
- [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.
|
|
15
|
+
- [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.
|
|
15
16
|
- [Connected apps](../reference/auth.md#oauth-for-mcp-clients): People allow an AI client to sign in, and disconnect it later.
|
|
@@ -68,7 +68,7 @@ Making the query role needs `CREATEROLE` once, for the role that applies the mig
|
|
|
68
68
|
|
|
69
69
|
`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).
|
|
70
70
|
|
|
71
|
-
`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)`, `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. 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.
|
|
71
|
+
`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)`, `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. Each answers `{ record, etag }`. `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
|
|
|
@@ -35,9 +35,11 @@ Each tool reads as the signed-in person: their role's access rules, row filters,
|
|
|
35
35
|
|
|
36
36
|
| Tool | What it does |
|
|
37
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. |
|
|
38
|
+
| `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
|
+
| `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
|
+
| `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. |
|
|
41
|
+
|
|
42
|
+
`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. Soft-deleted records come under the same access rules, tenant and hidden fields as the rest, and carry the field their deletion set.
|
|
41
43
|
|
|
42
44
|
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
45
|
|
|
@@ -64,6 +66,7 @@ createAdmin({ ..., auth, options: { mcp: { writes: true } } })
|
|
|
64
66
|
| `create_record` | Creates a record of a resource from `data`, field names to values, and returns it with its ETag. |
|
|
65
67
|
| `update_record` | Changes the fields in `data` of one record by its key, and returns it with its new ETag. 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`. |
|
|
66
68
|
| `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
|
+
| `batch_write` | Creates, updates and deletes records across resources in one transaction, see [Batch writes](#batch-writes). |
|
|
67
70
|
|
|
68
71
|
Each write goes through the REST API as the person: their role's access rules, `validate`, write hooks, events and webhooks apply, so the client can do only what the person may do in the app.
|
|
69
72
|
|
|
@@ -91,6 +94,25 @@ No role is exempt unless named. The roles are checked against the signed-in user
|
|
|
91
94
|
|
|
92
95
|
A deleted record cannot be restored over MCP, and there is no SQL that writes.
|
|
93
96
|
|
|
97
|
+
#### Batch writes
|
|
98
|
+
|
|
99
|
+
`batch_write` takes a list of creates, updates and deletes, each naming its resource, with the key and ETag for an update or delete, and runs them in order in one transaction, as the REST API's [batch writes](api.md#batch-writes) do: either all of them are written or none, and a record changed since its ETag fails the whole batch.
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{ "operations": [
|
|
103
|
+
{ "op": "create", "resource": "tasks", "data": { "title": "Plan the release" }, "ref": "task" },
|
|
104
|
+
{ "op": "create", "resource": "task_links", "data": { "task_id": { "$ref": "task" }, "url": "https://example.com" } },
|
|
105
|
+
{ "op": "update", "resource": "tasks", "key": 12, "etag": "\"3\"", "data": { "status": "done" } },
|
|
106
|
+
{ "op": "delete", "resource": "task_links", "key": 40, "etag": "\"1\"" }
|
|
107
|
+
] }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
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": [...] }`, as the REST batch answers: each created or updated record with its new ETag, so the client can go on writing.
|
|
111
|
+
|
|
112
|
+
The person approves the batch once, seeing each write in it: how many creates, updates and deletes it makes on each resource, then each operation with its key and data, the first 50 in full and the rest counted. The approval says plainly when deletes in it cannot be undone, which is every delete on a resource that does not [soft delete](data-config.md#resource).
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
94
116
|
## Browsers and hosts
|
|
95
117
|
|
|
96
118
|
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.
|
|
@@ -104,7 +126,7 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
|
|
|
104
126
|
- `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.
|
|
105
127
|
- `mcpServer({ info, tools, context, report, rolesWithoutApproval })`: 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`: each call gets its own, which asks the client's user, or approves at once when the session's user holds one of `rolesWithoutApproval`.
|
|
106
128
|
- `mcpTools({ db, sql, writes })`: the default tools for a session; `writes` is `true`, `false` or `{ resources, rolesWithoutApproval }`.
|
|
107
|
-
- `writeRecordTools({ resources })`, or `createRecordTool(...)`, `updateRecordTool(...)` and `deleteRecordTool(...)`: the write tools alone, on the listed resources or, without `resources`, on any.
|
|
129
|
+
- `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.
|
|
108
130
|
- `mcpGate({ authenticate, resource, scope })`: the token check alone, answering 401 or 403 with a challenge that names the resource's metadata.
|
|
109
131
|
- `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.
|
|
110
132
|
|