@protobase/cli 0.36.0 → 0.37.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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.36.0";
2
+ var version = "0.37.1";
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.36.0",
3
+ "version": "0.37.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.36.0",
40
- "@protobase/query": "0.36.0",
41
- "@protobase/schema": "0.36.0",
42
- "@protobase/server": "0.36.0",
43
- "@protobase/ui": "0.36.0",
39
+ "@protobase/layout": "0.37.1",
40
+ "@protobase/query": "0.37.1",
41
+ "@protobase/schema": "0.37.1",
42
+ "@protobase/server": "0.37.1",
43
+ "@protobase/ui": "0.37.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",
@@ -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 })
@@ -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.