@softr/sdk 1.8.1 → 1.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - `softrMcpMiddleware` holds an assistant to the access its user approved. A connection approved to read only lists only the read actions and `whoami`, and a call to any other action returns an error without writing. A connection approved to make changes works as before, and so does one whose assistant asked for no particular access: it is approved for everything. A connection that can no longer make changes after the upgrade works again once you reconnect it.
8
+
3
9
  ## 1.8.1
4
10
 
5
11
  ### Patch Changes
package/dist/mcp.js CHANGED
@@ -16,10 +16,16 @@ const AUTHORIZE_PATH = "/_softr/oauth/authorize";
16
16
  const TOKEN_PATH = "/_softr/oauth/token";
17
17
  const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
18
18
  const AUTHORIZATION_SERVER_PATH = "/.well-known/oauth-authorization-server";
19
+ /** The scope that lets a caller run an action that is not a read. */
20
+ const WRITE_SCOPE = "mcp:write";
19
21
  /** What the platform grants. Advertised here so a client asks for the same. */
20
- const SCOPES = ["mcp:read", "mcp:write"];
21
- /** What a client that named no scope gets. Matches the platform's own default. */
22
- const DEFAULT_SCOPE = "mcp:read";
22
+ const SCOPES = ["mcp:read", WRITE_SCOPE];
23
+ /**
24
+ * What a client that named no scope gets: everything. Such a client chose
25
+ * nothing, and the Allow page never offered less. A client that wants less
26
+ * asks for less.
27
+ */
28
+ const DEFAULT_SCOPE = SCOPES.join(" ");
23
29
  const SUPPORTED_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26"];
24
30
  /**
25
31
  * Serves the MCP endpoint and its OAuth flow from the app's own origin.
@@ -227,14 +233,20 @@ async function platformSession(accessToken) {
227
233
  ok: false,
228
234
  refused: response.status === 401 || response.status === 403
229
235
  };
230
- const parsed = z.object({ sessionJwt: z.string() }).safeParse(await response.json().catch(() => null));
231
- return parsed.success ? {
232
- ok: true,
233
- sessionToken: parsed.data.sessionJwt
234
- } : {
236
+ const parsed = z.object({
237
+ sessionJwt: z.string(),
238
+ scope: z.string().nullish()
239
+ }).safeParse(await response.json().catch(() => null));
240
+ if (!parsed.success) return {
235
241
  ok: false,
236
242
  refused: false
237
243
  };
244
+ const scopes = parsed.data.scope?.split(" ") ?? [];
245
+ return {
246
+ ok: true,
247
+ sessionToken: parsed.data.sessionJwt,
248
+ canWrite: scopes.includes(WRITE_SCOPE)
249
+ };
238
250
  }
239
251
  const WHOAMI = {
240
252
  name: "whoami",
@@ -386,7 +398,8 @@ async function rpc(request, origin, actions) {
386
398
  if (token === null) return unauthorized(origin);
387
399
  const session = await platformSession(token);
388
400
  if (!session.ok) return session.refused ? unauthorized(origin) : unavailable();
389
- const { sessionToken } = session;
401
+ const { sessionToken, canWrite } = session;
402
+ const allowed = (action) => canWrite || action.resource.operation === "read";
390
403
  const body = await readJson(request);
391
404
  const message = z.object({
392
405
  id: z.union([z.string(), z.number()]).optional(),
@@ -415,7 +428,7 @@ async function rpc(request, origin, actions) {
415
428
  }
416
429
  });
417
430
  }
418
- case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].map(describeTool)] });
431
+ case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].filter(allowed).map(describeTool)] });
419
432
  case "tools/call": {
420
433
  const name = params?.name;
421
434
  const args = typeof params?.arguments === "object" && params.arguments !== null ? params.arguments : {};
@@ -426,6 +439,13 @@ async function rpc(request, origin, actions) {
426
439
  }
427
440
  const action = typeof name === "string" ? actions.get(name) : void 0;
428
441
  if (action === void 0) return failure(id, -32602, `Unknown tool: ${String(name)}`);
442
+ if (!allowed(action)) return result(id, {
443
+ isError: true,
444
+ content: [{
445
+ type: "text",
446
+ text: `"${action.id}" changes data, and this assistant's connection allows reading only, so it cannot run it.`
447
+ }]
448
+ });
429
449
  try {
430
450
  return result(id, toolResult(await withSessionToken(sessionToken, () => runTool(action, args))));
431
451
  } catch (error) {
@@ -472,7 +492,7 @@ function unauthorized(origin) {
472
492
  status: 401,
473
493
  headers: {
474
494
  "content-type": "application/json",
475
- "www-authenticate": `Bearer resource_metadata="${origin}${PROTECTED_RESOURCE_PATH}", scope="${SCOPES.join(" ")}"`
495
+ "www-authenticate": `Bearer resource_metadata="${origin}${PROTECTED_RESOURCE_PATH}", scope="${DEFAULT_SCOPE}"`
476
496
  }
477
497
  });
478
498
  }
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.8.1";
2
+ var version = "1.9.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: core
12
12
  library: softr-sdk
13
- library_version: 1.8.1
13
+ library_version: 1.9.0
14
14
  ---
15
15
 
16
16
  # Softr SDK core
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.8.1
16
+ library_version: 1.9.0
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.8.1
13
+ library_version: 1.9.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.8.1
13
+ library_version: 1.9.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A helper that calls `ds` outside a handler goes in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary). `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.8.1
14
+ library_version: 1.9.0
15
15
  ---
16
16
 
17
17
  # The current user
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 1.8.1
15
+ library_version: 1.9.0
16
16
  ---
17
17
 
18
18
  **Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.8.1
10
+ library_version: 1.9.0
11
11
  ---
12
12
 
13
13
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 1.8.1
11
+ library_version: 1.9.0
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.8.1
10
+ library_version: 1.9.0
11
11
  ---
12
12
 
13
13
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.8.1
12
+ library_version: 1.9.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
@@ -53,6 +53,7 @@ The list is the whole tool surface. Write it out:
53
53
 
54
54
  - An action you leave out is invisible to the assistant, even where the app's pages use it freely.
55
55
  - An action you list still obeys its own `permissions`. Listing it does not widen who may run it — the assistant runs as whoever signed in, with that user's groups.
56
+ - A write reaches only an assistant the user allowed to make changes when they connected it. One allowed to read only sees the reads and `whoami`.
56
57
  - Two actions with the same `id` throw at startup. So does anything that is not a `defineQuery` or `defineMutation` value.
57
58
 
58
59
  Reads first. Add a write only when the user asked for one, and name it back to them.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.8.1
12
+ library_version: 1.9.0
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.8.1
13
+ library_version: 1.9.0
14
14
  ---
15
15
 
16
16
  # Installing the app
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.8.1
13
+ library_version: 1.9.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.8.1
14
+ library_version: 1.9.0
15
15
  ---
16
16
 
17
17
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A route `loader` also runs in the browser, so it calls a server function, never `ds`. A helper that calls `ds` outside a handler, in this file or in another one, goes in `createServerOnlyFn` from `@tanstack/react-start`, or inside the handler. An exported helper without it keeps the server-only import in the browser bundle, and every page stops loading until it moves. Do not make such a helper a server function when it takes an id: any visitor can call a server function with any id. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.8.1
12
+ library_version: 1.9.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.8.1
12
+ library_version: 1.9.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.8.1
12
+ library_version: 1.9.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.