@softr/sdk 1.15.3 → 1.15.4

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.15.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Skills: the mcp skill and the `defineTool` docs now say that a tool's handler never calls `ds`, or anything else from `@softr/sdk/server`, itself. `src/start.ts` imports the tools and is part of the browser bundle, so such a handler fails the production build. Action: move each such call into a helper wrapped in `createServerOnlyFn` from `@tanstack/react-start`, and call the helper from the handler.
8
+
3
9
  ## 1.15.3
4
10
 
5
11
  ### Patch Changes
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.15.3";
2
+ var version = "1.15.4";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/tool.d.ts CHANGED
@@ -37,8 +37,12 @@ type ToolDefinition<TInput extends z.ZodObject, TOutput> = {
37
37
  */
38
38
  destructive?: boolean;
39
39
  /**
40
- * Runs the tool as the signed-in user. `ds` calls inside it act as that user,
41
- * with their groups, as a click in the app would. Return JSON.
40
+ * Runs the tool as the signed-in user. The `ds` calls it reaches act as that
41
+ * user, with their groups, as a click in the app would. Return JSON.
42
+ *
43
+ * Never call `ds`, or anything else from `@softr/sdk/server`, in the handler
44
+ * itself: the production build fails. Call a helper wrapped in
45
+ * `createServerOnlyFn` from `@tanstack/react-start`.
42
46
  */
43
47
  handler: (input: z.output<TInput>, context: {
44
48
  user: User;
@@ -48,6 +52,7 @@ type ToolDefinition<TInput extends z.ZodObject, TOutput> = {
48
52
  * An MCP tool that runs the app's own logic, for `softrMcpMiddleware({ tools })`.
49
53
  *
50
54
  * @example
55
+ * // createIssueFor is wrapped in createServerOnlyFn, and calls `ds`.
51
56
  * export const createIssue = defineTool({
52
57
  * name: 'create_issue',
53
58
  * description: 'Create an issue in a project. Returns the new issue with its key.',
package/dist/tool.js CHANGED
@@ -8,6 +8,7 @@ const TOOL_NAME = /^[A-Za-z0-9_.-]{1,128}$/;
8
8
  * An MCP tool that runs the app's own logic, for `softrMcpMiddleware({ tools })`.
9
9
  *
10
10
  * @example
11
+ * // createIssueFor is wrapped in createServerOnlyFn, and calls `ds`.
11
12
  * export const createIssue = defineTool({
12
13
  * name: 'create_issue',
13
14
  * description: 'Create an issue in a project. Returns the new issue with its key.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.15.3",
3
+ "version": "1.15.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: core
13
13
  library: softr-sdk
14
- library_version: 1.15.3
14
+ library_version: 1.15.4
15
15
  ---
16
16
 
17
17
  # 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.15.3
16
+ library_version: 1.15.4
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.15.3
13
+ library_version: 1.15.4
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.15.3
13
+ library_version: 1.15.4
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.15.3
14
+ library_version: 1.15.4
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.15.3
15
+ library_version: 1.15.4
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.15.3
10
+ library_version: 1.15.4
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.15.3
11
+ library_version: 1.15.4
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.15.3
10
+ library_version: 1.15.4
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.
@@ -11,10 +11,10 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.15.3
14
+ library_version: 1.15.4
15
15
  ---
16
16
 
17
- **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. The tools you hand it come from `defineTool`, also on `@softr/sdk`, and call the same server logic the pages do.
17
+ **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. The tools you hand it come from `defineTool`, also on `@softr/sdk`, and call the same server logic the pages do. `src/start.ts` is part of the browser bundle, so a tool's handler never calls `ds` itself: it calls a helper wrapped in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary).
18
18
 
19
19
  # MCP
20
20
 
@@ -57,10 +57,8 @@ An action is one list, create, update or delete on one datasource. When the app
57
57
  ```ts
58
58
  // src/mcp-tools.ts
59
59
  import { defineTool } from '@softr/sdk'
60
- import { ds } from '@softr/sdk/server'
61
60
  import { z } from 'zod'
62
- import { createIssueFor } from './issues'
63
- import { projectIssues } from './actions'
61
+ import { createIssueFor, listIssues } from './issues'
64
62
 
65
63
  export const createIssue = defineTool({
66
64
  name: 'create_issue',
@@ -83,16 +81,30 @@ export const findIssues = defineTool({
83
81
  status: z.enum(['open', 'done']).optional().describe('Only issues with this status.'),
84
82
  }),
85
83
  readOnly: true,
86
- handler: async (input) => {
87
- let list = ds.list(projectIssues).where((q) => q.project.isOneOf([input.projectId]))
88
- if (input.status) list = list.where((q) => q.status.is(input.status))
89
- const { records } = await list.orderBy((q) => q.createdAt.desc).limit(50)
90
- return { issues: records.map((r) => ({ id: r.id, ...r.fields })) }
91
- },
84
+ handler: async (input) => ({ issues: await listIssues(input) }),
85
+ })
86
+ ```
87
+
88
+ The `ds` calls live in helpers wrapped in `createServerOnlyFn`, in a file of their own:
89
+
90
+ ```ts
91
+ // src/issues.ts
92
+ import { createServerOnlyFn } from '@tanstack/react-start'
93
+ import { ds } from '@softr/sdk/server'
94
+ import { projectIssues } from './actions'
95
+
96
+ export const listIssues = createServerOnlyFn(async ({ projectId, status }: { projectId: string; status?: 'open' | 'done' }) => {
97
+ let list = ds.list(projectIssues).where((q) => q.project.isOneOf([projectId]))
98
+ if (status) list = list.where((q) => q.status.is(status))
99
+ const { records } = await list.orderBy((q) => q.createdAt.desc).limit(50)
100
+ return records.map((r) => ({ id: r.id, ...r.fields }))
92
101
  })
93
102
  ```
94
103
 
95
- - **`handler` runs as the signed-in user.** `ds` calls inside it act as that user, with their groups, as a click in the app would. `user` is the same `User` a server function reads from `context.user`. Move logic a server function and a tool share into a function that takes the user, and pass `context.user` from the server function and `user` from the tool.
104
+ `createIssueFor` is wrapped the same way.
105
+
106
+ - **`handler` runs as the signed-in user.** The `ds` calls its helpers make act as that user, with their groups, as a click in the app would. `user` is the same `User` a server function reads from `context.user`. Move logic a server function and a tool share into a function that takes the user, and pass `context.user` from the server function and `user` from the tool.
107
+ - **`handler` never calls `ds` itself.** Nor anything else from `@softr/sdk/server`. Each such call goes in a helper wrapped in `createServerOnlyFn`, and the handler calls the helper. A helper the app's server functions already use is fine as long as it is wrapped.
96
108
  - **`readOnly` is required.** `true` only when the tool changes nothing. A read-only tool that calls `ds.create`, `ds.update`, `ds.delete`, `email`, `workflow`, `upload` or an `integration` action whose method is not `GET` or `HEAD` from `@softr/sdk/server` fails with an error, and nothing is written or sent. An integration that reads with `POST`, such as a search or GraphQL API, fails too: make that tool `readOnly: false`. So does every `auth` call that is not a plain read: a sign-in, a sign-up, a password reset, a sign-out, a profile change or an authenticator change. Your own calls to other services are not stopped, so keep them out of a read-only tool too. An `ai` call is not stopped either: it changes no data, but it spends the workspace's AI credits for an assistant approved to read only, so use it there on purpose.
97
109
  - **`destructive`** says whether a tool that is not read-only deletes or overwrites data: `true` when it does, `false` when it only adds. The assistant may ask the user before it runs a destructive one. Left out, the assistant is told neither and treats the tool as one that may delete or overwrite, so set it on every tool that is not read-only.
98
110
  - **`input` is a zod object.** Describe each field with `.describe()`: the assistant reads it. Use types JSON can carry: a string for a date, not `z.date()`, which fails when the tool is defined. A top-level argument the schema does not name is refused with a message saying which, and the handler does not run. Inside a nested object an unknown key is dropped without a word, so declare a nested object with `z.strictObject` to have it refused too.
@@ -125,6 +137,8 @@ Connecting starts with an approval page the app serves. Most people hit it signe
125
137
 
126
138
  **A write as an action, where the app has logic around it.** The record is written and everything the app does around it is skipped: no counter, no log entry, no email, no author. Write it as a `defineTool` that calls that logic.
127
139
 
140
+ **A tool handler that calls `ds` directly fails the production build.** `src/start.ts` imports the tool, so the server-only import reaches the browser bundle. The preview may still work, and publishing fails. Move the call into a `createServerOnlyFn` helper.
141
+
128
142
  **Marking a tool read-only that changes data.** Its writes fail when it runs. Set `readOnly: false`.
129
143
 
130
144
  **Registering after `softrAuthMiddleware`.** Not a supported order. Put the MCP middleware first.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.15.3
12
+ library_version: 1.15.4
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.15.3
13
+ library_version: 1.15.4
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.15.3
13
+ library_version: 1.15.4
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.15.3
14
+ library_version: 1.15.4
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.15.3
12
+ library_version: 1.15.4
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.15.3
12
+ library_version: 1.15.4
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.15.3
12
+ library_version: 1.15.4
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.