@rsc-kit/mcp 0.33.0 → 0.35.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.
@@ -394,6 +394,44 @@ caching](/guides/edge-caching) covers what that buys. What rsc-kit puts in it:
394
394
  the postponed state from its own build, so it never parses what a caller
395
395
  wrote.
396
396
 
397
+ ### The files: `.output/files.json`
398
+
399
+ A server in front of the app — nginx, a CDN, a PHP front controller — can
400
+ answer the app's files from disk without asking it. Everything under
401
+ `.output/public` is served before the renderer is reached, so nothing of the
402
+ app runs for a file: no `middleware.ts`, no `route.ts`, and
403
+ `rscKit({ headers })` is a page's, not a file's. Every server build says what
404
+ that takes:
405
+
406
+ ```json
407
+ {
408
+ "v": 1,
409
+ "root": "public",
410
+ "files": ["/assets/app-1a2b3c4d.js", "/favicon.ico", "/sw.js"],
411
+ "precompressed": ["br", "gzip", "zstd"],
412
+ "headers": [
413
+ { "match": "/sw.js", "headers": { "cache-control": "public, max-age=0, must-revalidate" } },
414
+ { "match": "/assets/**", "headers": { "cache-control": "public, max-age=31536000, immutable" } }
415
+ ],
416
+ "middleware": false
417
+ }
418
+ ```
419
+
420
+ - **`files`** is every file a request may be answered with, by url path,
421
+ relative to `root` (beside `files.json`). Nothing else under `root` is
422
+ public: the stored pages a Workers build copies there are not in it.
423
+ - **`precompressed`** names the encodings a file may also exist in, as a
424
+ sibling with the suffix (`/sw.js.br`, `.gz`, `.zst`). Send it with
425
+ `Content-Encoding` and `Vary: Accept-Encoding` when the request accepts it.
426
+ - **`headers`** are what a file goes out with beyond its `Content-Type`: each
427
+ applies to an exact path, or, ending in `/**`, to every path under it. They
428
+ are the route rules the build's own server uses, so a front that sends them
429
+ answers exactly as the app would. Mind `/sw.js`: a service worker kept by a
430
+ heuristic cache installs the previous deploy's file list against the new
431
+ server.
432
+ - **`middleware`** is always `false`, and says so rather than leave a front
433
+ to wonder whether a guard is skipped.
434
+
397
435
  Do not work the list out from the files in `.output/server/rsc-static/`. A
398
436
  guarded page has a shell on disk too, `_team_` cannot say whether it was a
399
437
  parameter or a folder of that name, and the folder's layout is not a contract.
package/guides/domains.md CHANGED
@@ -26,24 +26,14 @@ whole host. The site's own hosts — the one in the root layout's
26
26
  nothing, so the apex keeps path routing and an app adds tenants without moving
27
27
  a file. `localhost` and an ip address are always the site's own.
28
28
 
29
- Nothing to configure for that: `metadataBase` names the apex, and a
30
- directory does the rest. `hosts` is for a name that is neither the apex nor a
31
- subdomain of it and is still the site rather than a tenant — a staging or
32
- internal name, or a second brand domain:
33
-
34
- ```ts title="vite.config.ts"
35
- rscKit({ hosts: ['app.internal', 'example.co.uk'] })
36
- ```
37
-
38
- Listing a subdomain there makes it the site by path instead of a tenant —
29
+ Listing a subdomain in `hosts` makes it the site by path instead of a tenant —
39
30
  the "app on `app.example.com`, marketing on the apex" split — which is a
40
31
  choice, not a requirement.
41
32
 
42
33
  And only when a route could answer it: a `[domain]` (or `[host]`) directory at
43
34
  the top of `app/`, or a directory named for the host. Any other parameter
44
35
  name at the top of `app/` — `[collection]`, `[slug]` — is a path segment, as
45
- it is in Next. An app with a `metadataBase` and no tenant tree routes every
46
- host by path, and a proxy that forwards to the app by an internal name is not
36
+ it is in Next. An app with no tenant tree routes every host by path, and a proxy that forwards to the app by an internal name is not
47
37
  read as a tenant called `internal`.
48
38
 
49
39
  A subdomain of the site with no directory of its name falls back the same
@@ -59,6 +49,48 @@ The visitor's url is untouched: `acme.example.com/settings` stays in the
59
49
  address bar, and a link to `/billing` on that page goes to
60
50
  `acme.example.com/billing`. Only the match changed.
61
51
 
