@rsc-kit/mcp 0.46.1 → 0.48.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.
@@ -60,7 +60,7 @@ renders can be, and that one is fine.
60
60
  | `next/image` | [unpic](/guides/images) for a CDN, `vite-imagetools` for files in the repo |
61
61
  | `next/script` | [a `<script>` tag](/guides/third-party-scripts): React 19 hoists and dedupes `async` scripts itself |
62
62
  | `NEXT_PUBLIC_*` | `VITE_*`, read through `import.meta.env`; everything else stays `process.env` on the server |
63
- | `flags/next` (Vercel's Flags SDK) | unchanged — the build answers its `next/headers` import with `headers()` and `cookies()` from here; [Feature flags](/guides/feature-flags) |
63
+ | `flags/next` (Vercel's Flags SDK) | [OpenFeature](/guides/feature-flags): `@openfeature/server-sdk`, its evaluation context built from `cookies()`; Pennant on Laravel |
64
64
  | `next.config.js` | `vite.config.ts` — Tailwind, aliases and plugins are Vite's |
65
65
  | `serverExternalPackages` | `rscKit({ serverExternalPackages })`, with the same default list — sharp, bcrypt, prisma and the rest stay outside the bundle; [Running on Bun](/hosts/bun#native-dependencies-stay-outside-the-bundle) |
66
66
  | `instrumentation.ts` with `register()` | the same file, in `src/` — imported before any page and awaited before the first request; [startup](/guides/instrumentation) |
@@ -1,145 +1,231 @@
1
1
  # Feature flags
2
2
 
3
- > Vercel's Flags SDK runs unchanged — flags/next, without Next.
3
+ > OpenFeature in a server component, Pennant on Laravel, the OpenFeature Go SDK on Go.
4
4
 
5
- Use the [Flags SDK](https://flags-sdk.dev) as its docs show it. Its Next
6
- integration, `flags/next`, works here without Next, so there is nothing to
7
- install from rsc-kit:
5
+ Read a flag in a server component and render from it. In a JavaScript app, use
6
+ [OpenFeature](https://openfeature.dev), the vendor-neutral flag standard. It
7
+ runs the same on Bun, Node and Workers, and the service that holds your flags
8
+ plugs in as a provider. With a backend, use the backend's own: Laravel
9
+ [Pennant](#laravel-pennant), or [OpenFeature's Go SDK](#go).
8
10
 
9
11
  ```sh
10
- bun add flags
12
+ bun add @openfeature/server-sdk @openfeature/core
11
13
  ```
12
14
 
13
- ```ts title="src/flags.ts"
14
- import { flag } from 'flags/next'
15
+ ```ts title="src/server/flags.ts"
16
+ import { cache } from 'react'
17
+ import { OpenFeature, InMemoryProvider } from '@openfeature/server-sdk'
15
18
 
16
- export const showBanner = flag<boolean>({
17
- key: 'show-banner',
18
- decide: () => false,
19
- })
19
+ await OpenFeature.setProviderAndWait(
20
+ new InMemoryProvider({
21
+ 'new-banner': {
22
+ variants: { on: true, off: false },
23
+ defaultVariant: 'off',
24
+ disabled: false,
25
+ },
26
+ }),
27
+ )
28
+
29
+ const client = OpenFeature.getClient()
30
+
31
+ export const newBanner = cache(() => client.getBooleanValue('new-banner', false))
20
32
  ```
21
33
 
22
34
  ```tsx title="src/app/page.tsx"
23
- import { showBanner } from '../flags'
35
+ import { newBanner } from '../server/flags'
24
36
 
25
37
  export default async function Home() {
26
- return (await showBanner()) ? <Banner /> : null
38
+ return (await newBanner()) ? <Banner /> : null
27
39
  }
28
40
  ```
29
41
 
30
- ## Deciding per visitor
31
-
32
- A flag usually depends on who is asking. `identify` reads the request, and
33
- `dedupe` makes it run once per request however many flags use it:
34
-
35
- ```ts title="src/flags.ts"
36
- import { flag, dedupe } from 'flags/next'
42
+ React's `cache()` evaluates a flag once per render, however many components
43
+ ask for it. A flag that is the same for everyone doesn't read the request, so
44
+ the page is stored at build like any other.
37
45
 
38
- type Visitor = { id: string; country: string }
46
+ ## Deciding per visitor
39
47
 
40
- const visitor = dedupe(async ({ cookies, headers }): Promise<Visitor> => ({
41
- id: cookies.get('visitor')?.value ?? 'anonymous',
42
- country: headers.get('x-vercel-ip-country') ?? headers.get('cf-ipcountry') ?? '',
48
+ A flag usually depends on who is asking. Build OpenFeature's evaluation context
49
+ from the request, and pass it with every evaluation:
50
+
51
+ ```ts title="src/server/flags.ts"
52
+ import { cache } from 'react'
53
+ import { OpenFeature, InMemoryProvider } from '@openfeature/server-sdk'
54
+ import { cookies } from '@rsc-kit/core/request'
55
+
56
+ await OpenFeature.setProviderAndWait(
57
+ new InMemoryProvider({
58
+ 'new-banner': {
59
+ variants: { on: true, off: false },
60
+ defaultVariant: 'off',
61
+ disabled: false,
62
+ contextEvaluator: (context) => (context.targetingKey === 'ada' ? 'on' : 'off'),
63
+ },
64
+ }),
65
+ )
66
+
67
+ const client = OpenFeature.getClient()
68
+
69
+ const visitor = cache(async () => ({
70
+ targetingKey: (await cookies()).get('user')?.value ?? 'anonymous',
43
71
  }))
44
72
 
45
- export const showBanner = flag<boolean, Visitor>({
46
- key: 'show-banner',
47
- identify: visitor,
48
- decide: ({ entities }) => entities?.country === 'GB',
49
- })
50
-
51
- export const newCheckout = flag<boolean, Visitor>({
52
- key: 'new-checkout',
53
- identify: visitor,
54
- decide: ({ entities }) => entities?.id.endsWith('7') ?? false,
55
- })
73
+ export const newBanner = cache(async () => client.getBooleanValue('new-banner', false, await visitor()))
56
74
  ```
57
75
 
58
- An adapter, such as Statsig, LaunchDarkly or Vercel's own, belongs to the SDK.
59
- Configure it the way its docs say.
60
-
61
- ## Reading a flag in a page
76
+ `targetingKey` is who the flag is decided for, usually a user id. Any other
77
+ field you add is an attribute the provider can target on, such as a country or
78
+ a plan.
62
79
 
63
- A flag reads the request, so the part of the page that awaits it renders per
64
- visitor. Put it under `<Suspense>`, and the build stores the rest of the page
65
- as a shell:
80
+ A flag that reads the visitor makes what renders it per visitor. Put that part
81
+ under `<Suspense>`, so the rest of the page is still stored as a shell:
66
82
 
67
83
  ```tsx title="src/app/page.tsx"
68
84
  import { Suspense } from 'react'
69
- import { showBanner } from '../flags'
85
+ import { newBanner } from '../server/flags'
86
+
87
+ async function Banner() {
88
+ return (await newBanner()) ? <p>Try the new board</p> : null
89
+ }
70
90
 
71
91
  export default function Home() {
72
92
  return (
73
- <>
93
+ <main>
94
+ <h1>Tasks</h1>
74
95
  <Suspense fallback={null}>
75
- <MaybeBanner />
96
+ <Banner />
76
97
  </Suspense>
77
- <h1>Welcome</h1>
78
- </>
98
+ </main>
79
99
  )
80
100
  }
101
+ ```
102
+
103
+ Without the boundary the read is above everything, and the whole page renders
104
+ per request.
105
+
106
+ ## Using a flag service
107
+
108
+ `InMemoryProvider` holds the flags in code, which is enough to ship a feature
109
+ behind a switch. To change flags without a deploy, swap it for the provider of
110
+ the service that holds them. OpenFeature lists them in its
111
+ [ecosystem](https://openfeature.dev/ecosystem). The evaluation calls don't
112
+ change:
113
+
114
+ ```ts
115
+ await OpenFeature.setProviderAndWait(new YourServiceProvider({ /* its options */ }))
116
+ ```
117
+
118
+ `setProviderAndWait` runs once, when the server starts, and rejects if the
119
+ provider can't start, so the server doesn't come up without its flags. Use
120
+ `setProvider` instead to start without waiting: until the provider is ready,
121
+ and whenever an evaluation fails, a flag answers the default you passed. An
122
+ evaluation never throws, so a page never fails over a flag.
123
+
124
+ ## Laravel: Pennant
125
+
126
+ On Laravel, flags are [Pennant](https://laravel.com/docs/pennant), defined as
127
+ Pennant's docs show. A page reads one through a class under `app/Rsc`:
128
+
129
+ ```php title="app/Providers/AppServiceProvider.php"
130
+ use App\Models\User;
131
+ use Laravel\Pennant\Feature;
132
+
133
+ public function boot(): void
134
+ {
135
+ Feature::define('new-banner', fn (User $user) => $user->isInternal());
136
+ }
137
+ ```
138
+
139
+ ```php title="app/Rsc/Flags.php"
140
+ namespace App\Rsc;
81
141
 
82
- async function MaybeBanner() {
83
- return (await showBanner()) ? <Banner /> : null
142
+ use Laravel\Pennant\Feature;
143
+
144
+ class Flags
145
+ {
146
+ public function newBanner(): bool
147
+ {
148
+ return Feature::active('new-banner');
149
+ }
84
150
  }
85
151
  ```
86
152
 
87
- The build's table says `headers() in run, cookies() in run stream per request`
88
- for that page. That is the same line any `headers()` call earns; see
89
- [Static generation](/guides/static-generation). A flag read under a boundary
90
- costs one streamed hole, not the page.
153
+ ```tsx title="resources/js/app/page.tsx"
154
+ async function Banner() {
155
+ return (await rpc('Flags.newBanner')) ? <p>Try the new board</p> : null
156
+ }
157
+ ```
158
+
159
+ Pennant decides a flag for the signed-in user by default, and the call has the
160
+ visitor's session, so `Feature::active()` is decided for them. The build sees
161
+ that read and leaves the call to the request, so put the component under
162
+ `<Suspense>` as above. A flag decided for nobody, `Feature::for(null)`, is
163
+ answered once at build and stored with the page.
164
+
165
+ To share one flag service between Laravel and a JavaScript app, OpenFeature has
166
+ a [PHP SDK](https://openfeature.dev/docs/reference/technologies/server/php) with
167
+ the same providers.
91
168
 
92
- ## The discovery endpoint
169
+ ## Go
93
170
 
94
- The Flags Explorer finds your flags through a route handler, and a `route.ts`
95
- already has that shape:
171
+ On Go, use [OpenFeature's Go SDK](https://openfeature.dev/docs/reference/technologies/server/go)
172
+ in a handler. Pass the handler's `ctx`, and build the evaluation context from the
173
+ visitor:
96
174
 
97
- ```ts title="src/app/.well-known/vercel/flags/route.ts"
98
- import { createFlagsDiscoveryEndpoint, getProviderData } from 'flags/next'
99
- import * as flags from '../../../../flags'
175
+ ```go title="flags.go"
176
+ client := openfeature.NewDefaultClient()
100
177
 
101
- export const GET = createFlagsDiscoveryEndpoint(async () => getProviderData(flags))
102
- export const openapi = false
178
+ reg.Handle("Flags.newBanner", func(ctx context.Context) (bool, error) {
179
+ visitor := openfeature.NewEvaluationContext(userID(rsckit.HeadersFrom(ctx)), nil)
180
+
181
+ return client.BooleanValue(ctx, "new-banner", false, visitor)
182
+ })
103
183
  ```
104
184
 
105
- ## Testing a flag
185
+ ```tsx title="src/app/page.tsx"
186
+ async function Banner() {
187
+ return (await rpc('Flags.newBanner')) ? <p>Try the new board</p> : null
188
+ }
189
+ ```
106
190
 
107
- A test isn't built, so it needs the alias the build adds. The scaffold's test
108
- preload ships it:
191
+ The build sees `HeadersFrom` and leaves the call to the request. It also sees
192
+ the SDK look up its own context value, which it can't tell apart from a visitor
193
+ read, so even a flag that is the same for everyone isn't stored. If your app
194
+ never sets OpenFeature's transaction context, tell the build that value isn't
195
+ the visitor:
109
196
 
110
- ```ts title="tests/preload.ts"
111
- mock.module('next/headers', () => import('@rsc-kit/core/request'))
197
+ ```go
198
+ reg.ServeCalls(os.Stdin, os.Stdout, rsckit.NotTheVisitor("github.com/open-feature/go-sdk/openfeature"))
112
199
  ```
113
200
 
114
- Without it, `flags/next` finds Next's own `next/headers`, installed by some
115
- other app in a monorepo, and throws that `headers` was called outside a
116
- request scope.
201
+ A flag read with the headers still streams per visitor; one that is the same
202
+ for everyone is then stored. See
203
+ [Reading from Go](/hosts/go/reading-from-go) for what else the build watches.
204
+
205
+ ## Testing a flag
117
206
 
118
- Then evaluate the flag inside `withRequest()`, the way anything that reads the
119
- request is tested:
207
+ A flag that reads the request evaluates in a test inside `withRequest()`:
120
208
 
121
209
  ```ts title="tests/flags.test.ts"
210
+ import { expect, test } from 'bun:test'
122
211
  import { withRequest } from '@rsc-kit/core/request'
123
- import { showBanner } from '../src/flags'
212
+ import { newBanner } from '../src/server/flags'
124
213
 
125
- test('visitors from the UK see the banner', async () => {
126
- const request = new Request('https://app.test/', { headers: { 'cf-ipcountry': 'GB' } })
214
+ test('the banner is on for ada only', async () => {
215
+ const as = (cookie: string) => new Request('https://app.test/', { headers: { Cookie: cookie } })
127
216
 
128
- expect(await withRequest(request, () => showBanner())).toBe(true)
217
+ expect(await withRequest(as('user=ada'), newBanner)).toBe(true)
218
+ expect(await withRequest(as('user=grace'), newBanner)).toBe(false)
129
219
  })
130
220
  ```
131
221
 
132
- See [Testing](/guides/testing).
133
-
134
- ## What doesn't carry over
135
-
136
- `precompute()` doesn't. It is built on a Next middleware rewriting the URL to
137
- a permutation, which is Next's routing. Read the flag in the page instead,
138
- under a boundary.
222
+ On Laravel, test the flag with Pennant's own `Feature::activate()` and
223
+ `Feature::deactivate()`, as in any Laravel test.
139
224
 
140
- ## How it works
225
+ ## Why not a framework's flag SDK
141
226
 
142
- `flags/next` needs one thing from Next: `next/headers`, for `headers()` and
143
- `cookies()`. Those exist here under the same names and with the same shapes,
144
- one object per request, which is what the SDK's per-request dedupe keys on.
145
- The build answers `next/headers` with them, so the SDK runs as written.
227
+ A flag SDK built for one framework reads the request through that framework,
228
+ and rsc-kit would have to impersonate it. The integration then breaks whenever
229
+ the SDK reaches for something new: Vercel's `flags/next` started importing
230
+ `next/navigation` in 4.5.2. OpenFeature takes the request as data you pass in,
231
+ so there is nothing to impersonate.
package/guides/forms.md CHANGED
@@ -369,13 +369,23 @@ covered without binding it.
369
369
 
370
370
  ### Checking with the server before submit
371
371
 
372
- When a field is left **having changed**, the form asks the server to check it.
372
+ Add `precognitive` and, when a field is left **having changed**, the form asks
373
+ the server to check it:
374
+
375
+ ```tsx
376
+ <Form action={register} precognitive>
377
+ ```
378
+
373
379
  The action's guards and validation run for that field, and the action itself
374
380
  doesn't. The answer shows on `error()` like any other. This catches what a
375
381
  schema in the browser can't know, such as an email that is already subscribed
376
382
  or a coupon that has expired.
377
383
 
378
- There's nothing to turn on. The actions that can be asked:
384
+ Without `precognitive`, the server hears from the form only when it is
385
+ submitted, or when you call `validate()`. A `schema` still checks each field as
386
+ it is left, since that runs in the browser.
387
+
388
+ The actions that can be asked:
379
389
 
380
390
  - a `createActionClient()` action with an input schema. Its middleware and
381
391
  schema run, and its handler is skipped.
@@ -393,7 +403,10 @@ button isn't asked about either: the submit checks every field. A file is sent
393
403
  only when its own field is the one being checked.
394
404
 
395
405
  A check runs the action's guards, so a check counts against a `throttle` on
396
- the action as a submit does.
406
+ the action as a submit does. A form of four fields behind a limit of five spends
407
+ the limit before it is sent. Let checks through in the limiter: on Laravel,
408
+ `$request->isPrecognitive()` is true for a check while the guards run (see
409
+ [Checking a field as it is filled in](/hosts/laravel/server-actions/#checking-a-field-as-it-is-filled-in)).
397
410
 
398
411
  #### When a blur is not the moment
399
412
 
package/guides/index.json CHANGED
@@ -87,7 +87,7 @@
87
87
  {
88
88
  "slug": "feature-flags",
89
89
  "title": "Feature flags",
90
- "description": "Vercel's Flags SDK runs unchanged — flags/next, without Next."
90
+ "description": "OpenFeature in a server component, Pennant on Laravel, the OpenFeature Go SDK on Go."
91
91
  },
92
92
  {
93
93
  "slug": "file-uploads",
package/guides/testing.md CHANGED
@@ -120,7 +120,7 @@ test('and no cookie is nobody', async () => {
120
120
  The scope belongs to one call, so two requests in flight in the same test don't
121
121
  see each other's cookies.
122
122
 
123
- ### `server-only` and `next/headers`
123
+ ### `server-only`
124
124
 
125
125
  A file with `import 'server-only'` throws when `bun test` imports it, because
126
126
  the test loads the real package. Keep the line: the build honours it, and a
@@ -137,16 +137,9 @@ preload = ["./tests/preload.ts"]
137
137
  import { mock } from 'bun:test'
138
138
 
139
139
  mock.module('server-only', () => ({}))
140
- mock.module('next/headers', () => import('@rsc-kit/core/request'))
140
+ mock.module('client-only', () => ({}))
141
141
  ```
142
142
 
143
- The second line covers libraries written for Next, such as the
144
- [Flags SDK](/guides/feature-flags)'s `flags/next`. The build answers
145
- `next/headers` with this package's `headers()` and `cookies()`. A test isn't
146
- built, so the import would find Next's own module, which throws outside a Next
147
- request, or nothing at all. With the stub, a flag read in an action or a page
148
- evaluates under `withRequest()` as it does in the app.
149
-
150
143
  ## Testing the whole app
151
144
 
152
145
  `createTestApp()` loads the built app and answers `Request → Response` through
@@ -94,6 +94,38 @@ too.
94
94
  [Authorization](/guides/authorization).
95
95
  </Aside>
96
96
 
97
+ ## Checking with the backend's rules
98
+
99
+ When a backend action describes its input, `<Form>` checks it with no `schema`
100
+ prop. The backend's rules and messages are the only copy, and the browser shows
101
+ the same words a submit would:
102
+
103
+ ```tsx
104
+ <Form action={store}>
105
+ {({ error }) => (
106
+ <>
107
+ <input name="email" />
108
+ {error('email') && <p className="error">{error('email')}</p>}
109
+ </>
110
+ )}
111
+ </Form>
112
+ ```
113
+
114
+ The backend writes the input's JSON Schema, with its own messages, under
115
+ `schemas` in `rsc-host.json`. See
116
+ [Describing a form's input](/hosts/your-own-backend/server-actions#describing-a-forms-input).
117
+
118
+ - Nothing is added to the page. Focusing a field loads a small index of the
119
+ actions that have schemas, and the first check loads that action's schema and
120
+ a 2.5 KB validator, [json-schema-to-standard](https://www.npmjs.com/package/json-schema-to-standard).
121
+ Both are cached files, shared by every page.
122
+ - It works whether the form imports its action or is handed it by a server
123
+ component.
124
+ - A blank field the schema doesn't require isn't posted. To the backend's rules
125
+ a blank optional field is absent, so posted as `""` it would fail a rule the
126
+ browser passed.
127
+ - A `schema` prop, when there is one, is used instead.
128
+
97
129
  ## Validating in a server action
98
130
 
99
131
  Validate with the same schema in the action, and **return** the failure rather
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsc-kit/mcp",
3
- "version": "0.46.1",
3
+ "version": "0.48.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.46.1",
37
+ "create-rsc-kit": "^0.48.0",
38
38
  "zod": "^3.25"
39
39
  },
40
40
  "devDependencies": {