@rsc-kit/mcp 0.30.49 → 0.30.51

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/admin.md CHANGED
@@ -132,6 +132,44 @@ const customersSource: DataSource<Customer, Values> = {
132
132
  }
133
133
  ```
134
134
 
135
+ ### Pages by count, or by cursor
136
+
137
+ A list answers its page one of two ways, and the table pages to match:
138
+
139
+ - `{ rows, total }` - counted. The table says how many, and numbers its pages.
140
+ - `{ rows, next, prev }` - by cursor. The table has Previous and Next, each a
141
+ link to the list with `?cursor=` set to the one the source handed out, and
142
+ says nothing of how many. `null` is no page that way.
143
+
144
+ A cursor suits a table too big to count, or a query that is cheap only by key -
145
+ Laravel's `cursorPaginate`, a keyset query, an API that hands back a cursor.
146
+ The source is told the one it gave as `query.cursor`, absent on the first page,
147
+ and reads that rather than `page`. A search, a filter or a sort starts again from
148
+ the first page; paging keeps them.
149
+
150
+ ```ts
151
+ list: async (query) => {
152
+ const page = await rpc('Orders.list', query)
153
+
154
+ return { rows: page.data as Order[], next: page.next_cursor, prev: page.prev_cursor }
155
+ },
156
+ ```
157
+
158
+ ```php title="app/Rsc/Orders.php"
159
+ public function list(array $query): CursorPaginator
160
+ {
161
+ return Order::latest('id')->cursorPaginate($query['perPage'], cursor: $query['cursor'] ?? null);
162
+ }
163
+ ```
164
+
165
+ A method returning a paginator is typed as Laravel encodes it - `data`,
166
+ `next_cursor` and `prev_cursor` from `cursorPaginate`, `data` and `total` from
167
+ `paginate`, which is `{ rows: page.data as Order[], total: page.total }` - with
168
+ its rows unknown, which the cast names (`rsc-kit/laravel` 0.19).
169
+
170
+ Each resource chooses for itself, so one panel can have both. The dashboard
171
+ shows a dash for a resource it cannot count.
172
+
135
173
  A save says "Product saved." on the list it lands on, and a delete says
136
174
  "Product deleted." in place, as a toast. Both use
137
175
  [`flash()`](/guides/server-actions#a-message-for-the-next-page).
@@ -168,6 +206,54 @@ and its messages show under the same fields as the schema's, with the form's
168
206
  values kept. Nothing to catch: the panel treats the backend's refusal and its
169
207
  own the same way.
170
208
 
209
+ ### The backend's actions as the form
210
+
211
+ When the backend already says what a record takes - a FormRequest, a Go struct
212
+ with `validate` tags - the resource needs no schema of its own. Give it the
213
+ backend's generated actions instead of `form`, and the source keeps only
214
+ `list`, `find` and `delete`:
215
+
216
+ ```ts title="src/admin/resources/products.ts"
217
+ import { productsStore, productsUpdate } from '@/actions/products'
218
+
219
+ export const products = defineResource<Product>()({
220
+ name: 'products',
221
+ key: 'id',
222
+ title: 'name',
223
+ source: { list: (q) => rpc('Products.list', q), find: (id) => rpc('Products.find', id), delete: (id) => rpc('Products.delete', id) },
224
+ actions: { create: productsStore, update: productsUpdate },
225
+ fields: { category_id: { relation: 'categories' } },
226
+ table: (col) => [col.text('name'), col.money('price')],
227
+ })
228
+ ```
229
+
230
+ The create form is drawn from what `create` takes, and the edit form from what
231
+ `update` takes, so a password required on one can be optional on the other.
232
+ `fields` names the backend's fields - a misspelt one fails the typecheck - and
233
+ adds what the rules cannot say, such as a relation. `create` is called with the
234
+ values; `update` with the values, then the record's key:
235
+
236
+ ```php title="app/Rsc/Actions/Products.php"
237
+ public function update(UpdateProductRequest $request, string $product): Product
238
+ {
239
+ return tap(Product::findOrFail($product))->update($request->validated());
240
+ }
241
+ ```
242
+
243
+ ```php title="app/Http/Requests/UpdateProductRequest.php"
244
+ 'sku' => ['required', Rule::unique('products')->ignore($this->route('product'))],
245
+ ```
246
+
247
+ The key reaches the FormRequest as its route parameter, under the method's own
248
+ name for it, so a unique rule ignores the record being edited as it would on
249
+ `PUT /products/{product}` - and `Route::model()` binds it. In Go the update is
250
+ `func(ctx context.Context, in ProductInput, id string)`. An update that takes
251
+ only the values is refused at startup, since it could not be told which
252
+ record, and so is a `create` that takes a key.
253
+
254
+ The backend does every check. The panel still refuses a relation the visitor
255
+ cannot see before the backend is asked.
256
+
171
257
  ### Choices that read as words
172
258
 
173
259
  An enum's options are shown humanized - `'in_stock'` reads "In stock" in the
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
@@ -305,6 +331,14 @@ arguments you bound. An action scoped to a team, `func(ctx, team string, in NewA
305
331
  is `<Form action={appsCreate.bind(null, team)}>`. Numbers and booleans are
306
332
  coerced by the struct's types and a repeated field is a slice.
307
333
 
334
+ An admin resource takes the generated actions in place of a schema, its create
335
+ `func(ctx, in ProductInput)` and its update the record's key after the struct,
336
+ `func(ctx, in ProductInput, id string)`. See
337
+ [the admin guide](/guides/admin#the-backends-actions-as-the-form). A list too
338
+ big to count pages by cursor: answer a struct tagged `json:"rows"`,
339
+ `json:"next"` and `json:"prev"`, and read the cursor from the query's `cursor`
340
+ ([pages by count, or by cursor](/guides/admin#pages-by-count-or-by-cursor)).
341
+
308
342
  `Revalidate` names a [section](/guides/sections) or `page`, and the answer to
309
343
  the action carries it re-rendered rather than the browser being told to ask
310
344
  again.
package/guides/laravel.md CHANGED
@@ -431,7 +431,9 @@ purges the CDN as well, after the transaction commits and the response has gone.
431
431
 
432
432
  A contact form or a sign-up anyone may fill in is declared in three places: the
433
433
  rules in a `FormRequest`, the action that takes it, and a few lines of
434
- TypeScript handing that action to a form. There is no schema to write: the fields and the browser's
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
435
437
  checks are read from `rules()`.
436
438
 
437
439
  **1. The rules.** `php artisan make:request SendContact`, and let anyone send it:
@@ -517,6 +519,14 @@ taking the generated action, and `rsc-kit make:form`, need `@rsc-kit/press`
517
519
  `rsc-kit/laravel` 0.17; an older package draws the fields with `required` and
518
520
  their types only.
519
521
 
522
+ An admin resource takes the same generated actions in place of a schema, and
523
+ its update takes the record's key after the request:
524
+ `update(UpdateProductRequest $request, string $product)`. The key is the
525
+ request's route parameter under that name, so
526
+ `Rule::unique('products')->ignore($this->route('product'))` keeps the record's
527
+ own value. [The admin guide](/guides/admin#the-backends-actions-as-the-form)
528
+ has it; it needs `@rsc-kit/press` 0.30.51 and `rsc-kit/laravel` 0.19.
529
+
520
530
  ## Route middleware
521
531
 
522
532
  The renderer owns the route table, but Laravel still decides whether a route
@@ -528,7 +538,21 @@ export const middleware = ['auth', 'verified', 'can:update,post']
528
538
  ```
529
539
 
530
540
  Before anything at or below that directory renders, the names are sent to
531
- PHP and run through the real pipeline against the real request. It fails
541
+ PHP with the page they guard, and run through the real pipeline against that
542
+ page's request: its url, its route parameters, the visitor's address, cookie
543
+ and session. So the vocabulary means what it does in `routes/web.php`:
544
+
545
+ - `signed` checks the link the visitor followed. `signed:relative` too.
546
+ - `throttle:5,1` counts per visitor, and once per page load.
547
+ - `can:update,post` gets a `post`: the `{post}` the route bound, through
548
+ `Route::bind` or `Route::model` in a service provider. Implicit binding
549
+ needs a controller signature to read, and a page has none, so bind the names
550
+ your guards use explicitly. Without a binding the ability receives the
551
+ string.
552
+ - `request()` and the `Request` a middleware is handed are the page's, not the
553
+ host call's.
554
+
555
+ It fails
532
556
  closed: anything that is not a literal `true` is a refusal, so a middleware
533
557
  that aborts, redirects or simply errors keeps the page from rendering rather
534
558
  than being read as silence. A page frozen at build time is asked too, before
@@ -617,11 +641,12 @@ redirects to come out against the public origin rather than its own.
617
641
 
618
642
  Trusting it means trusting what it forwards, so the renderer drops any
619
643
  `X-Forwarded-For`, `Forwarded` or `X-Real-IP` the browser sent: otherwise a
620
- visitor would pick their own address for Laravel's throttles. The renderer
621
- cannot see the peer address to put in its place, so Laravel sees the
622
- renderer's. If the renderer sits behind a proxy of its own that writes those
623
- headers (a load balancer, Cloudflare), set `RSC_TRUST_FORWARDED=1` on the
624
- renderer and they are passed through.
644
+ visitor would pick their own address for Laravel's throttles. It sends the
645
+ address it accepted the page request from instead, and the package makes that
646
+ `$request->ip()` once the secret matches, whatever `trustProxies` says. If the
647
+ renderer sits behind a proxy of its own that writes those headers (a load
648
+ balancer, Cloudflare), set `RSC_TRUST_FORWARDED=1` on the renderer and the
649
+ first hop is the visitor's address.
625
650
 
626
651
  Setting `RSC_RENDERER_URL` puts Laravel in front instead: it proxies anything
627
652
  it does not route, which is what development does. In production it has the
@@ -265,11 +265,11 @@ dropped - `handle` never sees it, and the bot learns nothing. It is a filter
265
265
  for the crudest spam, not a CAPTCHA; a form worth attacking wants rate
266
266
  limiting as well.
267
267
 
268
- Put that in front of the app, at the CDN or the proxy, where the visitor's
269
- address is known. A backend sees the renderer's address on an `rpc()`, not the
270
- visitor's, so `throttle:5,1` on a Laravel method puts every logged-out visitor
271
- in one bucket. To limit in the backend, key on something the submission carries,
272
- 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.
273
273
 
274
274
  The trap is named `homepage`, so a form cannot have a field of that name.
275
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.49",
3
+ "version": "0.30.51",
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.49",
37
+ "create-rsc-kit": "^0.30.51",
38
38
  "zod": "^3.25"
39
39
  },
40
40
  "devDependencies": {