@rsc-kit/mcp 0.30.48 → 0.30.49

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
@@ -400,10 +400,64 @@ well; `reg.SetPurger` replaces it. Call it after your transaction commits.
400
400
 
401
401
  ## Public forms
402
402
 
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.
403
+ A contact form or a sign-up anyone may fill in is an action that takes a
404
+ struct, and a few lines of TypeScript handing that action to a form. There is
405
+ no schema to write: the fields and the browser's checks come from the struct.
406
+
407
+ **1. The action.** Its `json` tags are the field names, a `validate` tag adds
408
+ what the browser can check, and `rsckit.InvalidField` is a refusal under that
409
+ field:
410
+
411
+ ```go
412
+ type ContactInput struct {
413
+ Name string `json:"name" validate:"required,min=2"`
414
+ Email string `json:"email" validate:"required,email"`
415
+ Topic string `json:"topic" validate:"required,oneof=sales support"`
416
+ Message string `json:"message" validate:"required,min=10,max=2000"`
417
+ }
418
+
419
+ reg.HandleAction("contactSend", "Contact.send", func(ctx context.Context, in ContactInput) error {
420
+ if blocked(in.Email) {
421
+ return rsckit.InvalidField("email", "That address is blocked.")
422
+ }
423
+
424
+ return messages.Insert(ctx, in)
425
+ })
426
+ ```
427
+
428
+ The tag is read, never run: check what was sent in the function too, since a
429
+ post need not come from a browser.
430
+
431
+ **2. The form.** The build generates `contactSend` from the manifest, and
432
+ `bunx rsc-kit make:form contactSend` writes the form around it:
433
+
434
+ ```ts title="src/forms/contact.ts"
435
+ import { defineForm } from '@rsc-kit/press/forms'
436
+ import { shadcn } from '@rsc-kit/press/shadcn'
437
+ import { contactSend } from '../server-actions.generated'
438
+
439
+ export const contact = defineForm({
440
+ name: 'contact',
441
+ action: contactSend,
442
+ fields: { message: { type: 'textarea' } },
443
+ theme: shadcn,
444
+ done: 'Thanks - we will be in touch.',
445
+ })
446
+ ```
447
+
448
+ Then place it in a page, which stays static:
449
+
450
+ ```tsx title="src/app/contact/page.tsx"
451
+ import { contact } from '../../forms/contact'
452
+
453
+ export default function ContactPage() {
454
+ return <contact.Form />
455
+ }
456
+ ```
457
+
458
+ `oneof` draws a select, and a field is required unless its `json` tag says
459
+ `omitempty`. [Public forms](/guides/public-forms#go) has every tag that is read.
460
+ It needs `@rsc-kit/press` 0.30.49 and `github.com/rsc-kit/go` v0.14.0.
407
461
 
408
462
  ## Production
409
463
 
package/guides/laravel.md CHANGED
@@ -429,10 +429,93 @@ 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. There is no schema to write: the fields and the browser's
435
+ checks are read from `rules()`.
436
+
437
+ **1. The rules.** `php artisan make:request SendContact`, and let anyone send it:
438
+
439
+ ```php title="app/Http/Requests/SendContact.php"
440
+ namespace App\Http\Requests;
441
+
442
+ use Illuminate\Foundation\Http\FormRequest;
443
+
444
+ class SendContact extends FormRequest
445
+ {
446
+ public function authorize(): bool
447
+ {
448
+ return true; // make:request writes false, which refuses everyone
449
+ }
450
+
451
+ public function rules(): array
452
+ {
453
+ return [
454
+ 'name' => ['required', 'string', 'min:2'],
455
+ 'email' => ['required', 'email', 'unique:subscribers,email'],
456
+ 'topic' => ['required', 'in:sales,support'],
457
+ 'message' => ['required', 'string', 'min:10', 'max:2000'],
458
+ ];
459
+ }
460
+ }
461
+ ```
462
+
463
+ **2. The action.** Under `app/Rsc/Actions`, taking the request alone:
464
+
465
+ ```php title="app/Rsc/Actions/Contact.php"
466
+ namespace App\Rsc\Actions;
467
+
468
+ use App\Http\Requests\SendContact;
469
+ use App\Models\Message;
470
+
471
+ class Contact
472
+ {
473
+ public function send(SendContact $request): void
474
+ {
475
+ Message::create($request->validated());
476
+ }
477
+ }
478
+ ```
479
+
480
+ **3. The form.** The build generates `contactSend` from the method, and
481
+ `bunx rsc-kit make:form contactSend` writes the form around it:
482
+
483
+ ```ts title="resources/js/forms/contact.ts"
484
+ import { defineForm } from '@rsc-kit/press/forms'
485
+ import { shadcn } from '@rsc-kit/press/shadcn'
486
+ import { contactSend } from '../server-actions.generated'
487
+
488
+ export const contact = defineForm({
489
+ name: 'contact',
490
+ action: contactSend,
491
+ fields: { message: { type: 'textarea' } },
492
+ theme: shadcn,
493
+ done: 'Thanks - we will be in touch.',
494
+ })
495
+ ```
496
+
497
+ Then place it in a page, which stays static:
498
+
499
+ ```tsx title="resources/js/app/contact/page.tsx"
500
+ import { contact } from '../../forms/contact'
501
+
502
+ export default function ContactPage() {
503
+ return <contact.Form />
504
+ }
505
+ ```
506
+
507
+ The fields are drawn in the order of `rules()`. `email`, `url`, `date`, `min`,
508
+ `max`, `size` and `between` become the browser's checks, and `in` or `Rule::in()`
509
+ draws a select. Everything else, `unique` included, is checked by Laravel alone:
510
+ its 422 shows under the field, with what was typed kept. A field named in
511
+ `fields` that `rules()` does not have fails the typecheck.
512
+
513
+ A file field, or a check in TypeScript first, needs a schema and a `handle`
514
+ instead. [Public forms](/guides/public-forms#laravel) has the rest. `action`
515
+ taking the generated action, and `rsc-kit make:form`, need `@rsc-kit/press`
516
+ 0.30.49, and the browser's checks from `rules()` need
517
+ `rsc-kit/laravel` 0.17; an older package draws the fields with `required` and
518
+ their types only.
436
519
 
437
520
  ## Route middleware
438
521
 
@@ -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
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.49",
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.49",
38
38
  "zod": "^3.25"
39
39
  },
40
40
  "devDependencies": {