52
+ ## The one step: name the site's host
53
+
54
+ The router has to know which host is the site, and it learns it from either
55
+ the root layout's `metadataBase` or `rscKit({ hosts })` — one is enough, and
56
+ neither is needed for anything else here. Name neither and no host is the
57
+ site's: `merchant.example.com` is then a foreign host whose segment is the
58
+ whole name, no directory matches it, and it is served by path — the home page,
59
+ with nothing said.
60
+
61
+ `hosts` is the one to reach for when the address is in the environment, as a
62
+ Laravel app's is in `APP_URL`. It is read by the build, so the address of the
63
+ machine running it — `example.test` under Herd, the real domain in
64
+ production — is the one named:
65
+
66
+ ```ts title="vite.config.ts"
67
+ import { defineConfig, loadEnv } from 'vite'
68
+
69
+ export default defineConfig(({ mode }) => {
70
+ const env = loadEnv(mode, process.cwd(), '')
71
+
72
+ return {
73
+ plugins: [rscKit({ hosts: [new URL(env.APP_URL).host] })],
74
+ }
75
+ })
76
+ ```
77
+
78
+ `metadataBase` does the same when it is written as a literal, but it is for
79
+ metadata — the base a relative Open Graph image or canonical url is made
80
+ absolute against — and a computed one is not read for routing. An app with no
81
+ such metadata needs none.
82
+
83
+ `hosts` also takes a name that is neither the apex nor a subdomain of it and
84
+ is still the site rather than a tenant — a staging or internal name, or a
85
+ second brand domain:
86
+
87
+ ```ts title="vite.config.ts"
88
+ rscKit({ hosts: ['app.internal', 'example.co.uk'] })
89
+ ```
90
+
91
+ A directory then does the rest: `app/merchant/` is all `merchant.example.com`
92
+ needs.
93
+
62
94
  ## A tenant tree
63
95
 
64
96
  Whether the tenant exists is a guard, so it goes in `middleware.ts`. It runs
@@ -109,7 +141,7 @@ one's, and it is rendered again when one of its own values changes:
109
141
  tenant layout for globex, while the root layout above it stays mounted.
110
142
 
111
143
  `[domain]` is an ordinary dynamic segment: `params.domain` in every page and
112
- layout below it, `route('/[domain]/settings', { domain })` typed, `loading.tsx`
144
+ layout below it, `hostUrl(domain, '/settings')` to link to it (below), `loading.tsx`
113
145
  and `error.tsx` where you put them. A directory named for a host,
114
146
  `app/admin/`, wins over `[domain]` the way a static segment wins over a
115
147
  parameter anywhere else.
@@ -121,6 +153,46 @@ reached as `example.com/acme`. Next has no such guard — its `[domain]` folder
121
153
  matches any path once the rewrite is in place — which is why Next apps tuck
122
154
  the tenant tree under a route group.
123
155
 
156
+ ## Linking to another host
157
+
158
+ A typed `href` is a folder path: `/merchant/orders` is the page at
159
+ `app/merchant/orders`, and that is the url a link to it goes to — the site,
160
+ by path. Both addresses work, so nothing breaks; but when the page is meant
161
+ to be seen on `merchant.example.com`, say so with `hostUrl`:
162
+
163
+ ```tsx title="src/app/page.tsx"
164
+ import { Link } from '@rsc-kit/core/link';
165
+ import { hostUrl } from '@rsc-kit/core/routes';
166
+
167
+ <Link href={hostUrl('merchant', '/orders')}>Orders</Link> // //merchant.example.com/orders
168
+ <Link href={hostUrl(tenant.slug, '/settings')}>Settings</Link> // //testbrand.example.com/settings
169
+ <Link href={hostUrl('acme.com', '/settings')}>Settings</Link> // //acme.com/settings
170
+ <Link href={hostUrl('/pricing')}>Pricing</Link> // //example.com/pricing, from a subdomain
171
+ ```
172
+
173
+ - The first argument autocompletes to the top-level folders of `app/`, and
174
+ takes any other string too: a tenant's subdomain, read from the database
175
+ at request time. A name with a dot is a whole domain, used as written.
176
+ - The path is typed by what that host answers. For a folder it is the pages
177
+ under it, with the folder taken off — `hostUrl('merchant', '/orders')`, not
178
+ `'/merchant/orders'`. For any other name it is the tenant tree's paths.
179
+ - With one argument it is the site itself: the link back from a subdomain,
180
+ where a plain `/pricing` would stay on the subdomain.
181
+
182
+ The site's host is the first one `rscKit({ hosts })` names (a literal
183
+ `metadataBase` otherwise), port and all, so `hosts: [new URL(env.APP_URL).host]`
184
+ gives `merchant.example.test` under Herd and `merchant.example.com` in
185
+ production. With no host named, a folder's url is its path,
186
+ `/merchant/orders`, since every page is then reached by path.
187
+
188
+ It is the same string on the server and in the browser, so the link hydrates
189
+ as it was rendered, and it works in `visit()` and `redirect()` too. On the
190
+ host it names already, Link navigates without a reload; to another host it is
191
+ a full page load, as a link to another origin always is.
192
+
193
+ Nothing redirects between the two addresses. When one of them should not be
194
+ reachable, a `redirect()` in that folder's `middleware.ts` says which.
195
+
124
196
  ## Domains in a database
