@protobase/cli 0.53.0 → 0.53.2
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.53.
|
|
3
|
+
"version": "0.53.2",
|
|
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.53.
|
|
46
|
-
"@protobase/layout": "0.53.
|
|
47
|
-
"@protobase/query": "0.53.
|
|
48
|
-
"@protobase/schema": "0.53.
|
|
49
|
-
"@protobase/server": "0.53.
|
|
50
|
-
"@protobase/ui": "0.53.
|
|
45
|
+
"@protobase/config": "0.53.2",
|
|
46
|
+
"@protobase/layout": "0.53.2",
|
|
47
|
+
"@protobase/query": "0.53.2",
|
|
48
|
+
"@protobase/schema": "0.53.2",
|
|
49
|
+
"@protobase/server": "0.53.2",
|
|
50
|
+
"@protobase/ui": "0.53.2",
|
|
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,8 +10,8 @@ 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: they list the resources in a small first call, describe one resource's fields when they need them, and find and read records within that person's access, soft-deleted ones too when asked.
|
|
13
|
+
- [MCP read fields](../reference/mcp.md#reading-only-what-is-needed): AI clients read only the fields they name, a plain list returns the columns of the app's table, and the server tells clients how to keep reads small.
|
|
13
14
|
- [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
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.
|
|
16
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
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.
|
|
@@ -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"`.
|
|
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.
|
|
@@ -42,20 +42,30 @@ Each tool reads as the signed-in person: their role's access rules, row filters,
|
|
|
42
42
|
| Tool | What it does |
|
|
43
43
|
| --- | --- |
|
|
44
44
|
| `list_resources` | The resources the person may read, kept small for a client's first call: each one's name, label, the first line of its help, key and whether it soft deletes (`soft_delete`), without its fields. |
|
|
45
|
-
| `describe_resource` | One resource the person may read, with its fields: each field's type, label, help, enum values, the resource a relation links to, and whether it is optional, read-only and taken by filters and sorts. |
|
|
46
|
-
| `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. |
|
|
45
|
+
| `describe_resource` | One resource the person may read, with its fields: each field's type, label, help, enum values, the resource a relation links to, and whether it is optional, read-only and taken by filters and sorts. It also names the resource's `list_fields`, what `list_records` returns when not told which. |
|
|
46
|
+
| `list_records` | A page of a resource's records: `fields`, `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 and `total_size_estimate`, an estimate rather than an exact count. `show_deleted: true` also returns soft-deleted records. |
|
|
47
47
|
| `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. |
|
|
48
|
-
| `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.
|
|
48
|
+
| `get_record` | One record by its key, with its ETag, holding the `fields` asked for or, without them, every field. A composite key is passed as the values of its fields, in order. `show_deleted: true` also finds a soft-deleted record. |
|
|
49
49
|
|
|
50
50
|
`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.
|
|
51
51
|
|
|
52
|
-
###
|
|
52
|
+
### Reading only what is needed
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
Records can hold long texts, such as a description or notes, and a page of them can run past what a client can take in. So `list_records` and `get_record` take `fields`, the field names to return, as an [AIP-157](https://google.aip.dev/157) read mask does, with `["*"]` for every field.
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
Without `fields`, `list_records` returns the record's key and the columns of the resource's table in the app: the list's `columns` of the person's view, or its first six fields when the view has no list. `describe_resource` names them as the resource's `list_fields`, and the page names the fields it left out in `omitted_fields`. `get_record` returns every field unless told which.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
The server tells each client this when it connects, in its instructions, and the tool descriptions repeat it: name the fields needed, filter on the fields marked filterable, which are indexed, rather than paging through records to search them, and keep pages small. For example, the open tasks, newest first, ten at a time, then the brief of one of them:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{ "resource": "tasks", "fields": ["id", "status", "title"], "filter": "status = \"open\"", "order_by": "created_at desc", "page_size": 10 }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{ "resource": "tasks", "key": "42", "fields": ["brief"] }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A refusal, such as a resource the person may not read, a bad filter or a field the person may not read, comes back to the client as text it can act on, `{ "error": ..., "message": ... }`.
|
|
59
69
|
|
|
60
70
|
### Comments
|
|
61
71
|
|
|
@@ -161,7 +171,7 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
|
|
|
161
171
|
`@protobase/server` exports the pieces the endpoint is made of, for an MCP server of your own with tools of your own:
|
|
162
172
|
|
|
163
173
|
- `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.
|
|
164
|
-
- `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.
|
|
174
|
+
- `mcpServer({ info, instructions, 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. `instructions` is what it tells clients when they connect, by default `mcpInstructions`, the advice on reading records above.
|
|
165
175
|
- `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.
|
|
166
176
|
- `readRecordTools()`, or `listResourcesTool()`, `describeResourceTool()`, `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.
|
|
167
177
|
- `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`.
|