@protobase/cli 0.41.1 → 0.43.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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.41.1";
2
+ var version = "0.43.0";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.41.1",
3
+ "version": "0.43.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.41.1",
40
- "@protobase/query": "0.41.1",
41
- "@protobase/schema": "0.41.1",
42
- "@protobase/server": "0.41.1",
43
- "@protobase/ui": "0.41.1",
39
+ "@protobase/layout": "0.43.0",
40
+ "@protobase/query": "0.43.0",
41
+ "@protobase/schema": "0.43.0",
42
+ "@protobase/server": "0.43.0",
43
+ "@protobase/ui": "0.43.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",
@@ -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.
13
- - [MCP writes](../reference/mcp.md#writes): When turned on, for every resource or only those you list, AI clients create and update records after the person approves each write.
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 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.
@@ -47,7 +47,7 @@ The second argument of a handler (`c.env` in a [Hono app](#hono-apps)):
47
47
  | | |
48
48
  | --- | --- |
49
49
  | `session` | The caller: `{ user: { id, roles }, tenant? }`, from the app's `authenticate`. |
50
- | `records` | The app's resources, acting as the caller: `list`, `get`, `create`, `update`, `delete`. |
50
+ | `records` | The app's resources, acting as the caller: `list`, `get`, `create`, `update`, `delete`, `softDeleteField`. |
51
51
  | `db` | The Kysely instance itself. It skips every access rule, row filter and tenant scope. |
52
52
  | `caller()` | Resolves to `{ session, records }`. Public functions use it to ask for a caller when they need one. |
53
53
  | `acceptWebSocket(events)` | Answers a WebSocket upgrade with a socket; return its response. See [WebSockets](#websockets). |
@@ -88,6 +88,7 @@ export default defineFunction({ roles: ['mechanic', 'desk'] }, async (request, {
88
88
  | `create(resource, data)` | `{ record, etag }` of the new record. |
89
89
  | `update(resource, key, data, { etag }?)` | With `etag`, it fails with `412` when the record changed after it was read. |
90
90
  | `delete(resource, key, { etag }?)` | `{ record, etag }` of the record as it was. It is a soft delete when the resource has one. |
91
+ | `softDeleteField(resource)` | The field a delete sets when the resource has a soft delete, or `undefined` when a delete removes the record. |
91
92
 
92
93
  A refusal or a missing record rejects with the problem the REST API would answer, such as `403`, `404` or `412`. Left uncaught, that problem becomes the function's response. Each call is its own transaction. Use the [batch endpoint](../reference/api.md#batch-writes) when several writes must succeed or fail together.
93
94
 
@@ -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)` 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.
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
 
@@ -53,7 +55,7 @@ It runs one `SELECT` in a read-only transaction, as the app's database role, **o
53
55
 
54
56
  ### Writes
55
57
 
56
- `createAdmin`'s `options.mcp.writes` also offers two tools that change records, to everyone signed in:
58
+ `createAdmin`'s `options.mcp.writes` also offers three tools that change records, to everyone signed in:
57
59
 
58
60
  ```ts
59
61
  createAdmin({ ..., auth, options: { mcp: { writes: true } } })
@@ -62,11 +64,13 @@ createAdmin({ ..., auth, options: { mcp: { writes: true } } })
62
64
  | Tool | What it does |
63
65
  | --- | --- |
64
66
  | `create_record` | Creates a record of a resource from `data`, field names to values, and returns it with its ETag. |
65
- | `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. |
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`. |
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). |
66
70
 
67
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.
68
72
 
69
- Before each write the client asks the person to approve it, showing the resource and the data, through MCP's form elicitation. Nothing is written until they approve, and declining writes nothing. A client's own setting that always allows a tool is not this approval. A client that cannot ask, one without form elicitation or one on the 2025 protocol, gets each write refused with a message saying so.
73
+ Before each write the client asks the person to approve it, showing the resource and the data, or for a delete the resource, the key and whether the record can be restored, through MCP's form elicitation. For a resource without a soft delete, the approval says plainly that the delete cannot be undone. Nothing is written until they approve, and declining writes nothing. A client's own setting that always allows a tool is not this approval. A client that cannot ask, one without form elicitation or one on the 2025 protocol, gets each write refused with a message saying so.
70
74
 
71
75
  To offer the writes on some resources only, list them:
72
76
 
@@ -84,11 +88,30 @@ An app that runs service accounts over MCP, such as a backend job or an agent wi
84
88
  createAdmin({ ..., auth, options: { mcp: { writes: { resources: ['tasks'], rolesWithoutApproval: ['service'] } } } })
85
89
  ```
86
90
 
87
- A user with one of those roles creates and updates records over MCP without the approval step: the client is never asked, so a client that cannot ask writes too. Their role's access rules and the listed resources still limit every write as before, so a job with no person present can keep the app's data over MCP and do nothing there it could not do through the REST API. Everyone else is still asked before each write.
91
+ A user with one of those roles creates, updates and deletes records over MCP without the approval step: the client is never asked, so a client that cannot ask writes too. Their role's access rules and the listed resources still limit every write as before, so a job with no person present can keep the app's data over MCP and do nothing there it could not do through the REST API. Everyone else is still asked before each write.
88
92
 
89
93
  No role is exempt unless named. The roles are checked against the signed-in user, not against the client, and a user holding several is exempt when any of them is named. A name that is not one of the app's roles, or is `anonymous`, stops the server at startup. Naming a role a person signs in with lets any client that person allows write as them unasked.
90
94
 
91
- Nothing can be deleted over MCP, and there is no SQL that writes.
95
+ A deleted record cannot be restored over MCP, and there is no SQL that writes.
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.
92
115
 
93
116
  ## Browsers and hosts
94
117
 
@@ -103,7 +126,7 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
103
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.
104
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`.
105
128
  - `mcpTools({ db, sql, writes })`: the default tools for a session; `writes` is `true`, `false` or `{ resources, rolesWithoutApproval }`.
106
- - `writeRecordTools({ resources })`, or `createRecordTool(...)` and `updateRecordTool(...)`: 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.
107
130
  - `mcpGate({ authenticate, resource, scope })`: the token check alone, answering 401 or 403 with a challenge that names the resource's metadata.
108
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.
109
132