@rsc-kit/mcp 0.38.0 → 0.40.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/dist/recipes.js +35 -2
- package/dist/recipes.js.map +1 -1
- package/guides/api-routes.md +24 -0
- package/guides/backend-answered-pages.md +3 -1
- package/guides/domains.md +6 -2
- package/guides/edge-caching.md +8 -2
- package/guides/forms.md +65 -0
- package/guides/where-it-runs.md +4 -0
- package/guides/your-own-backend.md +28 -0
- package/package.json +2 -2
package/guides/api-routes.md
CHANGED
|
@@ -84,6 +84,30 @@ rscKit({ trustedOrigins: ['https://admin.example.com'] })
|
|
|
84
84
|
|
|
85
85
|
`GET`, `HEAD` and `OPTIONS` change nothing and are answered from anywhere.
|
|
86
86
|
|
|
87
|
+
### An api other sites call
|
|
88
|
+
|
|
89
|
+
A route other sites post to from the browser - a chat widget embedded on your
|
|
90
|
+
customers' pages, whose origins live in your database rather than in a config
|
|
91
|
+
file - says so itself:
|
|
92
|
+
|
|
93
|
+
```ts title="src/app/api/v1/chat/route.ts"
|
|
94
|
+
export const crossOrigin = true
|
|
95
|
+
|
|
96
|
+
export async function POST(request: Request) {
|
|
97
|
+
const key = request.headers.get('authorization') // the widget's own key
|
|
98
|
+
// ...
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Another site's request then reaches the handler **without the visitor's
|
|
103
|
+
cookies**: `cookies()`, `headers()`, `request` and any backend call see none,
|
|
104
|
+
and a guard that reads the session finds nobody. A forged post needs those
|
|
105
|
+
cookies, so taking them away is what makes the route safe to open; your own
|
|
106
|
+
site's requests keep them. Authenticate with a key the caller sends, and check
|
|
107
|
+
the `Origin` yourself if each key belongs to particular sites. Answering the
|
|
108
|
+
browser's CORS preflight - an `OPTIONS` export - is still the route's job.
|
|
109
|
+
`true` or `false` only, written as a literal: the build reads it from the source.
|
|
110
|
+
|
|
87
111
|
## Dynamic segments
|
|
88
112
|
|
|
89
113
|
`[name]` and `[...rest]` work as they do for pages, and bind into the second
|
|
@@ -110,7 +110,9 @@ browser → renderer ──render──▶ React
|
|
|
110
110
|
of the backend's urls does not get it: name the backend's prefixes with
|
|
111
111
|
`backendPaths` and they go first. A whole segment in brackets is any one
|
|
112
112
|
segment (`'/login/[provider]'` is `/login/google` and what is under it, not
|
|
113
|
-
`/login`)
|
|
113
|
+
`/login`). A page any entry would cover - `'/login'` with `app/login/page.tsx` -
|
|
114
|
+
stops the build, since it would never render; so does an entry under a folder
|
|
115
|
+
named in `subdomains`, whose visitors never send that path. The build lists the plain prefixes in
|
|
114
116
|
`.output/rsc-kit.json`, so a proxy in front can send them straight to the
|
|
115
117
|
backend without going through the renderer
|
|
116
118
|
([deployment](/hosts/deployment/#sending-the-backends-urls-past-the-renderer)).
|
package/guides/domains.md
CHANGED
|
@@ -202,13 +202,17 @@ rscKit({ hosts: [new URL(env.APP_URL).host], subdomains: ['merchant'] })
|
|
|
202
202
|
```
|
|
203
203
|
|
|
204
204
|
- `example.com/merchant/orders` answers 301 to `merchant.example.com/orders`,
|
|
205
|
-
query kept.
|
|
206
|
-
|
|
205
|
+
query kept. Only on the site's own host: on `localhost`, an address, a
|
|
206
|
+
preview or a platform's own name (`<app>.homeport.run`) the path form still
|
|
207
|
+
renders and links keep it, since there is no subdomain of those to go to.
|
|
207
208
|
- `<Link href="/merchant/orders">`, `visit('/merchant/orders')` and
|
|
208
209
|
`redirect('/merchant/orders')` go to `merchant.example.com/orders`: the typed
|
|
209
210
|
href stays the folder path, and the host is placed for you. No `hostUrl`.
|
|
210
211
|
- On the subdomain, a root path that is not under the folder is the site's:
|
|
211
212
|
`<Link href="/pricing">` goes to `example.com/pricing`.
|
|
213
|
+
- `edge.json` lists none of the folder's pages: an edge answers by path and
|
|
214
|
+
would skip the 301. A `backendPaths` entry under the folder stops the build -
|
|
215
|
+
visitors there send `/auth`, never `/merchant/auth`.
|
|
212
216
|
- The build's route table lists the folder, so a backend that names routes
|
|
213
217
|
puts them on the subdomain - Laravel's `route('merchant.orders')` is
|
|
214
218
|
`https://merchant.example.com/orders`.
|
package/guides/edge-caching.md
CHANGED
|
@@ -81,7 +81,11 @@ A CDN keeps it for 60 seconds and refreshes it in the background after that;
|
|
|
81
81
|
a browser never keeps it. rsc-kit sends `CDN-Cache-Control` (RFC 9213), so a
|
|
82
82
|
CDN that reads it can cache pages: Cloudflare does, and Homeport's edge caches
|
|
83
83
|
on nothing else and strips it before the answer leaves, so you will not see it
|
|
84
|
-
in a browser there.
|
|
84
|
+
in a browser there. `CDN-Cache-Control` goes out only when a purge can reach
|
|
85
|
+
the CDN - `CDN_PURGE_URL` set, or a purge installed with `installPurge()` - so
|
|
86
|
+
an edge that keeps pages on it alone never holds one `changed()` cannot take
|
|
87
|
+
back. Without one, `Cache-Control`'s `s-maxage` still says the same lifetime to
|
|
88
|
+
a cache that reads it. The two headers always say the same thing, and only a
|
|
85
89
|
public answer has either. While your origin is down, erroring or mid-deploy, a
|
|
86
90
|
CDN that reads `stale-if-error` serves the copy it has for up to a day rather
|
|
87
91
|
than the error. A cache revalidating a copy that has not changed is
|
|
@@ -209,7 +213,9 @@ installPurge(async ({ tags }) => {
|
|
|
209
213
|
Every CDN's purge API is its own, so this is one hook rather than a list of
|
|
210
214
|
vendors. A purge that fails is logged and never fails the change: the CDN
|
|
211
215
|
still drops its copy at its `max-age` in `CDN-Cache-Control`. `purge({ tags, paths, all })` sends
|
|
212
|
-
one yourself, from a deploy step or a webhook.
|
|
216
|
+
one yourself, from a deploy step or a webhook. A path under a folder named in
|
|
217
|
+
`subdomains` is also sent as the path its visitors use: `/merchant/orders`
|
|
218
|
+
purges `/orders` as well.
|
|
213
219
|
|
|
214
220
|
With `CDN_PURGE_URL` set, the hook is `cdnPurge()`, posting
|
|
215
221
|
`{"tags": [...]}` there, unless you installed another. It is the only name
|
package/guides/forms.md
CHANGED
|
@@ -578,6 +578,71 @@ It works on ordinary uncontrolled fields too — the form listens for `focusout`
|
|
|
578
578
|
rather than each field listening for `blur`, so `<Input name="title" />` is
|
|
579
579
|
covered without being bound to anything.
|
|
580
580
|
|
|
581
|
+
### Checked by the server before it is submitted
|
|
582
|
+
|
|
583
|
+
A schema in the browser cannot know that an email is already subscribed, or
|
|
584
|
+
that a coupon has expired. The server can, and `<Form>` asks it: when a field
|
|
585
|
+
is left **having changed**, the form sends what it holds to the action marked
|
|
586
|
+
as a check. The action's guards and validation run for that field; the action
|
|
587
|
+
itself does not. Its answer lands on `error()` like any other.
|
|
588
|
+
|
|
589
|
+
Nothing to opt into. Which actions can be asked:
|
|
590
|
+
|
|
591
|
+
- a `createActionClient()` action with an input schema - its middleware and
|
|
592
|
+
schema run, its handler is skipped;
|
|
593
|
+
- a backend function the backend says it can check without running - in
|
|
594
|
+
Laravel, any action whose first parameter is a form request (its
|
|
595
|
+
`authorize()` and `rules()`, filtered to the field, as Laravel's
|
|
596
|
+
Precognition does);
|
|
597
|
+
- nothing else. A plain `"use server"` function cannot be stopped before its
|
|
598
|
+
body, so it is never called to check, and the form stops asking after the
|
|
599
|
+
first answer says so.
|
|
600
|
+
|
|
601
|
+
A field the browser's schema already refuses costs no round trip, a field
|
|
602
|
+
passed through without being changed is not asked about again, and a file goes
|
|
603
|
+
only when its own field is the one being checked.
|
|
604
|
+
|
|
605
|
+
#### When a blur is not the moment
|
|
606
|
+
|
|
607
|
+
`validate()` asks now, about the fields you name - or every field, with none.
|
|
608
|
+
It resolves `true` when they pass. That is a wizard's step:
|
|
609
|
+
|
|
610
|
+
```tsx
|
|
611
|
+
<Form action={register}>
|
|
612
|
+
{({ validate, validating, valid, error }) => (
|
|
613
|
+
<>
|
|
614
|
+
{step === 1 && (
|
|
615
|
+
<>
|
|
616
|
+
<Input name="email" />
|
|
617
|
+
{valid('email') && <Check />}
|
|
618
|
+
{error('email') && <p>{error('email')}</p>}
|
|
619
|
+
<Button
|
|
620
|
+
type="button"
|
|
621
|
+
disabled={validating}
|
|
622
|
+
onClick={async () => (await validate('email', 'name')) && setStep(2)}
|
|
623
|
+
>
|
|
624
|
+
Next
|
|
625
|
+
</Button>
|
|
626
|
+
</>
|
|
627
|
+
)}
|
|
628
|
+
{/* ... */}
|
|
629
|
+
</>
|
|
630
|
+
)}
|
|
631
|
+
</Form>
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
A step's fields stay in the form while hidden (render them with `hidden`
|
|
635
|
+
rather than not at all), so the last step's submit sends every one.
|
|
636
|
+
|
|
637
|
+
`*` stands for one segment of a nested name, as in Laravel: `validate('items.*.sku')`.
|
|
638
|
+
For a field checked as it is typed, call `validate('handle')` from its
|
|
639
|
+
`onChange` - and debounce it yourself; the form does not decide how often you
|
|
640
|
+
may ask.
|
|
641
|
+
|
|
642
|
+
`validating` is true while a check is out. `valid(name)` is true once a check
|
|
643
|
+
of that field passed and it has not been edited since - for a tick beside it,
|
|
644
|
+
not for deciding anything.
|
|
645
|
+
|
|
581
646
|
### After a successful submit
|
|
582
647
|
|
|
583
648
|
```tsx
|
package/guides/where-it-runs.md
CHANGED
|
@@ -346,6 +346,10 @@ Nitro's own `latest` tag is a dated prerelease, and it sorts **above** the plain
|
|
|
346
346
|
complaint and then answers 404 to every route. TanStack Start pins a dated beta
|
|
347
347
|
for the same reason.
|
|
348
348
|
|
|
349
|
+
That version is also the oldest rsc-kit runs on. The build stops with the line to
|
|
350
|
+
change if the app has an older Nitro, `3.0.0` included. A later dated release
|
|
351
|
+
passes.
|
|
352
|
+
|
|
349
353
|
## Assets are Nitro's
|
|
350
354
|
|
|
351
355
|
The build writes browser assets to `.output/public`, and Nitro serves them from
|
|
@@ -386,6 +386,34 @@ it cannot go stale: a stale one names a method since renamed, and nothing
|
|
|
386
386
|
fails until the browser calls it. Laravel's `rsc:host-manifest` is this
|
|
387
387
|
step; a Go registry's `WriteManifest` writes the same file.
|
|
388
388
|
|
|
389
|
+
### Checking a form before it is submitted
|
|
390
|
+
|
|
391
|
+
`<Form>` asks whether a field would pass before the form is sent, and an
|
|
392
|
+
action whose validation runs before its body can answer without running.
|
|
393
|
+
List those functions in `rsc-host.json` - a function not listed is never sent
|
|
394
|
+
a check, because a backend that has never heard of one would run the call:
|
|
395
|
+
|
|
396
|
+
```json
|
|
397
|
+
"validates": ["Profile.update"]
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
The check is an ordinary call with `validate` beside its `args`, never in a
|
|
401
|
+
batch: the fields to check, `*` matching one segment of a dotted name, and an
|
|
402
|
+
empty list meaning every field.
|
|
403
|
+
|
|
404
|
+
```json
|
|
405
|
+
{ "function": "Profile.update", "args": [{ "email": "taken@example.com" }], "validate": ["email"] }
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Run what would refuse the call - authentication, authorization, validation,
|
|
409
|
+
limited to those fields - and stop there. Fields that pass answer
|
|
410
|
+
`{ "result": null }`; fields that do not answer the [422 with
|
|
411
|
+
`validationErrors`](#the-reply) a submit would. Nothing may be written. Any
|
|
412
|
+
other refusal is no verdict on the fields, and the form shows nothing for it.
|
|
413
|
+
|
|
414
|
+
Laravel does this for a function whose first parameter is a form request,
|
|
415
|
+
with Precognition's own rule filtering.
|
|
416
|
+
|
|
389
417
|
### A message for the next page
|
|
390
418
|
|
|
391
419
|
`useFlash()` on the page shows what an action leaves for the next one. Your
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.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.
|
|
37
|
+
"create-rsc-kit": "^0.40.0",
|
|
38
38
|
"zod": "^3.25"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|