@rsc-kit/mcp 0.42.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.
@@ -132,6 +132,87 @@ rscKit({
132
132
  typed a moment after it is saved.
133
133
  - `watch` names the backend's source, relative to the project root.
134
134
 
135
+ ### Answered at build time
136
+
137
+ With `hostManifest`, the build also asks the backend what `rpc()` answers while
138
+ it renders each page:
139
+
140
+ ```tsx title="src/app/register/page.tsx"
141
+ export default async function Register() {
142
+ const rules = await rpc('Passwords.rules') // the same for everyone: stored
143
+
144
+ return <RegisterForm rules={rules} />
145
+ }
146
+ ```
147
+
148
+ There is nothing to mark. The backend notices whether a function read who is
149
+ asking:
150
+
151
+ | The function | What the build does |
152
+ | --- | --- |
153
+ | reads nothing of the visitor's | stores the answer with the page |
154
+ | reads the session, a cookie, a header, who is signed in, or the visitor's address | leaves it to the request: the page [streams](/guides/ppr) that part |
155
+ | refuses as not signed in or not allowed, or sets a cookie | the same |
156
+ | fails | fails the build, with the backend's error |
157
+
158
+ The build's report names the calls each page stores, and what the others read:
159
+
160
+ ```text
161
+ ○ /register rpc("Passwords.rules") answered at build time, and stored
162
+ ◐ /login rpc("Auth.options") (the session) streams per request; the rest is stored
163
+ ```
164
+
165
+ A stored answer is kept until the next build. No tag, `Rsc::changed` or
166
+ `cache()` refreshes a page stored whole, as with any page that read its data
167
+ while it was built. To have it read again:
168
+
169
+ - `await connection()` before the call asks per request.
170
+ - `export const revalidate = 60` keeps the page [for a time](/guides/isr)
171
+ instead; the build doesn't store it.
172
+
173
+ What to know before the first build that does this:
174
+
175
+ - **The build runs your functions**, so it needs what they need: the database,
176
+ its environment. A function a render calls that writes something writes it
177
+ during the build.
178
+ - **Only what goes through the framework is noticed.** A function reading
179
+ `$_COOKIE` itself, or a package's own per-visitor state, looks the same for
180
+ everyone, and is stored as a guest would see it. Put `await connection()`
181
+ before it.
182
+ - **Guards still run per request.** A page under `middleware.ts` is not
183
+ answered to anyone its guards refuse.
184
+
185
+ `rscKit({ hostManifest: { command, calls: false } })` stops the build asking.
186
+ Every page that calls `rpc()` then streams it. `calls` can also be a whole
187
+ command of its own, such as `['./api', '-calls']`.
188
+
189
+ Laravel's `rsc:host-manifest` answers these calls itself. In Go, a
190
+ [flag does](/hosts/go/reading-from-go/#answered-at-build-time); an adapter of
191
+ your own says [how it is asked](/hosts/your-own-backend/calls/#during-a-build).
192
+
193
+ ### Going to the backend's function
194
+
195
+ A backend that also writes `sources` gives your editor somewhere to go:
196
+
197
+ ```json title="rsc-host.json"
198
+ {
199
+ "functions": ["Orders.recent"],
200
+ "types": { "Orders.recent": { "params": [], "result": { "type": "string" } } },
201
+ "sources": { "Orders.recent": { "file": "app/Rsc/Orders.php", "line": 24, "name": "App\\Rsc\\Orders::recent" } }
202
+ }
203
+ ```
204
+
205
+ Cmd+click (Ctrl+click) `rpc` in `rpc('Orders.recent')` opens `Orders.php` at
206
+ line 24, and hovering it names the method. No extension is needed: the build
207
+ writes a source map beside `rsc-env.d.ts`, which editors already follow.
208
+
209
+ - Click the word `rpc`. TypeScript has nothing to offer for the name in quotes.
210
+ - The function needs an entry in `types`.
211
+ - `file` is relative to `rsc-host.json`, and `line` starts at 1. `name` is
212
+ optional.
213
+ - Lines move as you edit the backend. A change to `sources` alone doesn't
214
+ restart the dev server, and `--check` doesn't call it stale.
215
+
135
216
  ### Checking it in CI
136
217
 
137
218
  If you commit `rsc-host.json` or the generated types, fail CI when they are
@@ -83,6 +83,8 @@ Use `connection()` when:
83
83
  - the database or API isn't reachable from the build machine
84
84
  - the value must differ per visitor
85
85
  - the data changes faster than you deploy
86
+ - an [`rpc()` call answered at build](/hosts/backend-answered-pages/#answered-at-build-time)
87
+ should be asked per request instead
86
88
 
87
89
  A page that reads `params`, `searchParams`, `headers()` or `cookies()` already
88
90
  waits for the request, and needs no `connection()` for that part.
@@ -26,9 +26,47 @@ Every page then adds a `script-src` and a `style-src` naming its own inline
26
26
  code: the script that boots it, and the scripts React writes to put each
27
27
  streamed part in place.
28
28
 
29
- ## Writing your own directives
29
+ ## Adding to the default
30
30
 
31
- Your directives replace the default:
31
+ `extend` adds sources to the default and keeps the rest of it. This allows
32
+ Cloudflare Turnstile, which loads a script and opens a frame:
33
+
34
+ ```ts title="vite.config.ts"
35
+ rscKit({
36
+ contentSecurityPolicy: {
37
+ extend: {
38
+ 'script-src': 'https://challenges.cloudflare.com',
39
+ 'frame-src': 'https://challenges.cloudflare.com',
40
+ },
41
+ },
42
+ })
43
+ ```
44
+
45
+ ```text
46
+ default-src 'self'; base-uri 'self'; object-src 'none'; style-src-attr 'unsafe-inline'; script-src 'self' https://challenges.cloudflare.com; frame-src 'self' https://challenges.cloudflare.com
47
+ ```
48
+
49
+ A directive takes a list or a space-separated string:
50
+
51
+ ```ts
52
+ 'img-src': ['data:', 'https://images.example.com'],
53
+ 'img-src': 'data: https://images.example.com',
54
+ ```
55
+
56
+ - **A directive the default doesn't name** starts from the one the browser
57
+ would fall back to. `script-src` starts from `default-src 'self'`, so adding
58
+ an origin never blocks your own scripts.
59
+ - **One that falls back to nothing**, such as `frame-ancestors` or
60
+ `form-action`, is only what you write.
61
+ - **A source added to a `'none'` directive** replaces the `'none'`.
62
+
63
+ `extend` only adds. Closing a directive that allows something, as in
64
+ `'frame-src': "'none'"`, fails the build: write that policy with `directives`.
65
+
66
+ ## Writing the whole policy
67
+
68
+ `directives` replaces the default, so a directive you leave out isn't sent.
69
+ Setting both `extend` and `directives` fails the build.
32
70
 
33
71
  ```ts title="vite.config.ts"
34
72
  rscKit({
@@ -46,12 +84,6 @@ rscKit({
46
84
  })
47
85
  ```
48
86
 
49
- A directive takes a list or a space-separated string:
50
-
51
- ```ts
52
- 'img-src': "'self' data: https://images.example.com",
53
- ```
54
-
55
87
  Keep `style-src-attr 'unsafe-inline'`. React's `style={{ ... }}` is a style
56
88
  attribute, which no hash or nonce can allow. An attribute can't run code, and
57
89
  without it every `style` prop is refused.
@@ -105,7 +137,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
105
137
  origin in `script-src`:
106
138
 
107
139
  ```ts
108
- 'script-src': ["'self'", 'https://plausible.io'],
140
+ extend: { 'script-src': 'https://plausible.io' },
109
141
  ```
110
142
 
111
143
  If your app writes `<style>` tags, put `'unsafe-inline'` in `style-src` and
package/guides/ppr.md CHANGED
@@ -97,7 +97,9 @@ Anything the build can't know:
97
97
  - **`await params`**, for a route that hasn't listed its URLs
98
98
  - **`await searchParams`**, the query string
99
99
  - **`await headers()` and `await cookies()`**, the request
100
- - **a host call**, on a host that has one
100
+ - **an `rpc()` call that reads the visitor**: their session, a cookie, who is
101
+ signed in. One that doesn't is [answered at build](/hosts/backend-answered-pages/#answered-at-build-time)
102
+ and stored, when the build has a backend to ask
101
103
  - **slow work of your own** that outlasts the build's time budget
102
104
 
103
105
  Each one suspends, the nearest fallback above it goes into the shell, and the
@@ -223,7 +225,7 @@ the build fails:
223
225
  ```text
224
226
  Some routes could not be prerendered:
225
227
 
226
- /dashboard — reaches for the host before anything can paint, so there is no shell to store
228
+ /dashboard — waits on rpc("Dashboard.summary") before anything can paint. Add a loading.tsx beside it, or put a <Suspense> above the waiting, and it has a skeleton to store.
227
229
 
228
230
  Each one reads request data — params, headers, cookies, or the host —
229
231
  above every Suspense boundary, so nothing can paint without it.
@@ -37,8 +37,10 @@ A refused route has its boundary in the wrong place. Put the part that waits
37
37
  inside `<Suspense>`, and the route becomes a shell. [Partial prerendering](/guides/ppr)
38
38
  covers where boundaries go.
39
39
 
40
- Whatever a stored page read during the build is in the file. If something
41
- should be current on every request, it has to read the request - `params`,
40
+ Whatever a stored page read during the build is in the file, what
41
+ [`rpc()` answered](/hosts/backend-answered-pages/#answered-at-build-time)
42
+ included, until the next build: a page stored whole is not refreshed by a tag.
43
+ If something should be current on every request, it has to read the request - `params`,
42
44
  `searchParams`, `headers()`, `cookies()` - or call
43
45
  [`connection()`](/guides/connection), which puts it behind a boundary instead
44
46
  of in the stored bytes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsc-kit/mcp",
3
- "version": "0.42.1",
3
+ "version": "0.43.0",
4
4
  "description": "An MCP server over what an rsc-kit build decided: the routes, why each one is static or not, and what it costs the browser.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@modelcontextprotocol/sdk": "^1.30.0",
37
- "create-rsc-kit": "^0.42.1",
37
+ "create-rsc-kit": "^0.43.0",
38
38
  "zod": "^3.25"
39
39
  },
40
40
  "devDependencies": {