125
197
 
126
198
  `generateStaticParams` on the tenant route is the hook. The listed hosts are
@@ -141,9 +213,12 @@ for that tenant and stored for none, exactly as any page is.
141
213
 
142
214
  ## Locally
143
215
 
144
- Keep `metadataBase` as the production host. `localhost` and an ip address
145
- are always the site's own, so the dev server routes by path as it always
146
- did, and nothing changes until a `[domain]` directory exists. To try a tenant
216
+ `localhost` and an ip address are always the site's own, so a dev server
217
+ opened on one routes by path as it always did. A local name is not:
218
+ `example.test` under Herd or Valet is a host like any other, and
219
+ `merchant.example.test` reaches `app/merchant/` only when `example.test` is
220
+ named in `hosts` — which reading `APP_URL`, as above, does. A `metadataBase`
221
+ fixed to the production host names only that one. To try a tenant
147
222
  without DNS, send the host the router will see in production:
148
223
 
149
224
  ```bash
package/guides/go.md CHANGED
@@ -152,6 +152,11 @@ const orders = await rpc('Orders.recent', 5) // Order[]; rpc('Orders.recent',
152
152
  unless it says what it writes with a `JSONSchema` method (below).
153
153
  - **Empty, not null.** A nil slice or map in the result is sent as `[]` or
154
154
  `{}`, as its type says; only a nil pointer is `null`.
155
+ - **Who is asking.** `rsckit.ClientIP(ctx)` and `rsckit.ClientUserAgent(ctx)`
156
+ are the visitor's address and browser, sent by the renderer and believed
157
+ because the call carried the secret. `r.RemoteAddr` and `r.UserAgent()`
158
+ would be the renderer's own, the same for every visitor. Both are empty
159
+ when there is no visitor: a build, or a page stored for everyone.
155
160
 
156
161
  ### A type that writes its own JSON
157
162
 
@@ -55,6 +55,7 @@ X-Rsc-Host-Secret: a-long-random-string
55
55
  Cookie: <the visitor's, forwarded unchanged>
56
56
  Authorization: <likewise, if the page request had one>
57
57
  X-Rsc-Client-Ip: <the visitor's address, as the renderer's server saw it>
58
+ X-Rsc-Client-User-Agent: <the visitor's User-Agent>
58
59
 
59
60
  { "function": "Orders.recent", "args": [5] }
60
61
  ```
@@ -76,6 +77,13 @@ the renderer's and the same for every visitor. A throttle keyed on that puts
76
77
  everyone in one bucket. Absent when there is no visitor: a build, or a page
77
78
  stored for everyone.
78
79
 
80
+ **`X-Rsc-Client-User-Agent` is the visitor's browser**, for whatever you keep
81
+ about a request: a log, a list of signed-in devices, an audit entry. The
82
+ call's own `User-Agent` is the renderer's runtime, the same for everyone.
83
+ Believe it on the same terms as the address, and expect it absent on the same
84
+ occasions. Laravel puts it where `$request->userAgent()` reads; Go's is
85
+ `rsckit.ClientUserAgent(ctx)`.
86
+
79
87
  **Arguments that do not fit the function are a failure, not a refusal.**
80
88
  Too few, or a value your language cannot decode into the parameter's type:
81
89
  answer 500 with `error`, as Go and Laravel do. The renderer's calls are typed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsc-kit/mcp",
3
- "version": "0.33.0",
3
+ "version": "0.35.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.33.0",
37
+ "create-rsc-kit": "^0.35.0",
38
38
  "zod": "^3.25"
39
39
  },
40
40
  "devDependencies": {