@rsc-kit/mcp 0.30.48 → 0.30.50

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/guides/go.md CHANGED
@@ -253,6 +253,32 @@ receives what follows the colon in its name (`"manage-orders"`, `"60,1"`,
253
253
  registered for refuses rather than passes: a declared check that silently
254
254
  does not happen is the failure this exists to prevent.
255
255
 
256
+ A guard is asked about a page, not about the call that carries it:
257
+
258
+ ```go
259
+ reg.Middleware("owns-order", func(ctx context.Context, _ string) error {
260
+ page, _ := rsckit.PageFrom(ctx) // the url the visitor asked for, and the route's params
261
+ if !owns(ctx, page.Params["order"]) {
262
+ return rsckit.Unauthorized("not your order")
263
+ }
264
+ return nil
265
+ })
266
+
267
+ reg.Middleware("throttle", func(ctx context.Context, rule string) error {
268
+ if !limiter.Allow(rsckit.ClientIP(ctx), rule) { // the visitor's address, not the renderer's
269
+ return rsckit.Refuse(429, "slow down")
270
+ }
271
+ return nil
272
+ })
273
+ ```
274
+
275
+ `page.URL` is under the public host and scheme when a proxy forwarded them,
276
+ so a signature checks against the link the visitor followed; it is empty
277
+ during a build. `page.Params` holds only what the route's segments bound,
278
+ never the query. `ClientIP` is read only once the secret matched, and is
279
+ empty when there is no visitor. One page load asks once, so a throttle
280
+ counts it once.
281
+
256
282
  ## Server actions
257
283
 
258
284
  ```go
@@ -400,10 +426,64 @@ well; `reg.SetPurger` replaces it. Call it after your transaction commits.
400
426
 
401
427
  ## Public forms
402
428
 
403
- A contact form or a sign-up is `defineForm({ action: 'Contact.send' })` in
404
- TypeScript: the fields come from the struct the function takes, with no schema
405
- to write. `rsckit.InvalidField` shows under that field.
406
- [Public forms](/guides/public-forms#go) has the code.
429
+ A contact form or a sign-up anyone may fill in is an action that takes a
430
+ struct, and a few lines of TypeScript handing that action to a form. There is
431
+ no schema to write: the fields and the browser's checks come from the struct.
432
+
433
+ **1. The action.** Its `json` tags are the field names, a `validate` tag adds
434
+ what the browser can check, and `rsckit.InvalidField` is a refusal under that
435
+ field:
436
+
437
+ ```go
438
+ type ContactInput struct {
439
+ Name string `json:"name" validate:"required,min=2"`
440
+ Email string `json:"email" validate:"required,email"`
441
+ Topic string `json:"topic" validate:"required,oneof=sales support"`
442
+ Message string `json:"message" validate:"required,min=10,max=2000"`
443
+ }
444
+
445
+ reg.HandleAction("contactSend", "Contact.send", func(ctx context.Context, in ContactInput) error {
446
+ if blocked(in.Email) {
447
+ return rsckit.InvalidField("email", "That address is blocked.")
448
+ }
449
+
450
+ return messages.Insert(ctx, in)
451
+ })
452
+ ```
453
+
454
+ The tag is read, never run: check what was sent in the function too, since a
455
+ post need not come from a browser.
456
+
457
+ **2. The form.** The build generates `contactSend` from the manifest, and
458
+ `bunx rsc-kit make:form contactSend` writes the form around it:
459
+
460
+ ```ts title="src/forms/contact.ts"
461
+ import { defineForm } from '@rsc-kit/press/forms'
462
+ import { shadcn } from '@rsc-kit/press/shadcn'
463
+ import { contactSend } from '../server-actions.generated'
464
+
465
+ export const contact = defineForm({
466
+ name: 'contact',
467
+ action: contactSend,
468
+ fields: { message: { type: 'textarea' } },
469
+ theme: shadcn,
470
+ done: 'Thanks - we will be in touch.',
471
+ })
472
+ ```
473
+
474
+ Then place it in a page, which stays static:
475
+
476
+ ```tsx title="src/app/contact/page.tsx"
477
+ import { contact } from '../../forms/contact'
478
+
479
+ export default function ContactPage() {
480
+ return <contact.Form />
481
+ }
482
+ ```
483
+
484
+ `oneof` draws a select, and a field is required unless its `json` tag says
485
+ `omitempty`. [Public forms](/guides/public-forms#go) has every tag that is read.
486
+ It needs `@rsc-kit/press` 0.30.49 and `github.com/rsc-kit/go` v0.14.0.
407
487
 
408
488
  ## Production
409
489
 
package/guides/laravel.md CHANGED
@@ -429,10 +429,95 @@ purges the CDN as well, after the transaction commits and the response has gone.
429
429
 
430
430
  ## Public forms
431
431
 
432
- A contact form or a sign-up is `defineForm({ action: 'Contact.send' })` in
433
- TypeScript: the fields come from the `FormRequest` on that method, with no schema
434
- to write. What the rules refuse shows under each field. [Public forms](/guides/public-forms#laravel) has the
435
- code.
432
+ A contact form or a sign-up anyone may fill in is declared in three places: the
433
+ rules in a `FormRequest`, the action that takes it, and a few lines of
434
+ TypeScript handing that action to a form. `php artisan make:rsc-action Contact --method=send
435
+ --form` writes all three, as below, for you to fill in (`rsc-kit/laravel`
436
+ 0.18). There is no schema to write: the fields and the browser's
437
+ checks are read from `rules()`.
438
+
439
+ **1. The rules.** `php artisan make:request SendContact`, and let anyone send it:
440
+
441
+ ```php title="app/Http/Requests/SendContact.php"
442
+ namespace App\Http\Requests;
443
+
444
+ use Illuminate\Foundation\Http\FormRequest;
445
+
446
+ class SendContact extends FormRequest
447
+ {
448
+ public function authorize(): bool
449
+ {
450
+ return true; // make:request writes false, which refuses everyone
451
+ }
452
+
453
+ public function rules(): array
454
+ {
455
+ return [
456
+ 'name' => ['required', 'string', 'min:2'],
457
+ 'email' => ['required', 'email', 'unique:subscribers,email'],
458
+ 'topic' => ['required', 'in:sales,support'],
459
+ 'message' => ['required', 'string', 'min:10', 'max:2000'],
460
+ ];
461
+ }
462
+ }
463
+ ```
464
+
465
+ **2. The action.** Under `app/Rsc/Actions`, taking the request alone:
466
+
467
+ ```php title="app/Rsc/Actions/Contact.php"
468
+ namespace App\Rsc\Actions;
469
+
470
+ use App\Http\Requests\SendContact;
471
+ use App\Models\Message;
472
+
473
+ class Contact
474
+ {
475
+ public function send(SendContact $request): void
476
+ {
477
+ Message::create($request->validated());
478
+ }
479
+ }
480
+ ```
481
+
482
+ **3. The form.** The build generates `contactSend` from the method, and
483
+ `bunx rsc-kit make:form contactSend` writes the form around it:
484
+
485
+ ```ts title="resources/js/forms/contact.ts"
486
+ import { defineForm } from '@rsc-kit/press/forms'
487
+ import { shadcn } from '@rsc-kit/press/shadcn'
488
+ import { contactSend } from '../server-actions.generated'
489
+
490
+ export const contact = defineForm({
491
+ name: 'contact',
492
+ action: contactSend,
493
+ fields: { message: { type: 'textarea' } },
494
+ theme: shadcn,
495
+ done: 'Thanks - we will be in touch.',
496
+ })
497
+ ```
498
+
499
+ Then place it in a page, which stays static:
500
+
501
+ ```tsx title="resources/js/app/contact/page.tsx"
502
+ import { contact } from '../../forms/contact'
503
+
504
+ export default function ContactPage() {
505
+ return <contact.Form />
506
+ }
507
+ ```
508
+
509
+ The fields are drawn in the order of `rules()`. `email`, `url`, `date`, `min`,
510
+ `max`, `size` and `between` become the browser's checks, and `in` or `Rule::in()`
511
+ draws a select. Everything else, `unique` included, is checked by Laravel alone:
512
+ its 422 shows under the field, with what was typed kept. A field named in
513
+ `fields` that `rules()` does not have fails the typecheck.
514
+
515
+ A file field, or a check in TypeScript first, needs a schema and a `handle`
516
+ instead. [Public forms](/guides/public-forms#laravel) has the rest. `action`
517
+ taking the generated action, and `rsc-kit make:form`, need `@rsc-kit/press`
518
+ 0.30.49, and the browser's checks from `rules()` need
519
+ `rsc-kit/laravel` 0.17; an older package draws the fields with `required` and
520
+ their types only.
436
521
 
437
522
  ## Route middleware
438
523
 
@@ -445,7 +530,21 @@ export const middleware = ['auth', 'verified', 'can:update,post']
445
530
  ```
446
531
 
447
532
  Before anything at or below that directory renders, the names are sent to
448
- PHP and run through the real pipeline against the real request. It fails
533
+ PHP with the page they guard, and run through the real pipeline against that
534
+ page's request: its url, its route parameters, the visitor's address, cookie
535
+ and session. So the vocabulary means what it does in `routes/web.php`:
536
+
537
+ - `signed` checks the link the visitor followed. `signed:relative` too.
538
+ - `throttle:5,1` counts per visitor, and once per page load.
539
+ - `can:update,post` gets a `post`: the `{post}` the route bound, through
540
+ `Route::bind` or `Route::model` in a service provider. Implicit binding
541
+ needs a controller signature to read, and a page has none, so bind the names
542
+ your guards use explicitly. Without a binding the ability receives the
543
+ string.
544
+ - `request()` and the `Request` a middleware is handed are the page's, not the
545
+ host call's.
546
+
547
+ It fails
449
548
  closed: anything that is not a literal `true` is a refusal, so a middleware
450
549
  that aborts, redirects or simply errors keeps the page from rendering rather
451
550
  than being read as silence. A page frozen at build time is asked too, before
@@ -534,11 +633,12 @@ redirects to come out against the public origin rather than its own.
534
633
 
535
634
  Trusting it means trusting what it forwards, so the renderer drops any
536
635
  `X-Forwarded-For`, `Forwarded` or `X-Real-IP` the browser sent: otherwise a
537
- visitor would pick their own address for Laravel's throttles. The renderer
538
- cannot see the peer address to put in its place, so Laravel sees the
539
- renderer's. If the renderer sits behind a proxy of its own that writes those
540
- headers (a load balancer, Cloudflare), set `RSC_TRUST_FORWARDED=1` on the
541
- renderer and they are passed through.
636
+ visitor would pick their own address for Laravel's throttles. It sends the
637
+ address it accepted the page request from instead, and the package makes that
638
+ `$request->ip()` once the secret matches, whatever `trustProxies` says. If the
639
+ renderer sits behind a proxy of its own that writes those headers (a load
640
+ balancer, Cloudflare), set `RSC_TRUST_FORWARDED=1` on the renderer and the
641
+ first hop is the visitor's address.
542
642
 
543
643
  Setting `RSC_RENDERER_URL` puts Laravel in front instead: it proxies anything
544
644
  it does not route, which is what development does. In production it has the
@@ -7,6 +7,10 @@ It is the panel's form without the panel: the same fields read from the same
7
7
  schema, the same browser checks, the same refusals under the same fields - and
8
8
  a [theme](/guides/admin/#themes) to draw it. The `shadcn` theme draws both.
9
9
 
10
+ On a Laravel or Go backend there is no schema to write: name the backend's
11
+ function, and the form is drawn from what it takes. See
12
+ [A Laravel or Go backend](#a-laravel-or-go-backend).
13
+
10
14
  ```ts title="src/forms/contact.ts"
11
15
  import * as z from 'zod'
12
16
  import { defineForm } from '@rsc-kit/press/forms'
@@ -74,17 +78,19 @@ handle: async ({ email }) => {
74
78
 
75
79
  ## A Laravel or Go backend
76
80
 
77
- Name the function, and the form needs no schema of its own. The backend already
78
- says what the function takes, so the fields and the browser's checks come from
79
- there, and every check that counts is the backend's:
81
+ Give it the backend's action, and the form needs no schema of its own. The
82
+ backend already says what the action takes, so the fields and the browser's
83
+ checks come from there, and every check that counts is the backend's. The
84
+ action is the one the build generated, imported like any other:
80
85
 
81
86
  ```ts title="resources/js/forms/contact.ts"
82
87
  import { defineForm } from '@rsc-kit/press/forms'
83
88
  import { shadcn } from '@rsc-kit/press/shadcn'
89
+ import { contactSend } from '../server-actions.generated'
84
90
 
85
91
  export const contact = defineForm({
86
92
  name: 'contact',
87
- action: 'Contact.send',
93
+ action: contactSend,
88
94
  fields: { message: { type: 'textarea' } },
89
95
  theme: shadcn,
90
96
  submit: 'Send message',
@@ -92,14 +98,18 @@ export const contact = defineForm({
92
98
  })
93
99
  ```
94
100
 
95
- `action` is typed from the backend's functions, so a misspelt name fails the
96
- typecheck. `fields` still sets a label or a control, and the bot trap, `done`
101
+ You need not write it: `bunx rsc-kit make:form contactSend` writes this file
102
+ from the action, and it is yours to edit from then on.
103
+
104
+ An action that is not there fails the import, and a field `fields` names that
105
+ the action does not take fails the typecheck. `fields` still sets a label or a control, and the bot trap, `done`
97
106
  and `redirect` work as on any form. There is no `handle`: the values go to the
98
107
  function. Nothing reaches the browser but the form, and no validation library
99
108
  is added to the server.
100
109
 
101
- The function must take one object with named fields: a `FormRequest` in Laravel,
102
- a struct in Go. A form calling anything else says so when it first renders. So
110
+ The action must take one object with named fields: a `FormRequest` in Laravel,
111
+ a struct in Go. A form given anything else says so when it first renders, as
112
+ does one given a function the build did not generate. So
103
113
  does a field it cannot draw, such as a file: an action's values travel as JSON,
104
114
  so an upload needs `form` and `handle`. Give an open-typed field a control in
105
115
  `fields`.
@@ -109,7 +119,7 @@ a schema and call the backend yourself:
109
119
 
110
120
  ```ts
111
121
  form: z.object({ email: z.email() }),
112
- handle: (values) => rpc('Contact.send', values),
122
+ handle: (values) => contactSend(values),
113
123
  ```
114
124
 
115
125
  The schema's checks then run first, so a submission it refuses never reaches the
@@ -147,8 +157,8 @@ class SendContact extends FormRequest
147
157
  }
148
158
  ```
149
159
 
150
- ```php title="app/Rsc/Contact.php"
151
- namespace App\Rsc;
160
+ ```php title="app/Rsc/Actions/Contact.php"
161
+ namespace App\Rsc\Actions;
152
162
 
153
163
  use App\Http\Requests\SendContact;
154
164
  use App\Models\Message;
@@ -167,8 +177,8 @@ and call `Validator::make($values, [...])->validate()`, or throw
167
177
  `ValidationException::withMessages(['email' => 'That address is blocked.'])`.
168
178
  Either lands the same way.
169
179
 
170
- Keep the class under `app/Rsc`, and `action` and `rpc('Contact.send', ...)` are
171
- typed from it at the next build.
180
+ Keep the class under `app/Rsc/Actions`, where every public method is an action:
181
+ `Contact::send` is `contactSend`, generated at the next build.
172
182
 
173
183
  The form's fields are read from `rules()`, in order, at build time: `required`,
174
184
  the type rules, `email`, `url`, `date`, `min`, `max`, `size`, `between`, and
@@ -182,7 +192,7 @@ unstyled until the app has both.
182
192
 
183
193
  ### Go
184
194
 
185
- Register a function that takes the values as a struct. Its `json` tags are the
195
+ Register an action that takes the values as a struct. Its `json` tags are the
186
196
  form's field names, and `rsckit.InvalidField` or `rsckit.Invalid` is the 422.
187
197
 
188
198
  ```go
@@ -192,7 +202,7 @@ type ContactInput struct {
192
202
  Message string `json:"message"`
193
203
  }
194
204
 
195
- reg.Handle("Contact.send", func(ctx context.Context, in ContactInput) error {
205
+ reg.HandleAction("contactSend", "Contact.send", func(ctx context.Context, in ContactInput) error {
196
206
  if blocked(in.Email) {
197
207
  return rsckit.InvalidField("email", "That address is blocked.")
198
208
  }
@@ -210,8 +220,8 @@ return rsckit.Invalid(map[string][]string{
210
220
  })
211
221
  ```
212
222
 
213
- `reg.WriteManifest("rsc-host.json")` types `action` and `rpc('Contact.send', ...)`
214
- for the app, as with any function.
223
+ `reg.WriteManifest("rsc-host.json")` puts it in the manifest, and the build
224
+ generates `contactSend` from it, as for any action.
215
225
 
216
226
  The form's fields are the struct's, in its order, and a field is required unless
217
227
  its `json` tag says `omitempty`. A `validate` tag, in go-playground/validator's
@@ -255,11 +265,11 @@ dropped - `handle` never sees it, and the bot learns nothing. It is a filter
255
265
  for the crudest spam, not a CAPTCHA; a form worth attacking wants rate
256
266
  limiting as well.
257
267
 
258
- Put that in front of the app, at the CDN or the proxy, where the visitor's
259
- address is known. A backend sees the renderer's address on an `rpc()`, not the
260
- visitor's, so `throttle:5,1` on a Laravel method puts every logged-out visitor
261
- in one bucket. To limit in the backend, key on something the submission carries,
262
- such as the email address.
268
+ A backend is told the visitor's address on every call, so `throttle:5,1` on
269
+ the action limits each visitor on their own - `$request->ip()` in Laravel,
270
+ `rsckit.ClientIP(ctx)` in Go. Behind a load balancer or Cloudflare, set
271
+ `RSC_TRUST_FORWARDED=1` on the renderer, or every visitor arrives as the
272
+ balancer. Limiting at the CDN as well spares the backend the work.
263
273
 
264
274
  The trap is named `homepage`, so a form cannot have a field of that name.
265
275
 
@@ -54,6 +54,7 @@ Content-Type: application/json
54
54
  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
+ X-Rsc-Client-Ip: <the visitor's address, as the renderer's server saw it>
57
58
 
58
59
  { "function": "Orders.recent", "args": [5] }
59
60
  ```
@@ -66,6 +67,15 @@ run *as the visitor*: your session middleware reads the cookie and finds the
66
67
  same person the page is being rendered for. During a build there is no
67
68
  visitor and the headers are absent.
68
69
 
70
+ **`X-Rsc-Client-Ip` is the visitor's address**, not the renderer's: the peer
71
+ the renderer's server accepted the page request from, or the first hop of
72
+ `X-Forwarded-For` when the renderer runs with `RSC_TRUST_FORWARDED=1` behind a
73
+ proxy of its own. Believe it only once the secret matches - before that,
74
+ anybody can send it - and then in place of the connection's address, which is
75
+ the renderer's and the same for every visitor. A throttle keyed on that puts
76
+ everyone in one bucket. Absent when there is no visitor: a build, or a page
77
+ stored for everyone.
78
+
69
79
  **Arguments that do not fit the function are a failure, not a refusal.**
70
80
  Too few, or a value your language cannot decode into the parameter's type:
71
81
  answer 500 with `error`, as Go and Laravel do. The renderer's calls are typed
@@ -221,9 +231,28 @@ directory renders — including a page frozen at build time, before the file is
221
231
  served — it calls the reserved function with the list:
222
232
 
223
233
  ```json
224
- { "function": "__rsc.middleware", "args": [["auth", "can:manage-users"]] }
234
+ {
235
+ "function": "__rsc.middleware",
236
+ "args": [
237
+ ["auth", "can:manage-users"],
238
+ { "url": "https://app.example.com/users/7/edit?tab=roles", "params": { "user": "7" } }
239
+ ]
240
+ }
225
241
  ```
226
242
 
243
+ The second argument is **the page being asked about**, because the call is
244
+ not it: a guard run against the POST to `/__rsc/host-call` checks a signature
245
+ on the endpoint's url, and finds no `{user}` to authorize against. `url` is
246
+ what the visitor asked for, under the public host and scheme when a proxy
247
+ forwarded them, or `null` during a build. `params` holds only the values the
248
+ route's own segments bound - never the query, so `?user=8` cannot stand in for
249
+ `{user}` - with a catch-all's parts joined by `/`. Run the guards as if that
250
+ were the request. A backend that ignores the argument still works for guards
251
+ that read only the session.
252
+
253
+ One request asks once. A page the renderer looks for in its store and then
254
+ renders is still one visit to the guards, so a throttle counts it once.
255
+
227
256
  Answer `{ "result": true }` to let the render go ahead. **Anything else is a
228
257
  refusal**: `false`, `null`, a string, an object, a 4xx, a connection error.
229
258
  The engine reads the literal `true` and nothing else, so a guard that aborts,
@@ -425,9 +454,12 @@ ordinary API, the way an app would write them:
425
454
  | `Conformance.flash` | leave the one-time message `"Saved."` (`"success"`) for the next page, after any the visitor's `rsc-flash` cookie still carries, and return `"ok"` |
426
455
  | `Conformance.change` | say `conformance:changed` changed, as your webhook would, and return `"ok"` |
427
456
 
428
- And three guards: `conformance-allow`, which passes, `conformance-deny`, which
429
- refuses, and `conformance-redirect`, which sends the visitor to
430
- `/conformance-login`. Then serve them and run:
457
+ Then `Conformance.ip`, returning the visitor's address as your request
458
+ reports it. And four guards: `conformance-allow`, which passes,
459
+ `conformance-deny`, which refuses, `conformance-redirect`, which sends the
460
+ visitor to `/conformance-login`, and `conformance-page`, which passes only when
461
+ the page it is asked about is `/conformance/orders/7` with `{order}` bound to
462
+ `"7"`. Then serve them and run:
431
463
 
432
464
  Start it with `HOMEPORT_PURGE_URL=http://127.0.0.1:8790/`, where the suite
433
465
  listens for its purges, then:
@@ -449,13 +481,15 @@ It checks the whole contract on this page:
449
481
  failing rather than refusing;
450
482
  - **forms** - a function taking one object, its fields in order with the hints
451
483
  a browser can check, and a refusal landing on its field;
452
- - **the request** - `Cookie` and `Authorization` forwarded, a cookie set by a
484
+ - **the request** - `Cookie` and `Authorization` forwarded, the visitor's
485
+ address in place of the renderer's, a cookie set by a
453
486
  call reaching the page, no secret or the wrong one refused with 403, an
454
487
  unknown function 404, a malformed body 400;
455
488
  - **batches** - every call answered, a refusal only its own, and more than 50
456
489
  refused with 413 before any runs;
457
490
  - **guards** - in the order named, stopping at the first that does not pass,
458
- a redirect from one, and a name nobody registered refusing;
491
+ a redirect from one, a name nobody registered refusing, and a guard reading
492
+ the page it is asked about rather than the call;
459
493
  - **live data** - a name never changed at 0, a change moving it to a time in
460
494
  milliseconds that never comes round again, only the names that differ
461
495
  answered, and a held call bounded by `wait`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsc-kit/mcp",
3
- "version": "0.30.48",
3
+ "version": "0.30.50",
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.30.48",
37
+ "create-rsc-kit": "^0.30.50",
38
38
  "zod": "^3.25"
39
39
  },
40
40
  "devDependencies": {