@storybook/mcp 0.7.0 → 0.8.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/README.md +15 -1
- package/dist/index.d.ts +348 -34
- package/dist/index.js +396 -73
- package/dist/instructions-CiOmp0JI.js +5 -0
- package/package.json +3 -3
- package/dist/instructions-Cl0vcW2j.js +0 -5
package/README.md
CHANGED
|
@@ -260,10 +260,24 @@ type SourceManifests = {
|
|
|
260
260
|
componentManifest: ComponentManifestMap;
|
|
261
261
|
docsManifest?: DocsManifestMap;
|
|
262
262
|
error?: string;
|
|
263
|
+
notice?: RequiresOwnMcpNotice;
|
|
263
264
|
};
|
|
264
265
|
```
|
|
265
266
|
|
|
266
|
-
Represents fetched manifests
|
|
267
|
+
Represents fetched manifests, an error, or non-error routing guidance for a single source.
|
|
268
|
+
|
|
269
|
+
#### `RequiresOwnMcpNotice`
|
|
270
|
+
|
|
271
|
+
Type:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
type RequiresOwnMcpNotice = {
|
|
275
|
+
kind: 'requires-own-mcp';
|
|
276
|
+
endpoint: string;
|
|
277
|
+
};
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Indicates that a composed Storybook source cannot be read through the local MCP proxy and should be accessed through its own MCP endpoint instead.
|
|
267
281
|
|
|
268
282
|
#### Tool registration exports
|
|
269
283
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as instructions_default } from "./instructions-
|
|
1
|
+
import { t as instructions_default } from "./instructions-CiOmp0JI.js";
|
|
2
2
|
import { McpServer } from "tmcp";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
|
|
@@ -11,6 +11,10 @@ type Source = {
|
|
|
11
11
|
title: string; /** Remote URL, undefined for local source */
|
|
12
12
|
url?: string;
|
|
13
13
|
};
|
|
14
|
+
type RequiresOwnMcpNotice = {
|
|
15
|
+
kind: 'requires-own-mcp';
|
|
16
|
+
endpoint: string;
|
|
17
|
+
};
|
|
14
18
|
/**
|
|
15
19
|
* All manifests for a single source.
|
|
16
20
|
*/
|
|
@@ -18,7 +22,8 @@ type SourceManifests = {
|
|
|
18
22
|
source: Source;
|
|
19
23
|
componentManifest: ComponentManifestMap;
|
|
20
24
|
docsManifest?: DocsManifestMap; /** Error message if fetching this source failed */
|
|
21
|
-
error?: string;
|
|
25
|
+
error?: string; /** Non-error guidance for sources that must be accessed through their own MCP endpoint */
|
|
26
|
+
notice?: RequiresOwnMcpNotice;
|
|
22
27
|
};
|
|
23
28
|
/**
|
|
24
29
|
* Custom context passed to MCP server and tools.
|
|
@@ -35,7 +40,7 @@ type StorybookContext = {
|
|
|
35
40
|
* The function receives the request object, a path to the manifest file, and optionally
|
|
36
41
|
* a source (in multi-source mode).
|
|
37
42
|
* The default provider requires a request object and constructs the manifest URL from the request origin,
|
|
38
|
-
*
|
|
43
|
+
* using the top-level manifest path such as /manifests/components.json.
|
|
39
44
|
* Custom providers can use the request parameter to determine the manifest source, or ignore it entirely.
|
|
40
45
|
*/
|
|
41
46
|
manifestProvider?: (request: Request | undefined, path: string, source?: Source) => Promise<string>;
|
|
@@ -71,25 +76,59 @@ type StorybookContext = {
|
|
|
71
76
|
foundDocumentation?: never;
|
|
72
77
|
resultText?: never;
|
|
73
78
|
})) => void | Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Optional in-process resolver for a single component or docs entry, used in
|
|
81
|
+
* Storybook's dev server when `experimentalDocgenServer` is enabled. When set,
|
|
82
|
+
* single-entry tools (`get-documentation`, `get-documentation-for-story`) call
|
|
83
|
+
* this instead of fetching the (potentially all-component) manifest index, so a
|
|
84
|
+
* single lookup never triggers docgen extraction for every component.
|
|
85
|
+
*
|
|
86
|
+
* Returns the fully-resolved component or doc in `@storybook/mcp`'s internal
|
|
87
|
+
* shape (already adapted from the open-service payloads), or `undefined` when the
|
|
88
|
+
* id is unknown.
|
|
89
|
+
*/
|
|
90
|
+
resolveEntry?: (id: string, source?: Source) => Promise<ResolvedEntry | undefined>;
|
|
74
91
|
};
|
|
75
92
|
/**
|
|
76
|
-
*
|
|
77
|
-
* or standalone
|
|
93
|
+
* Result of resolving a single id via {@link StorybookContext.resolveEntry}: either a
|
|
94
|
+
* fully-resolved component manifest or a standalone docs entry.
|
|
78
95
|
*/
|
|
79
|
-
|
|
96
|
+
type ResolvedEntry = {
|
|
97
|
+
kind: 'component';
|
|
98
|
+
component: ComponentManifest;
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'doc';
|
|
101
|
+
doc: Doc;
|
|
102
|
+
};
|
|
103
|
+
declare const Story: v.ObjectSchema<{
|
|
104
|
+
readonly id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
105
|
+
readonly snippet: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
106
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
107
|
+
readonly name: v.StringSchema<undefined>;
|
|
108
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
109
|
+
readonly jsDocTags: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
|
|
110
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
111
|
+
readonly name: v.StringSchema<undefined>;
|
|
112
|
+
readonly message: v.StringSchema<undefined>;
|
|
113
|
+
}, undefined>, undefined>;
|
|
114
|
+
}, undefined>;
|
|
115
|
+
type Story = v.InferOutput<typeof Story>;
|
|
116
|
+
/** Inline (v0) docs entry: the full MDX `content` is embedded. */
|
|
117
|
+
declare const DocV0: v.ObjectSchema<{
|
|
80
118
|
readonly id: v.StringSchema<undefined>;
|
|
81
119
|
readonly name: v.StringSchema<undefined>;
|
|
82
|
-
readonly title: v.StringSchema<undefined>;
|
|
83
|
-
readonly path: v.StringSchema<undefined>;
|
|
84
|
-
readonly content: v.StringSchema<undefined>;
|
|
120
|
+
readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
121
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
122
|
+
readonly content: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
85
123
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
86
124
|
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
87
125
|
readonly name: v.StringSchema<undefined>;
|
|
88
126
|
readonly message: v.StringSchema<undefined>;
|
|
89
127
|
}, undefined>, undefined>;
|
|
90
128
|
}, undefined>;
|
|
91
|
-
type
|
|
92
|
-
|
|
129
|
+
type DocV0 = v.InferOutput<typeof DocV0>;
|
|
130
|
+
/** Inline (v0) component: docgen, stories and attached docs are all embedded. */
|
|
131
|
+
declare const ComponentManifestV0: v.ObjectSchema<{
|
|
93
132
|
readonly id: v.StringSchema<undefined>;
|
|
94
133
|
readonly stories: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
95
134
|
readonly id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -104,7 +143,7 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
104
143
|
}, undefined>, undefined>;
|
|
105
144
|
}, undefined>, undefined>, undefined>;
|
|
106
145
|
readonly subcomponents: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
107
|
-
readonly path: v.StringSchema<undefined>;
|
|
146
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
108
147
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
109
148
|
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
110
149
|
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
@@ -121,16 +160,16 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
121
160
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
122
161
|
readonly id: v.StringSchema<undefined>;
|
|
123
162
|
readonly name: v.StringSchema<undefined>;
|
|
124
|
-
readonly title: v.StringSchema<undefined>;
|
|
125
|
-
readonly path: v.StringSchema<undefined>;
|
|
126
|
-
readonly content: v.StringSchema<undefined>;
|
|
163
|
+
readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
164
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
165
|
+
readonly content: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
127
166
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
128
167
|
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
129
168
|
readonly name: v.StringSchema<undefined>;
|
|
130
169
|
readonly message: v.StringSchema<undefined>;
|
|
131
170
|
}, undefined>, undefined>;
|
|
132
171
|
}, undefined>, undefined>, undefined>;
|
|
133
|
-
readonly path: v.StringSchema<undefined>;
|
|
172
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
134
173
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
135
174
|
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
136
175
|
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
@@ -144,9 +183,63 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
144
183
|
readonly message: v.StringSchema<undefined>;
|
|
145
184
|
}, undefined>, undefined>;
|
|
146
185
|
}, undefined>;
|
|
147
|
-
type
|
|
148
|
-
|
|
149
|
-
|
|
186
|
+
type ComponentManifestV0 = v.InferOutput<typeof ComponentManifestV0>;
|
|
187
|
+
/**
|
|
188
|
+
* Shallow (v1) docs entry. The full MDX payload (title/path/content) lives behind
|
|
189
|
+
* `mdx.$ref`; `mdx` is optional because Storybook's in-process dev index omits it
|
|
190
|
+
* (those entries are resolved in-process via {@link StorybookContext.resolveEntry}).
|
|
191
|
+
*/
|
|
192
|
+
declare const DocV1: v.ObjectSchema<{
|
|
193
|
+
readonly id: v.StringSchema<undefined>;
|
|
194
|
+
readonly name: v.StringSchema<undefined>;
|
|
195
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
196
|
+
readonly mdx: v.OptionalSchema<v.ObjectSchema<{
|
|
197
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
198
|
+
}, undefined>, undefined>;
|
|
199
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
200
|
+
readonly name: v.StringSchema<undefined>;
|
|
201
|
+
readonly message: v.StringSchema<undefined>;
|
|
202
|
+
}, undefined>, undefined>;
|
|
203
|
+
}, undefined>;
|
|
204
|
+
type DocV1 = v.InferOutput<typeof DocV1>;
|
|
205
|
+
/**
|
|
206
|
+
* Shallow (v1) component index row. Identity + summary are inlined for cheap
|
|
207
|
+
* listing; docgen and story-docs live behind `$ref`s, attached docs behind nested
|
|
208
|
+
* `mdx.$ref`s. `docgen`/`stories` are optional (the in-process dev index omits
|
|
209
|
+
* `docgen`, and docs-only components have neither).
|
|
210
|
+
*/
|
|
211
|
+
declare const ComponentManifestV1: v.ObjectSchema<{
|
|
212
|
+
readonly id: v.StringSchema<undefined>;
|
|
213
|
+
readonly name: v.StringSchema<undefined>;
|
|
214
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
215
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
216
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
217
|
+
readonly name: v.StringSchema<undefined>;
|
|
218
|
+
readonly message: v.StringSchema<undefined>;
|
|
219
|
+
}, undefined>, undefined>;
|
|
220
|
+
readonly docgen: v.OptionalSchema<v.ObjectSchema<{
|
|
221
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
222
|
+
}, undefined>, undefined>;
|
|
223
|
+
readonly stories: v.OptionalSchema<v.ObjectSchema<{
|
|
224
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
225
|
+
}, undefined>, undefined>;
|
|
226
|
+
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
227
|
+
readonly id: v.StringSchema<undefined>;
|
|
228
|
+
readonly name: v.StringSchema<undefined>;
|
|
229
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
230
|
+
readonly mdx: v.OptionalSchema<v.ObjectSchema<{
|
|
231
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
232
|
+
}, undefined>, undefined>;
|
|
233
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
234
|
+
readonly name: v.StringSchema<undefined>;
|
|
235
|
+
readonly message: v.StringSchema<undefined>;
|
|
236
|
+
}, undefined>, undefined>;
|
|
237
|
+
}, undefined>, undefined>, undefined>;
|
|
238
|
+
}, undefined>;
|
|
239
|
+
type ComponentManifestV1 = v.InferOutput<typeof ComponentManifestV1>;
|
|
240
|
+
/** `components.json`, discriminated on `v` (0 = inline, 1 = split/ref). */
|
|
241
|
+
declare const ComponentManifestMap: v.VariantSchema<"v", [v.ObjectSchema<{
|
|
242
|
+
readonly v: v.LiteralSchema<0, undefined>;
|
|
150
243
|
readonly components: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
151
244
|
readonly id: v.StringSchema<undefined>;
|
|
152
245
|
readonly stories: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
@@ -162,7 +255,7 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
162
255
|
}, undefined>, undefined>;
|
|
163
256
|
}, undefined>, undefined>, undefined>;
|
|
164
257
|
readonly subcomponents: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
165
|
-
readonly path: v.StringSchema<undefined>;
|
|
258
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
166
259
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
167
260
|
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
168
261
|
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
@@ -179,16 +272,16 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
179
272
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
180
273
|
readonly id: v.StringSchema<undefined>;
|
|
181
274
|
readonly name: v.StringSchema<undefined>;
|
|
182
|
-
readonly title: v.StringSchema<undefined>;
|
|
183
|
-
readonly path: v.StringSchema<undefined>;
|
|
184
|
-
readonly content: v.StringSchema<undefined>;
|
|
275
|
+
readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
276
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
277
|
+
readonly content: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
185
278
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
186
279
|
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
187
280
|
readonly name: v.StringSchema<undefined>;
|
|
188
281
|
readonly message: v.StringSchema<undefined>;
|
|
189
282
|
}, undefined>, undefined>;
|
|
190
283
|
}, undefined>, undefined>, undefined>;
|
|
191
|
-
readonly path: v.StringSchema<undefined>;
|
|
284
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
192
285
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
193
286
|
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
194
287
|
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
@@ -202,55 +295,268 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
202
295
|
readonly message: v.StringSchema<undefined>;
|
|
203
296
|
}, undefined>, undefined>;
|
|
204
297
|
}, undefined>, undefined>;
|
|
205
|
-
}, undefined
|
|
298
|
+
}, undefined>, v.ObjectSchema<{
|
|
299
|
+
readonly v: v.LiteralSchema<1, undefined>;
|
|
300
|
+
readonly components: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
301
|
+
readonly id: v.StringSchema<undefined>;
|
|
302
|
+
readonly name: v.StringSchema<undefined>;
|
|
303
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
304
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
305
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
306
|
+
readonly name: v.StringSchema<undefined>;
|
|
307
|
+
readonly message: v.StringSchema<undefined>;
|
|
308
|
+
}, undefined>, undefined>;
|
|
309
|
+
readonly docgen: v.OptionalSchema<v.ObjectSchema<{
|
|
310
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
311
|
+
}, undefined>, undefined>;
|
|
312
|
+
readonly stories: v.OptionalSchema<v.ObjectSchema<{
|
|
313
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
314
|
+
}, undefined>, undefined>;
|
|
315
|
+
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
316
|
+
readonly id: v.StringSchema<undefined>;
|
|
317
|
+
readonly name: v.StringSchema<undefined>;
|
|
318
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
319
|
+
readonly mdx: v.OptionalSchema<v.ObjectSchema<{
|
|
320
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
321
|
+
}, undefined>, undefined>;
|
|
322
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
323
|
+
readonly name: v.StringSchema<undefined>;
|
|
324
|
+
readonly message: v.StringSchema<undefined>;
|
|
325
|
+
}, undefined>, undefined>;
|
|
326
|
+
}, undefined>, undefined>, undefined>;
|
|
327
|
+
}, undefined>, undefined>;
|
|
328
|
+
}, undefined>], undefined>;
|
|
206
329
|
type ComponentManifestMap = v.InferOutput<typeof ComponentManifestMap>;
|
|
207
330
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
331
|
+
* `docs.json` for unattached/standalone documentation entries (served at
|
|
332
|
+
* `/manifests/docs.json`), discriminated on `v`.
|
|
210
333
|
*/
|
|
211
|
-
declare const DocsManifestMap: v.ObjectSchema<{
|
|
212
|
-
readonly v: v.
|
|
334
|
+
declare const DocsManifestMap: v.VariantSchema<"v", [v.ObjectSchema<{
|
|
335
|
+
readonly v: v.LiteralSchema<0, undefined>;
|
|
213
336
|
readonly docs: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
214
337
|
readonly id: v.StringSchema<undefined>;
|
|
215
338
|
readonly name: v.StringSchema<undefined>;
|
|
216
|
-
readonly title: v.StringSchema<undefined>;
|
|
217
|
-
readonly path: v.StringSchema<undefined>;
|
|
218
|
-
readonly content: v.StringSchema<undefined>;
|
|
339
|
+
readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
340
|
+
readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
341
|
+
readonly content: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
219
342
|
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
220
343
|
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
221
344
|
readonly name: v.StringSchema<undefined>;
|
|
222
345
|
readonly message: v.StringSchema<undefined>;
|
|
223
346
|
}, undefined>, undefined>;
|
|
224
347
|
}, undefined>, undefined>;
|
|
225
|
-
}, undefined
|
|
348
|
+
}, undefined>, v.ObjectSchema<{
|
|
349
|
+
readonly v: v.LiteralSchema<1, undefined>;
|
|
350
|
+
readonly docs: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
351
|
+
readonly id: v.StringSchema<undefined>;
|
|
352
|
+
readonly name: v.StringSchema<undefined>;
|
|
353
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
354
|
+
readonly mdx: v.OptionalSchema<v.ObjectSchema<{
|
|
355
|
+
readonly $ref: v.StringSchema<undefined>;
|
|
356
|
+
}, undefined>, undefined>;
|
|
357
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
358
|
+
readonly name: v.StringSchema<undefined>;
|
|
359
|
+
readonly message: v.StringSchema<undefined>;
|
|
360
|
+
}, undefined>, undefined>;
|
|
361
|
+
}, undefined>, undefined>;
|
|
362
|
+
}, undefined>], undefined>;
|
|
226
363
|
type DocsManifestMap = v.InferOutput<typeof DocsManifestMap>;
|
|
364
|
+
/**
|
|
365
|
+
* A component index row as it appears in either format: inline (v0) or shallow
|
|
366
|
+
* ref (v1). This is what {@link resolveComponentEntry} consumes before following any
|
|
367
|
+
* `$ref`s.
|
|
368
|
+
*/
|
|
369
|
+
type ComponentManifestEntry = ComponentManifestV0 | ComponentManifestV1;
|
|
370
|
+
/** A docs index row as it appears in either format: inline (v0) or shallow ref (v1). */
|
|
371
|
+
type DocEntry = DocV0 | DocV1;
|
|
372
|
+
/**
|
|
373
|
+
* A fully-resolved component, as consumed by the tools and formatters: inline shape
|
|
374
|
+
* (stories as an array, attached docs with `content`, docgen inlined). Identical to
|
|
375
|
+
* the v0 shape — v1 rows are resolved into it by following their `$ref`s
|
|
376
|
+
* (`resolveComponentEntry`) or built in-process (`adaptCoreComponent`).
|
|
377
|
+
*/
|
|
378
|
+
type ComponentManifest = ComponentManifestV0;
|
|
379
|
+
/** A fully-resolved docs entry (inline `content`), as consumed by tools and formatters. */
|
|
380
|
+
type Doc = DocV0;
|
|
227
381
|
type AllManifests = {
|
|
228
382
|
componentManifest: ComponentManifestMap;
|
|
229
383
|
docsManifest?: DocsManifestMap;
|
|
230
384
|
};
|
|
385
|
+
/**
|
|
386
|
+
* Open-service payload contracts (the "core format") that Storybook's
|
|
387
|
+
* `experimentalDocgenServer` mode produces. `@storybook/mcp` adapts these into its
|
|
388
|
+
* internal {@link ComponentManifest}/{@link Doc} shapes in one place
|
|
389
|
+
* (`adaptCoreComponent`/`adaptCoreDoc`). Defined structurally (not as schemas) so
|
|
390
|
+
* the addon can build them in-process without importing Storybook core.
|
|
391
|
+
*/
|
|
392
|
+
/** One story snippet from the `core/story-docs` service. */
|
|
393
|
+
type CoreStoryDoc = {
|
|
394
|
+
id: string;
|
|
395
|
+
name: string;
|
|
396
|
+
snippet?: string;
|
|
397
|
+
description?: string;
|
|
398
|
+
summary?: string;
|
|
399
|
+
error?: {
|
|
400
|
+
name: string;
|
|
401
|
+
message: string;
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
/** One MDX doc from the `addon-docs/mdx` service. */
|
|
405
|
+
type CoreMdxDoc = {
|
|
406
|
+
id: string;
|
|
407
|
+
name: string;
|
|
408
|
+
path?: string;
|
|
409
|
+
title?: string;
|
|
410
|
+
content?: string;
|
|
411
|
+
summary?: string;
|
|
412
|
+
error?: {
|
|
413
|
+
name: string;
|
|
414
|
+
message: string;
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* Payload returned by the `addon-docs/mdx` service for a component or standalone
|
|
419
|
+
* docs entry.
|
|
420
|
+
*/
|
|
421
|
+
type CoreMdxPayload = {
|
|
422
|
+
id: string;
|
|
423
|
+
name: string;
|
|
424
|
+
docs: Record<string, CoreMdxDoc>;
|
|
425
|
+
};
|
|
426
|
+
/** Payload returned by the `core/story-docs` service for one component. */
|
|
427
|
+
type CoreStoryDocsPayload = {
|
|
428
|
+
id: string;
|
|
429
|
+
name: string;
|
|
430
|
+
path: string;
|
|
431
|
+
import?: string;
|
|
432
|
+
stories: Record<string, CoreStoryDoc>;
|
|
433
|
+
error?: {
|
|
434
|
+
name: string;
|
|
435
|
+
message: string;
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* Payload returned by the `core/docgen` service for one component. `argTypes` (a
|
|
440
|
+
* UI-normalized view) is intentionally ignored by the adapter; prop types come
|
|
441
|
+
* from `reactComponentMeta`/`react*` fields.
|
|
442
|
+
*/
|
|
443
|
+
type CoreDocgenPayload = {
|
|
444
|
+
id: string;
|
|
445
|
+
name: string;
|
|
446
|
+
path?: string;
|
|
447
|
+
description?: string;
|
|
448
|
+
summary?: string;
|
|
449
|
+
jsDocTags?: Record<string, string[]>;
|
|
450
|
+
import?: string;
|
|
451
|
+
reactComponentMeta?: unknown;
|
|
452
|
+
reactDocgen?: unknown;
|
|
453
|
+
reactDocgenTypescript?: unknown;
|
|
454
|
+
subcomponents?: Record<string, unknown>;
|
|
455
|
+
error?: {
|
|
456
|
+
name: string;
|
|
457
|
+
message: string;
|
|
458
|
+
};
|
|
459
|
+
[key: string]: unknown;
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* A component assembled from the `core/docgen` payload plus the `core/story-docs`
|
|
463
|
+
* stories and resolved attached MDX docs.
|
|
464
|
+
*/
|
|
465
|
+
type CoreDocgenComponent = CoreDocgenPayload & {
|
|
466
|
+
import?: string; /** Story snippets, either as a story-docs record or an already-resolved array. */
|
|
467
|
+
stories?: Record<string, CoreStoryDoc> | Story[]; /** Attached docs keyed by doc id (resolved MDX payloads). */
|
|
468
|
+
docs?: Record<string, CoreMdxDoc>;
|
|
469
|
+
};
|
|
231
470
|
//#endregion
|
|
232
471
|
//#region src/tools/list-all-documentation.d.ts
|
|
233
472
|
declare const LIST_TOOL_NAME = "list-all-documentation";
|
|
473
|
+
declare function getListAllDocumentationToolMetadata(): {
|
|
474
|
+
name: string;
|
|
475
|
+
title: string;
|
|
476
|
+
description: string;
|
|
477
|
+
schema: v.ObjectSchema<{
|
|
478
|
+
readonly withStoryIds: v.OptionalSchema<v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "When true, includes story sub-bullets under each component with story name and story ID. Use this to discover IDs for downstream story-focused workflows without filesystem lookup.">]>, false>;
|
|
479
|
+
}, undefined>;
|
|
480
|
+
};
|
|
234
481
|
declare function addListAllDocumentationTool(server: McpServer<any, StorybookContext>, enabled?: Parameters<McpServer<any, StorybookContext>['tool']>[0]['enabled']): Promise<void>;
|
|
235
482
|
//#endregion
|
|
236
483
|
//#region src/tools/get-documentation.d.ts
|
|
237
484
|
declare const GET_TOOL_NAME = "get-documentation";
|
|
485
|
+
declare function getDocumentationToolMetadata(options?: {
|
|
486
|
+
multiSource?: boolean;
|
|
487
|
+
}): {
|
|
488
|
+
name: string;
|
|
489
|
+
title: string;
|
|
490
|
+
description: string;
|
|
491
|
+
schema: v.ObjectSchema<{
|
|
492
|
+
readonly storybookId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "The Storybook source ID (e.g., \"local\", \"tetra\"). Required when multiple Storybooks are composed. See list-all-documentation for available sources.">]>;
|
|
493
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "The component or docs entry ID (e.g., \"button\")">]>;
|
|
494
|
+
}, undefined> | v.ObjectSchema<{
|
|
495
|
+
id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "The component or docs entry ID (e.g., \"button\")">]>;
|
|
496
|
+
}, undefined>;
|
|
497
|
+
};
|
|
238
498
|
declare function addGetDocumentationTool(server: McpServer<any, StorybookContext>, enabled?: Parameters<McpServer<any, StorybookContext>['tool']>[0]['enabled'], options?: {
|
|
239
499
|
multiSource?: boolean;
|
|
240
500
|
}): Promise<void>;
|
|
241
501
|
//#endregion
|
|
242
502
|
//#region src/tools/get-documentation-for-story.d.ts
|
|
243
503
|
declare const GET_STORY_TOOL_NAME = "get-documentation-for-story";
|
|
504
|
+
declare function getStoryDocumentationToolMetadata(options?: {
|
|
505
|
+
multiSource?: boolean;
|
|
506
|
+
}): {
|
|
507
|
+
name: string;
|
|
508
|
+
title: string;
|
|
509
|
+
description: string;
|
|
510
|
+
schema: v.ObjectSchema<{
|
|
511
|
+
readonly storybookId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "The Storybook source ID (e.g., \"local\", \"tetra\"). Required when multiple Storybooks are composed. See list-all-documentation for available sources.">]>;
|
|
512
|
+
readonly componentId: v.StringSchema<undefined>;
|
|
513
|
+
readonly storyName: v.StringSchema<undefined>;
|
|
514
|
+
}, undefined> | v.ObjectSchema<{
|
|
515
|
+
componentId: v.StringSchema<undefined>;
|
|
516
|
+
storyName: v.StringSchema<undefined>;
|
|
517
|
+
}, undefined>;
|
|
518
|
+
};
|
|
244
519
|
declare function addGetStoryDocumentationTool(server: McpServer<any, StorybookContext>, enabled?: Parameters<McpServer<any, StorybookContext>['tool']>[0]['enabled'], options?: {
|
|
245
520
|
multiSource?: boolean;
|
|
246
521
|
}): Promise<void>;
|
|
247
522
|
//#endregion
|
|
248
523
|
//#region src/utils/get-manifest.d.ts
|
|
524
|
+
type SourceWithUrl = Source & {
|
|
525
|
+
url: string;
|
|
526
|
+
};
|
|
527
|
+
type ManifestProvider = (request: Request | undefined, path: string, source?: Source) => Promise<string>;
|
|
249
528
|
/**
|
|
250
529
|
* The paths to the manifest files relative to the Storybook build
|
|
251
530
|
*/
|
|
252
531
|
declare const COMPONENT_MANIFEST_PATH = "./manifests/components.json";
|
|
253
532
|
declare const DOCS_MANIFEST_PATH = "./manifests/docs.json";
|
|
533
|
+
declare class RequiresOwnMcpError extends Error {
|
|
534
|
+
readonly source: SourceWithUrl;
|
|
535
|
+
readonly endpoint: string;
|
|
536
|
+
constructor(source: SourceWithUrl);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Resolves a component index entry into a full component manifest by following any
|
|
540
|
+
* `$ref`s it carries (docgen, story-docs, attached MDX docs), then adapting the
|
|
541
|
+
* core-format payloads into `@storybook/mcp`'s internal shape.
|
|
542
|
+
*
|
|
543
|
+
* Refs are read verbatim from the entry — never fabricated from an id — so a
|
|
544
|
+
* provider is only ever asked for top-level manifest paths or paths a manifest
|
|
545
|
+
* already pointed at. Components without any `$ref` (inline/v0 format, or entries
|
|
546
|
+
* already resolved in-process) are returned unchanged.
|
|
547
|
+
*/
|
|
548
|
+
declare function resolveComponentEntry(component: ComponentManifestEntry, request?: Request, manifestProvider?: ManifestProvider, source?: Source): Promise<ComponentManifest>;
|
|
549
|
+
/**
|
|
550
|
+
* Resolves only a component's stories `$ref` (story-docs payload) into a `Story[]`,
|
|
551
|
+
* leaving docgen/docs refs untouched. Used by `list-all-documentation` when story
|
|
552
|
+
* ids are requested, so listing doesn't pay for docgen/MDX resolution it won't show.
|
|
553
|
+
*/
|
|
554
|
+
declare function resolveComponentStories(component: ComponentManifestEntry, request?: Request, manifestProvider?: ManifestProvider, source?: Source): Promise<ComponentManifest>;
|
|
555
|
+
/**
|
|
556
|
+
* Resolves a standalone docs entry, following its `mdx.$ref` when present.
|
|
557
|
+
* Inline docs (v0) are returned unchanged.
|
|
558
|
+
*/
|
|
559
|
+
declare function resolveDoc(doc: DocEntry, request?: Request, manifestProvider?: ManifestProvider, source?: Source): Promise<Doc>;
|
|
254
560
|
/**
|
|
255
561
|
* Gets manifests from multiple sources.
|
|
256
562
|
* Returns an array of source manifests, each containing the source info and its manifests.
|
|
@@ -264,6 +570,14 @@ declare const DOCS_MANIFEST_PATH = "./manifests/docs.json";
|
|
|
264
570
|
*/
|
|
265
571
|
declare function getMultiSourceManifests(sources: Source[], request?: Request, manifestProvider?: (request: Request | undefined, path: string, source?: Source) => Promise<string>): Promise<SourceManifests[]>;
|
|
266
572
|
//#endregion
|
|
573
|
+
//#region src/utils/adapt-core-manifest.d.ts
|
|
574
|
+
/** Converts the story-docs `stories` record (or an already-resolved array) into `Story[]`. */
|
|
575
|
+
declare function adaptCoreStories(stories: CoreDocgenComponent['stories']): Story[] | undefined;
|
|
576
|
+
/** Adapts one MDX service payload into a {@link Doc}. */
|
|
577
|
+
declare function adaptCoreDoc(doc: CoreMdxDoc): Doc;
|
|
578
|
+
/** Adapts a core-format component (docgen + story-docs + attached MDX) into a {@link ComponentManifest}. */
|
|
579
|
+
declare function adaptCoreComponent(core: CoreDocgenComponent): ComponentManifest;
|
|
580
|
+
//#endregion
|
|
267
581
|
//#region src/index.d.ts
|
|
268
582
|
type InitializeRequestParams = {
|
|
269
583
|
protocolVersion: string;
|
|
@@ -302,4 +616,4 @@ interface StorybookMcpHandlerOptions extends StorybookContext {
|
|
|
302
616
|
type Handler = (req: Request, context?: StorybookContext) => Promise<Response>;
|
|
303
617
|
declare const createStorybookMcpHandler: (options?: StorybookMcpHandlerOptions) => Promise<Handler>;
|
|
304
618
|
//#endregion
|
|
305
|
-
export { COMPONENT_MANIFEST_PATH, type ComponentManifest, ComponentManifestMap, DOCS_MANIFEST_PATH, DocsManifestMap, GET_STORY_TOOL_NAME, GET_TOOL_NAME, LIST_TOOL_NAME, instructions_default as STORYBOOK_MCP_INSTRUCTIONS, type Source, type SourceManifests, type StorybookContext, StorybookMcpHandlerOptions, addGetDocumentationTool, addGetStoryDocumentationTool, addListAllDocumentationTool, createStorybookMcpHandler, getMultiSourceManifests };
|
|
619
|
+
export { COMPONENT_MANIFEST_PATH, type ComponentManifest, ComponentManifestMap, type CoreDocgenComponent, type CoreDocgenPayload, type CoreMdxDoc, type CoreMdxPayload, type CoreStoryDoc, type CoreStoryDocsPayload, DOCS_MANIFEST_PATH, type Doc, DocsManifestMap, GET_STORY_TOOL_NAME, GET_TOOL_NAME, LIST_TOOL_NAME, RequiresOwnMcpError, type RequiresOwnMcpNotice, type ResolvedEntry, instructions_default as STORYBOOK_MCP_INSTRUCTIONS, type Source, type SourceManifests, type Story, type StorybookContext, StorybookMcpHandlerOptions, adaptCoreComponent, adaptCoreDoc, adaptCoreStories, addGetDocumentationTool, addGetStoryDocumentationTool, addListAllDocumentationTool, createStorybookMcpHandler, getDocumentationToolMetadata, getListAllDocumentationToolMetadata, getMultiSourceManifests, getStoryDocumentationToolMetadata, resolveComponentEntry, resolveComponentStories, resolveDoc };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as instructions_default } from "./instructions-
|
|
1
|
+
import { t as instructions_default } from "./instructions-CiOmp0JI.js";
|
|
2
2
|
import { McpServer } from "tmcp";
|
|
3
3
|
import { ValibotJsonSchemaAdapter } from "@tmcp/adapter-valibot";
|
|
4
4
|
import { HttpTransport } from "@tmcp/transport-http";
|
|
@@ -6,13 +6,13 @@ import * as v from "valibot";
|
|
|
6
6
|
|
|
7
7
|
//#region package.json
|
|
8
8
|
var name = "@storybook/mcp";
|
|
9
|
-
var version = "0.
|
|
9
|
+
var version = "0.8.0";
|
|
10
10
|
var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/types.ts
|
|
14
14
|
const JSDocTag = v.record(v.string(), v.array(v.string()));
|
|
15
|
-
const
|
|
15
|
+
const ManifestError = v.object({
|
|
16
16
|
name: v.string(),
|
|
17
17
|
message: v.string()
|
|
18
18
|
});
|
|
@@ -20,7 +20,7 @@ const BaseManifest = v.object({
|
|
|
20
20
|
name: v.string(),
|
|
21
21
|
description: v.optional(v.string()),
|
|
22
22
|
jsDocTags: v.optional(JSDocTag),
|
|
23
|
-
error: v.optional(
|
|
23
|
+
error: v.optional(ManifestError)
|
|
24
24
|
});
|
|
25
25
|
const Story = v.object({
|
|
26
26
|
...BaseManifest.entries,
|
|
@@ -29,53 +29,149 @@ const Story = v.object({
|
|
|
29
29
|
summary: v.optional(v.string())
|
|
30
30
|
});
|
|
31
31
|
/**
|
|
32
|
-
* A
|
|
33
|
-
*
|
|
32
|
+
* A JSON Reference (`{ $ref }`) pointing at a value in another manifest document.
|
|
33
|
+
* Used by the v1 (split/ref) manifest format for docgen, story-docs and MDX payloads.
|
|
34
34
|
*/
|
|
35
|
-
const
|
|
35
|
+
const JsonRef = v.object({ $ref: v.string() });
|
|
36
|
+
/** Inline (v0) docs entry: the full MDX `content` is embedded. */
|
|
37
|
+
const DocV0 = v.object({
|
|
36
38
|
id: v.string(),
|
|
37
39
|
name: v.string(),
|
|
38
|
-
title: v.string(),
|
|
39
|
-
path: v.string(),
|
|
40
|
-
content: v.string(),
|
|
40
|
+
title: v.optional(v.string()),
|
|
41
|
+
path: v.optional(v.string()),
|
|
42
|
+
content: v.optional(v.string()),
|
|
41
43
|
summary: v.optional(v.string()),
|
|
42
|
-
error: v.optional(
|
|
44
|
+
error: v.optional(ManifestError)
|
|
43
45
|
});
|
|
44
|
-
const
|
|
46
|
+
const BaseInlineComponentProperties = v.object({
|
|
45
47
|
...BaseManifest.entries,
|
|
46
|
-
path: v.string(),
|
|
48
|
+
path: v.optional(v.string()),
|
|
47
49
|
summary: v.optional(v.string()),
|
|
48
50
|
import: v.optional(v.string()),
|
|
49
51
|
reactDocgen: v.optional(v.any()),
|
|
50
52
|
reactDocgenTypescript: v.optional(v.any()),
|
|
51
53
|
reactComponentMeta: v.optional(v.any())
|
|
52
54
|
});
|
|
53
|
-
const SubcomponentManifest = v.object({ ...
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const SubcomponentManifest = v.object({ ...BaseInlineComponentProperties.entries });
|
|
56
|
+
/** Inline (v0) component: docgen, stories and attached docs are all embedded. */
|
|
57
|
+
const ComponentManifestV0 = v.object({
|
|
58
|
+
...BaseInlineComponentProperties.entries,
|
|
56
59
|
id: v.string(),
|
|
57
60
|
stories: v.optional(v.array(Story)),
|
|
58
61
|
subcomponents: v.optional(v.record(v.string(), SubcomponentManifest)),
|
|
59
|
-
docs: v.optional(v.record(v.string(),
|
|
62
|
+
docs: v.optional(v.record(v.string(), DocV0))
|
|
60
63
|
});
|
|
61
|
-
const
|
|
62
|
-
v: v.
|
|
63
|
-
components: v.record(v.string(),
|
|
64
|
+
const ComponentManifestMapV0 = v.object({
|
|
65
|
+
v: v.literal(0),
|
|
66
|
+
components: v.record(v.string(), ComponentManifestV0)
|
|
67
|
+
});
|
|
68
|
+
const DocsManifestMapV0 = v.object({
|
|
69
|
+
v: v.literal(0),
|
|
70
|
+
docs: v.record(v.string(), DocV0)
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Shallow (v1) docs entry. The full MDX payload (title/path/content) lives behind
|
|
74
|
+
* `mdx.$ref`; `mdx` is optional because Storybook's in-process dev index omits it
|
|
75
|
+
* (those entries are resolved in-process via {@link StorybookContext.resolveEntry}).
|
|
76
|
+
*/
|
|
77
|
+
const DocV1 = v.object({
|
|
78
|
+
id: v.string(),
|
|
79
|
+
name: v.string(),
|
|
80
|
+
summary: v.optional(v.string()),
|
|
81
|
+
mdx: v.optional(JsonRef),
|
|
82
|
+
error: v.optional(ManifestError)
|
|
64
83
|
});
|
|
65
84
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
85
|
+
* Shallow (v1) component index row. Identity + summary are inlined for cheap
|
|
86
|
+
* listing; docgen and story-docs live behind `$ref`s, attached docs behind nested
|
|
87
|
+
* `mdx.$ref`s. `docgen`/`stories` are optional (the in-process dev index omits
|
|
88
|
+
* `docgen`, and docs-only components have neither).
|
|
68
89
|
*/
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
const ComponentManifestV1 = v.object({
|
|
91
|
+
id: v.string(),
|
|
92
|
+
name: v.string(),
|
|
93
|
+
description: v.optional(v.string()),
|
|
94
|
+
summary: v.optional(v.string()),
|
|
95
|
+
error: v.optional(ManifestError),
|
|
96
|
+
docgen: v.optional(JsonRef),
|
|
97
|
+
stories: v.optional(JsonRef),
|
|
98
|
+
docs: v.optional(v.record(v.string(), DocV1))
|
|
72
99
|
});
|
|
100
|
+
const ComponentManifestMapV1 = v.object({
|
|
101
|
+
v: v.literal(1),
|
|
102
|
+
components: v.record(v.string(), ComponentManifestV1)
|
|
103
|
+
});
|
|
104
|
+
const DocsManifestMapV1 = v.object({
|
|
105
|
+
v: v.literal(1),
|
|
106
|
+
docs: v.record(v.string(), DocV1)
|
|
107
|
+
});
|
|
108
|
+
/** `components.json`, discriminated on `v` (0 = inline, 1 = split/ref). */
|
|
109
|
+
const ComponentManifestMap = v.variant("v", [ComponentManifestMapV0, ComponentManifestMapV1]);
|
|
110
|
+
/**
|
|
111
|
+
* `docs.json` for unattached/standalone documentation entries (served at
|
|
112
|
+
* `/manifests/docs.json`), discriminated on `v`.
|
|
113
|
+
*/
|
|
114
|
+
const DocsManifestMap = v.variant("v", [DocsManifestMapV0, DocsManifestMapV1]);
|
|
73
115
|
/**
|
|
74
116
|
* Shared Valibot field for the storybookId input, used in multi-source mode.
|
|
75
117
|
* Reused across tools that support source selection.
|
|
76
118
|
*/
|
|
77
119
|
const StorybookIdField = { storybookId: v.pipe(v.string(), v.description("The Storybook source ID (e.g., \"local\", \"tetra\"). Required when multiple Storybooks are composed. See list-all-documentation for available sources.")) };
|
|
78
120
|
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/utils/adapt-core-manifest.ts
|
|
123
|
+
/**
|
|
124
|
+
* Adapts Storybook's `experimentalDocgenServer` open-service payloads (the "core
|
|
125
|
+
* format") into `@storybook/mcp`'s internal {@link ComponentManifest}/{@link Doc}
|
|
126
|
+
* shapes. This is the single place that bridges the two formats, used by both the
|
|
127
|
+
* ref-resolution path (built/static/remote manifests) and the addon's in-process
|
|
128
|
+
* `resolveEntry` hook (dev).
|
|
129
|
+
*
|
|
130
|
+
* Only `argTypes` is dropped: prop types still come from `reactComponentMeta` and
|
|
131
|
+
* the `react*` docgen-engine fields, which are passed through unchanged.
|
|
132
|
+
*/
|
|
133
|
+
const ARG_TYPES_KEY = "argTypes";
|
|
134
|
+
/** Converts the story-docs `stories` record (or an already-resolved array) into `Story[]`. */
|
|
135
|
+
function adaptCoreStories(stories) {
|
|
136
|
+
if (!stories) return;
|
|
137
|
+
if (Array.isArray(stories)) return stories;
|
|
138
|
+
return Object.values(stories);
|
|
139
|
+
}
|
|
140
|
+
/** Adapts one MDX service payload into a {@link Doc}. */
|
|
141
|
+
function adaptCoreDoc(doc) {
|
|
142
|
+
return { ...doc };
|
|
143
|
+
}
|
|
144
|
+
/** Adapts a core-format component (docgen + story-docs + attached MDX) into a {@link ComponentManifest}. */
|
|
145
|
+
function adaptCoreComponent(core) {
|
|
146
|
+
const { stories, docs, [ARG_TYPES_KEY]: _argTypes, ...rest } = core;
|
|
147
|
+
const component = { ...rest };
|
|
148
|
+
const adaptedStories = adaptCoreStories(stories);
|
|
149
|
+
if (adaptedStories) component.stories = adaptedStories;
|
|
150
|
+
if (docs) component.docs = Object.fromEntries(Object.entries(docs).map(([id, doc]) => [id, adaptCoreDoc(doc)]));
|
|
151
|
+
return component;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/utils/requires-own-mcp.ts
|
|
156
|
+
function getSourceMcpEndpoint(source) {
|
|
157
|
+
const base = new URL(source.url);
|
|
158
|
+
base.pathname = `${base.pathname.replace(/\/$/, "")}/`;
|
|
159
|
+
return new URL("mcp", base).toString();
|
|
160
|
+
}
|
|
161
|
+
function formatRequiresOwnMcpNotice(source, endpoint, options = {}) {
|
|
162
|
+
const parts = [];
|
|
163
|
+
if (options.includeHeader ?? true) {
|
|
164
|
+
parts.push(`# ${source.title}`);
|
|
165
|
+
parts.push(`id: ${source.id}`);
|
|
166
|
+
parts.push("");
|
|
167
|
+
}
|
|
168
|
+
parts.push("This composed Storybook is private and cannot be read through the local Storybook MCP proxy.");
|
|
169
|
+
parts.push("");
|
|
170
|
+
parts.push("Use this source's own MCP endpoint instead:");
|
|
171
|
+
parts.push(endpoint);
|
|
172
|
+
return parts.join("\n");
|
|
173
|
+
}
|
|
174
|
+
|
|
79
175
|
//#endregion
|
|
80
176
|
//#region src/utils/get-manifest.ts
|
|
81
177
|
/**
|
|
@@ -83,6 +179,11 @@ const StorybookIdField = { storybookId: v.pipe(v.string(), v.description("The St
|
|
|
83
179
|
*/
|
|
84
180
|
const COMPONENT_MANIFEST_PATH = "./manifests/components.json";
|
|
85
181
|
const DOCS_MANIFEST_PATH = "./manifests/docs.json";
|
|
182
|
+
/** Empty placeholder manifest used for sources that errored or need their own MCP endpoint. */
|
|
183
|
+
const EMPTY_COMPONENT_MANIFEST = {
|
|
184
|
+
v: 1,
|
|
185
|
+
components: {}
|
|
186
|
+
};
|
|
86
187
|
/**
|
|
87
188
|
* Error thrown when getting or parsing a manifest fails
|
|
88
189
|
*/
|
|
@@ -96,6 +197,17 @@ var ManifestGetError = class extends Error {
|
|
|
96
197
|
this.cause = cause;
|
|
97
198
|
}
|
|
98
199
|
};
|
|
200
|
+
var RequiresOwnMcpError = class extends Error {
|
|
201
|
+
source;
|
|
202
|
+
endpoint;
|
|
203
|
+
constructor(source) {
|
|
204
|
+
const endpoint = getSourceMcpEndpoint(source);
|
|
205
|
+
super(`Composed Storybook "${source.title}" requires its own MCP endpoint: ${endpoint}`);
|
|
206
|
+
this.name = "RequiresOwnMcpError";
|
|
207
|
+
this.source = source;
|
|
208
|
+
this.endpoint = endpoint;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
99
211
|
/**
|
|
100
212
|
* Converts an error to MCP-compatible content format
|
|
101
213
|
*
|
|
@@ -103,6 +215,10 @@ var ManifestGetError = class extends Error {
|
|
|
103
215
|
* @returns A tool result with error content and isError flag
|
|
104
216
|
*/
|
|
105
217
|
const errorToMCPContent = (error) => {
|
|
218
|
+
if (error instanceof RequiresOwnMcpError) return { content: [{
|
|
219
|
+
type: "text",
|
|
220
|
+
text: formatRequiresOwnMcpNotice(error.source, error.endpoint)
|
|
221
|
+
}] };
|
|
106
222
|
let fullMessage = `${error instanceof ManifestGetError ? "Error getting manifest" : "Unexpected error"}: ${error instanceof Error ? error.message : String(error)}`;
|
|
107
223
|
if (error instanceof ManifestGetError && error.cause) {
|
|
108
224
|
const causeMessage = error.cause instanceof Error ? error.cause.message : String(error.cause);
|
|
@@ -142,6 +258,7 @@ async function getManifests(request, manifestProvider, source) {
|
|
|
142
258
|
const getUrl = (path) => request ? getManifestUrlFromRequest(request, path) : "Unknown manifest source";
|
|
143
259
|
if (componentResult.status === "rejected") {
|
|
144
260
|
const reason = componentResult.reason;
|
|
261
|
+
if (reason instanceof RequiresOwnMcpError) throw reason;
|
|
145
262
|
const hint = reason instanceof ManifestGetError && reason.message.includes("404") ? `\nHint: The Storybook at this URL may not have the component manifest enabled. Add \`features: { componentsManifest: true }\` (or \`features: { experimentalComponentsManifest: true }\` for older Storybook versions) to its main.ts config.` : "";
|
|
146
263
|
throw new ManifestGetError(`Failed to get component manifest: ${reason instanceof Error ? reason.message : String(reason)}${hint}`, getUrl(COMPONENT_MANIFEST_PATH), reason instanceof Error ? reason : void 0);
|
|
147
264
|
}
|
|
@@ -164,17 +281,132 @@ async function getManifests(request, manifestProvider, source) {
|
|
|
164
281
|
};
|
|
165
282
|
}
|
|
166
283
|
/**
|
|
167
|
-
*
|
|
284
|
+
* Resolves a `$ref` into the provider path of the referenced file and the
|
|
285
|
+
* JSON-pointer segments into it.
|
|
286
|
+
*
|
|
287
|
+
* The `$ref` file path is relative to the component manifest's location, e.g.
|
|
288
|
+
* `"../services/core/docgen/button.json#/components/button"` from
|
|
289
|
+
* `./manifests/components.json` resolves to `./services/core/docgen/button.json`
|
|
290
|
+
* with pointer `["components", "button"]`. The same base (`manifests/`) applies to
|
|
291
|
+
* docgen, story-docs and MDX refs.
|
|
292
|
+
*/
|
|
293
|
+
function parseManifestRef(ref) {
|
|
294
|
+
const [filePath = "", hash = ""] = ref.split("#");
|
|
295
|
+
const manifestDir = COMPONENT_MANIFEST_PATH.replace(/^\.\//, "").replace(/[^/]+$/, "");
|
|
296
|
+
const resolved = new URL(filePath, `https://localhost/${manifestDir}`).pathname.replace(/^\//, "");
|
|
297
|
+
const pointer = hash.split("/").filter(Boolean).map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
298
|
+
return {
|
|
299
|
+
path: `./${resolved}`,
|
|
300
|
+
pointer
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Fetches the file a `$ref` points at (verbatim — never a fabricated path) and
|
|
305
|
+
* walks its JSON pointer, returning the pointed-to value.
|
|
306
|
+
*/
|
|
307
|
+
async function fetchRefValue(ref, request, provider, source) {
|
|
308
|
+
const { path, pointer } = parseManifestRef(ref);
|
|
309
|
+
const jsonString = await provider(request, path, source);
|
|
310
|
+
let target;
|
|
311
|
+
try {
|
|
312
|
+
target = JSON.parse(jsonString);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
throw new ManifestGetError(`Failed to parse externalized payload referenced by "${ref}"`, path, error instanceof Error ? error : void 0);
|
|
315
|
+
}
|
|
316
|
+
for (const key of pointer) if (target && typeof target === "object" && key in target) target = target[key];
|
|
317
|
+
else throw new ManifestGetError(`Reference "${ref}" could not be resolved: missing "${key}".`, path);
|
|
318
|
+
return target;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Resolves a component index entry into a full component manifest by following any
|
|
322
|
+
* `$ref`s it carries (docgen, story-docs, attached MDX docs), then adapting the
|
|
323
|
+
* core-format payloads into `@storybook/mcp`'s internal shape.
|
|
324
|
+
*
|
|
325
|
+
* Refs are read verbatim from the entry — never fabricated from an id — so a
|
|
326
|
+
* provider is only ever asked for top-level manifest paths or paths a manifest
|
|
327
|
+
* already pointed at. Components without any `$ref` (inline/v0 format, or entries
|
|
328
|
+
* already resolved in-process) are returned unchanged.
|
|
329
|
+
*/
|
|
330
|
+
async function resolveComponentEntry(component, request, manifestProvider, source) {
|
|
331
|
+
const docgenRef = "docgen" in component ? component.docgen?.$ref : void 0;
|
|
332
|
+
const storiesRef = component.stories && !Array.isArray(component.stories) ? component.stories.$ref : void 0;
|
|
333
|
+
const docEntries = component.docs ? Object.entries(component.docs) : [];
|
|
334
|
+
const docRefs = docEntries.filter(([, doc]) => "mdx" in doc && !!doc.mdx?.$ref);
|
|
335
|
+
if (!docgenRef && !storiesRef && docRefs.length === 0) return component;
|
|
336
|
+
const provider = manifestProvider ?? defaultManifestProvider;
|
|
337
|
+
let core = {
|
|
338
|
+
id: component.id,
|
|
339
|
+
name: component.name,
|
|
340
|
+
...component.description !== void 0 ? { description: component.description } : {},
|
|
341
|
+
...component.summary !== void 0 ? { summary: component.summary } : {},
|
|
342
|
+
...component.error !== void 0 ? { error: component.error } : {}
|
|
343
|
+
};
|
|
344
|
+
if (docgenRef) {
|
|
345
|
+
const payload = await fetchRefValue(docgenRef, request, provider, source);
|
|
346
|
+
core = {
|
|
347
|
+
...core,
|
|
348
|
+
...payload,
|
|
349
|
+
id: component.id,
|
|
350
|
+
name: component.name,
|
|
351
|
+
...component.description !== void 0 ? { description: component.description } : {},
|
|
352
|
+
...component.summary !== void 0 ? { summary: component.summary } : {},
|
|
353
|
+
...component.error !== void 0 ? { error: component.error } : {}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
if (Array.isArray(component.stories)) core.stories = component.stories;
|
|
357
|
+
if (storiesRef) {
|
|
358
|
+
const storyDocs = await fetchRefValue(storiesRef, request, provider, source);
|
|
359
|
+
if (storyDocs?.stories) core.stories = storyDocs.stories;
|
|
360
|
+
if (storyDocs?.import) core.import = storyDocs.import;
|
|
361
|
+
}
|
|
362
|
+
if (docEntries.length > 0) {
|
|
363
|
+
const docs = {};
|
|
364
|
+
for (const [docId, doc] of docEntries) {
|
|
365
|
+
const mdxRef = "mdx" in doc ? doc.mdx?.$ref : void 0;
|
|
366
|
+
docs[docId] = mdxRef ? await fetchRefValue(mdxRef, request, provider, source) : doc;
|
|
367
|
+
}
|
|
368
|
+
core.docs = docs;
|
|
369
|
+
}
|
|
370
|
+
return adaptCoreComponent(core);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Resolves only a component's stories `$ref` (story-docs payload) into a `Story[]`,
|
|
374
|
+
* leaving docgen/docs refs untouched. Used by `list-all-documentation` when story
|
|
375
|
+
* ids are requested, so listing doesn't pay for docgen/MDX resolution it won't show.
|
|
376
|
+
*/
|
|
377
|
+
async function resolveComponentStories(component, request, manifestProvider, source) {
|
|
378
|
+
if (!component.stories || Array.isArray(component.stories)) return component;
|
|
379
|
+
const provider = manifestProvider ?? defaultManifestProvider;
|
|
380
|
+
const storyDocs = await fetchRefValue(component.stories.$ref, request, provider, source);
|
|
381
|
+
return {
|
|
382
|
+
...component,
|
|
383
|
+
stories: storyDocs?.stories ? adaptCoreStories(storyDocs.stories) : []
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Resolves a standalone docs entry, following its `mdx.$ref` when present.
|
|
388
|
+
* Inline docs (v0) are returned unchanged.
|
|
389
|
+
*/
|
|
390
|
+
async function resolveDoc(doc, request, manifestProvider, source) {
|
|
391
|
+
const ref = "mdx" in doc ? doc.mdx?.$ref : void 0;
|
|
392
|
+
if (!ref) return doc;
|
|
393
|
+
const payload = await fetchRefValue(ref, request, manifestProvider ?? defaultManifestProvider, source);
|
|
394
|
+
return adaptCoreDoc({
|
|
395
|
+
...payload,
|
|
396
|
+
id: payload.id ?? doc.id,
|
|
397
|
+
name: payload.name ?? doc.name
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Constructs the manifest URL from the request origin and the top-level manifest path.
|
|
168
402
|
*/
|
|
169
403
|
function getManifestUrlFromRequest(request, path) {
|
|
170
|
-
const url = new URL(request.url);
|
|
171
404
|
const normalizedPath = path.replace(/^\.\//, "");
|
|
172
|
-
|
|
173
|
-
return url.toString();
|
|
405
|
+
return new URL(`/${normalizedPath}`, request.url).toString();
|
|
174
406
|
}
|
|
175
407
|
/**
|
|
176
408
|
* Default manifest provider that fetches from the same origin as the request,
|
|
177
|
-
*
|
|
409
|
+
* using Storybook's top-level manifest path.
|
|
178
410
|
*/
|
|
179
411
|
async function defaultManifestProvider(request, path) {
|
|
180
412
|
if (!request) throw new ManifestGetError("Request is required when using the default manifest provider. You must either pass the original request forward to the server context, or set a custom manifestProvider that doesn't need the request.");
|
|
@@ -206,17 +438,45 @@ async function getMultiSourceManifests(sources, request, manifestProvider) {
|
|
|
206
438
|
docsManifest: manifests.docsManifest
|
|
207
439
|
};
|
|
208
440
|
} catch (error) {
|
|
441
|
+
if (error instanceof RequiresOwnMcpError) return {
|
|
442
|
+
source,
|
|
443
|
+
componentManifest: EMPTY_COMPONENT_MANIFEST,
|
|
444
|
+
notice: {
|
|
445
|
+
kind: "requires-own-mcp",
|
|
446
|
+
endpoint: error.endpoint
|
|
447
|
+
}
|
|
448
|
+
};
|
|
209
449
|
return {
|
|
210
450
|
source,
|
|
211
|
-
componentManifest:
|
|
212
|
-
v: 1,
|
|
213
|
-
components: {}
|
|
214
|
-
},
|
|
451
|
+
componentManifest: EMPTY_COMPONENT_MANIFEST,
|
|
215
452
|
error: error instanceof Error ? error.message : String(error)
|
|
216
453
|
};
|
|
217
454
|
}
|
|
218
455
|
}));
|
|
219
|
-
|
|
456
|
+
const successCount = results.filter((r) => !r.error && !r.notice).length;
|
|
457
|
+
const noticeCount = results.filter((r) => r.notice).length;
|
|
458
|
+
if (successCount === 0 && noticeCount === 0) throw new ManifestGetError(`Failed to fetch manifests from any source. Errors:\n${results.map((r) => `- ${r.source.title}: ${r.error}`).join("\n")}`);
|
|
459
|
+
return results;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/utils/map-with-concurrency.ts
|
|
464
|
+
/**
|
|
465
|
+
* Maps `items` with at most `limit` concurrent in-flight `fn` calls.
|
|
466
|
+
*/
|
|
467
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
468
|
+
if (items.length === 0) return [];
|
|
469
|
+
const safeLimit = Number.isFinite(limit) ? limit : items.length;
|
|
470
|
+
const concurrency = Math.max(1, Math.min(safeLimit, items.length));
|
|
471
|
+
const results = Array(items.length);
|
|
472
|
+
let nextIndex = 0;
|
|
473
|
+
async function worker() {
|
|
474
|
+
while (nextIndex < items.length) {
|
|
475
|
+
const index = nextIndex++;
|
|
476
|
+
results[index] = await fn(items[index], index);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
await Promise.all(Array.from({ length: concurrency }, () => worker()));
|
|
220
480
|
return results;
|
|
221
481
|
}
|
|
222
482
|
|
|
@@ -374,8 +634,10 @@ function formatComponentLine(component) {
|
|
|
374
634
|
return `- ${component.name} (${component.id})`;
|
|
375
635
|
}
|
|
376
636
|
function formatDocLine(doc) {
|
|
377
|
-
const
|
|
378
|
-
|
|
637
|
+
const title = "title" in doc ? doc.title : void 0;
|
|
638
|
+
const content = "content" in doc ? doc.content : void 0;
|
|
639
|
+
const summary = doc.summary ?? extractDocsSummary(content ?? "");
|
|
640
|
+
return `- ${title ?? doc.name} (${doc.id})${summary ? `: ${summary}` : ""}`;
|
|
379
641
|
}
|
|
380
642
|
function formatStorySubLine(story) {
|
|
381
643
|
return ` - ${story.name}` + (story.id ? ` (${story.id})` : "");
|
|
@@ -502,10 +764,11 @@ function formatComponentManifest(componentManifest) {
|
|
|
502
764
|
}
|
|
503
765
|
parts.push(...formatSubcomponentsSection(componentManifest.subcomponents));
|
|
504
766
|
const parsedDocgen = getParsedDocgen(componentManifest);
|
|
505
|
-
|
|
767
|
+
const stories = Array.isArray(componentManifest.stories) ? componentManifest.stories : [];
|
|
768
|
+
if (stories.length > 0) {
|
|
506
769
|
parts.push("## Stories");
|
|
507
770
|
parts.push("");
|
|
508
|
-
const storiesWithSnippets =
|
|
771
|
+
const storiesWithSnippets = stories.filter((s) => s.snippet);
|
|
509
772
|
const hasProps = parsedDocgen && Object.keys(parsedDocgen.props).length > 0;
|
|
510
773
|
const storiesToShow = hasProps ? storiesWithSnippets.slice(0, MAX_STORIES_TO_SHOW) : storiesWithSnippets;
|
|
511
774
|
const remainingStories = hasProps ? storiesWithSnippets.slice(MAX_STORIES_TO_SHOW) : [];
|
|
@@ -533,14 +796,14 @@ function formatComponentManifest(componentManifest) {
|
|
|
533
796
|
}
|
|
534
797
|
parts.push(...formatPropsSection(parsedDocgen));
|
|
535
798
|
if (componentManifest.docs && Object.keys(componentManifest.docs).length > 0) {
|
|
536
|
-
const docsWithContent = Object.values(componentManifest.docs).filter((doc) => doc.content.trim().length > 0);
|
|
799
|
+
const docsWithContent = Object.values(componentManifest.docs).filter((doc) => (doc.content ?? "").trim().length > 0);
|
|
537
800
|
if (docsWithContent.length > 0) {
|
|
538
801
|
parts.push("## Docs");
|
|
539
802
|
parts.push("");
|
|
540
803
|
for (const doc of docsWithContent) {
|
|
541
804
|
parts.push(`### ${doc.name}`);
|
|
542
805
|
parts.push("");
|
|
543
|
-
parts.push(doc.content);
|
|
806
|
+
parts.push(doc.content ?? "");
|
|
544
807
|
parts.push("");
|
|
545
808
|
}
|
|
546
809
|
}
|
|
@@ -551,9 +814,9 @@ function formatComponentManifest(componentManifest) {
|
|
|
551
814
|
* Format a single doc manifest into markdown.
|
|
552
815
|
*/
|
|
553
816
|
function formatDocsManifest(doc) {
|
|
554
|
-
return dedent`# ${doc.title}
|
|
817
|
+
return dedent`# ${doc.title ?? doc.name}
|
|
555
818
|
|
|
556
|
-
${doc.content}`;
|
|
819
|
+
${doc.content ?? ""}`;
|
|
557
820
|
}
|
|
558
821
|
/**
|
|
559
822
|
* Format a component manifest map into a markdown list.
|
|
@@ -566,7 +829,7 @@ function formatManifestsToLists(manifests, options = {}) {
|
|
|
566
829
|
parts.push("");
|
|
567
830
|
for (const component of Object.values(manifests.componentManifest.components)) {
|
|
568
831
|
parts.push(formatComponentLine(component));
|
|
569
|
-
if (options.withStoryIds) for (const story of component.stories
|
|
832
|
+
if (options.withStoryIds && Array.isArray(component.stories)) for (const story of component.stories) parts.push(formatStorySubLine(story));
|
|
570
833
|
}
|
|
571
834
|
parts.push("");
|
|
572
835
|
if (!manifests.docsManifest) return parts.join("\n").trim();
|
|
@@ -577,7 +840,7 @@ function formatManifestsToLists(manifests, options = {}) {
|
|
|
577
840
|
}
|
|
578
841
|
function formatMultiSourceManifestsToLists(manifests, options = {}) {
|
|
579
842
|
const parts = [];
|
|
580
|
-
for (const { source, componentManifest, docsManifest, error } of manifests) {
|
|
843
|
+
for (const { source, componentManifest, docsManifest, error, notice } of manifests) {
|
|
581
844
|
parts.push(`# ${source.title}`);
|
|
582
845
|
parts.push(`id: ${source.id}`);
|
|
583
846
|
parts.push("");
|
|
@@ -586,13 +849,18 @@ function formatMultiSourceManifestsToLists(manifests, options = {}) {
|
|
|
586
849
|
parts.push("");
|
|
587
850
|
continue;
|
|
588
851
|
}
|
|
852
|
+
if (notice) {
|
|
853
|
+
parts.push(formatRequiresOwnMcpNotice(source, notice.endpoint, { includeHeader: false }));
|
|
854
|
+
parts.push("");
|
|
855
|
+
continue;
|
|
856
|
+
}
|
|
589
857
|
const components = Object.values(componentManifest.components);
|
|
590
858
|
if (components.length > 0) {
|
|
591
859
|
parts.push("## Components");
|
|
592
860
|
parts.push("");
|
|
593
861
|
for (const component of components) {
|
|
594
862
|
parts.push(formatComponentLine(component));
|
|
595
|
-
if (options.withStoryIds) for (const story of component.stories
|
|
863
|
+
if (options.withStoryIds && Array.isArray(component.stories)) for (const story of component.stories) parts.push(formatStorySubLine(story));
|
|
596
864
|
}
|
|
597
865
|
parts.push("");
|
|
598
866
|
}
|
|
@@ -609,7 +877,7 @@ function formatMultiSourceManifestsToLists(manifests, options = {}) {
|
|
|
609
877
|
* Format a single story's documentation.
|
|
610
878
|
*/
|
|
611
879
|
function formatStoryDocumentation(componentManifest, storyName) {
|
|
612
|
-
const story = componentManifest.stories
|
|
880
|
+
const story = Array.isArray(componentManifest.stories) ? componentManifest.stories.find((s) => s.name === storyName) : void 0;
|
|
613
881
|
if (!story || !story.snippet) return "";
|
|
614
882
|
const parts = [];
|
|
615
883
|
parts.push(`# ${componentManifest.name} - ${story.name}`);
|
|
@@ -622,12 +890,17 @@ function formatStoryDocumentation(componentManifest, storyName) {
|
|
|
622
890
|
//#region src/tools/list-all-documentation.ts
|
|
623
891
|
const LIST_TOOL_NAME = "list-all-documentation";
|
|
624
892
|
const ListAllDocumentationInput = v.object({ withStoryIds: v.optional(v.pipe(v.boolean(), v.description("When true, includes story sub-bullets under each component with story name and story ID. Use this to discover IDs for downstream story-focused workflows without filesystem lookup.")), false) });
|
|
625
|
-
|
|
626
|
-
|
|
893
|
+
function getListAllDocumentationToolMetadata() {
|
|
894
|
+
return {
|
|
627
895
|
name: LIST_TOOL_NAME,
|
|
628
896
|
title: "List All Documentation",
|
|
629
|
-
description: "List all available UI components and documentation entries from the Storybook",
|
|
630
|
-
schema: ListAllDocumentationInput
|
|
897
|
+
description: "List all available UI components and documentation entries from the Storybook, returning the IDs the other documentation tools take as input. Call this first for any UI task — before writing a new component, check what the design system already provides and build on it instead of hand-rolling a duplicate; before answering any question about props, API, or usage, discover the relevant IDs here rather than reading component source. Then fetch the entries with get-documentation, referencing only IDs returned here — never guess IDs. When multiple Storybook sources are configured, entries from every source are included; scope follow-up calls to one source via their `storybookId` input. Pass `withStoryIds: true` when you need story IDs for other tools.",
|
|
898
|
+
schema: ListAllDocumentationInput
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
async function addListAllDocumentationTool(server, enabled) {
|
|
902
|
+
server.tool({
|
|
903
|
+
...getListAllDocumentationToolMetadata(),
|
|
631
904
|
enabled
|
|
632
905
|
}, async (input) => {
|
|
633
906
|
try {
|
|
@@ -635,8 +908,18 @@ async function addListAllDocumentationTool(server, enabled) {
|
|
|
635
908
|
const withStoryIds = input.withStoryIds ?? false;
|
|
636
909
|
if (ctx?.sources?.some((s) => s.url)) {
|
|
637
910
|
const multiSourceManifests = await getMultiSourceManifests(ctx.sources, ctx.request, ctx.manifestProvider);
|
|
911
|
+
if (withStoryIds) await Promise.all(multiSourceManifests.map(async (sourceManifest) => {
|
|
912
|
+
if (sourceManifest.error || sourceManifest.notice) return;
|
|
913
|
+
try {
|
|
914
|
+
const components = sourceManifest.componentManifest.components;
|
|
915
|
+
const resolved = await mapWithConcurrency(Object.entries(components), 16, async ([id, component]) => {
|
|
916
|
+
return [id, await resolveComponentStories(component, ctx.request, ctx.manifestProvider, sourceManifest.source)];
|
|
917
|
+
});
|
|
918
|
+
for (const [id, component] of resolved) components[id] = component;
|
|
919
|
+
} catch {}
|
|
920
|
+
}));
|
|
638
921
|
const lists = formatMultiSourceManifestsToLists(multiSourceManifests, { withStoryIds });
|
|
639
|
-
const firstSuccess = multiSourceManifests.find((m) => !m.error);
|
|
922
|
+
const firstSuccess = multiSourceManifests.find((m) => !m.error && !m.notice);
|
|
640
923
|
if (firstSuccess) await ctx.onListAllDocumentation?.({
|
|
641
924
|
context: ctx,
|
|
642
925
|
manifests: {
|
|
@@ -652,6 +935,13 @@ async function addListAllDocumentationTool(server, enabled) {
|
|
|
652
935
|
}] };
|
|
653
936
|
}
|
|
654
937
|
const manifests = await getManifests(ctx?.request, ctx?.manifestProvider);
|
|
938
|
+
if (withStoryIds) {
|
|
939
|
+
const components = manifests.componentManifest.components;
|
|
940
|
+
const resolved = await mapWithConcurrency(Object.entries(components), 16, async ([id, component]) => {
|
|
941
|
+
return [id, await resolveComponentStories(component, ctx?.request, ctx?.manifestProvider)];
|
|
942
|
+
});
|
|
943
|
+
for (const [id, component] of resolved) components[id] = component;
|
|
944
|
+
}
|
|
655
945
|
const lists = formatManifestsToLists(manifests, { withStoryIds });
|
|
656
946
|
await ctx?.onListAllDocumentation?.({
|
|
657
947
|
context: ctx,
|
|
@@ -671,20 +961,28 @@ async function addListAllDocumentationTool(server, enabled) {
|
|
|
671
961
|
//#endregion
|
|
672
962
|
//#region src/tools/get-documentation-for-story.ts
|
|
673
963
|
const GET_STORY_TOOL_NAME = "get-documentation-for-story";
|
|
964
|
+
const GET_STORY_DOCUMENTATION_TOOL_DESCRIPTION = "Get detailed documentation for a specific story variant of a UI component. Use this when you need to see more usage examples of a component, via the stories written for it.";
|
|
674
965
|
const BaseInput$1 = {
|
|
675
966
|
componentId: v.string(),
|
|
676
967
|
storyName: v.string()
|
|
677
968
|
};
|
|
678
|
-
|
|
679
|
-
|
|
969
|
+
function getStoryDocumentationToolSchema(options) {
|
|
970
|
+
return options?.multiSource ? v.object({
|
|
680
971
|
...BaseInput$1,
|
|
681
972
|
...StorybookIdField
|
|
682
973
|
}) : v.object(BaseInput$1);
|
|
683
|
-
|
|
974
|
+
}
|
|
975
|
+
function getStoryDocumentationToolMetadata(options) {
|
|
976
|
+
return {
|
|
684
977
|
name: GET_STORY_TOOL_NAME,
|
|
685
978
|
title: "Get Documentation for Story",
|
|
686
|
-
description:
|
|
687
|
-
schema
|
|
979
|
+
description: GET_STORY_DOCUMENTATION_TOOL_DESCRIPTION,
|
|
980
|
+
schema: getStoryDocumentationToolSchema(options)
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
async function addGetStoryDocumentationTool(server, enabled, options) {
|
|
984
|
+
server.tool({
|
|
985
|
+
...getStoryDocumentationToolMetadata(options),
|
|
688
986
|
enabled
|
|
689
987
|
}, async (input) => {
|
|
690
988
|
try {
|
|
@@ -710,7 +1008,14 @@ async function addGetStoryDocumentationTool(server, enabled, options) {
|
|
|
710
1008
|
isError: true
|
|
711
1009
|
};
|
|
712
1010
|
}
|
|
713
|
-
|
|
1011
|
+
let component;
|
|
1012
|
+
if (ctx?.resolveEntry && !source?.url) {
|
|
1013
|
+
const resolved = await ctx.resolveEntry(componentId, source);
|
|
1014
|
+
if (resolved?.kind === "component") component = resolved.component;
|
|
1015
|
+
} else {
|
|
1016
|
+
const componentEntry = (await getManifests(ctx?.request, ctx?.manifestProvider, source)).componentManifest?.components[componentId];
|
|
1017
|
+
if (componentEntry) component = await resolveComponentEntry(componentEntry, ctx?.request, ctx?.manifestProvider, source);
|
|
1018
|
+
}
|
|
714
1019
|
if (!component) return {
|
|
715
1020
|
content: [{
|
|
716
1021
|
type: "text",
|
|
@@ -718,10 +1023,10 @@ async function addGetStoryDocumentationTool(server, enabled, options) {
|
|
|
718
1023
|
}],
|
|
719
1024
|
isError: true
|
|
720
1025
|
};
|
|
721
|
-
if (!component.stories
|
|
1026
|
+
if (!(Array.isArray(component.stories) ? component.stories.find((s) => s.name === storyName) : void 0)) return {
|
|
722
1027
|
content: [{
|
|
723
1028
|
type: "text",
|
|
724
|
-
text: `Story "${storyName}" not found for component "${componentId}". Available stories: ${component.stories
|
|
1029
|
+
text: `Story "${storyName}" not found for component "${componentId}". Available stories: ${Array.isArray(component.stories) ? component.stories.map((s) => s.name).join(", ") : "none"}`
|
|
725
1030
|
}],
|
|
726
1031
|
isError: true
|
|
727
1032
|
};
|
|
@@ -739,20 +1044,28 @@ async function addGetStoryDocumentationTool(server, enabled, options) {
|
|
|
739
1044
|
//#region src/tools/get-documentation.ts
|
|
740
1045
|
const GET_TOOL_NAME = "get-documentation";
|
|
741
1046
|
const BaseInput = { id: v.pipe(v.string(), v.description("The component or docs entry ID (e.g., \"button\")")) };
|
|
742
|
-
|
|
743
|
-
|
|
1047
|
+
const GET_DOCUMENTATION_TOOL_DESCRIPTION = `Get documentation for a UI component or docs entry.
|
|
1048
|
+
|
|
1049
|
+
Returns the first ${MAX_STORIES_TO_SHOW} stories (including story IDs) with code snippets showing how props are used, plus TypeScript prop definitions. Call this before using a component to avoid hallucinating prop names, types, or valid combinations, and to answer any question about a component's props, API, or usage — reading or grepping the component source is not a substitute. Stories reveal real prop usage patterns, interactions, and edge cases that type definitions alone don't show. If the example stories don't show the prop you need, use the ${GET_STORY_TOOL_NAME} tool to fetch the story documentation for the specific story variant you need.
|
|
1050
|
+
|
|
1051
|
+
Example: id="button" returns Primary, Secondary, Large stories with code like <Button variant="primary" size="large"> showing actual prop combinations.`;
|
|
1052
|
+
function getDocumentationToolSchema(options) {
|
|
1053
|
+
return options?.multiSource ? v.object({
|
|
744
1054
|
...BaseInput,
|
|
745
1055
|
...StorybookIdField
|
|
746
1056
|
}) : v.object(BaseInput);
|
|
747
|
-
|
|
1057
|
+
}
|
|
1058
|
+
function getDocumentationToolMetadata(options) {
|
|
1059
|
+
return {
|
|
748
1060
|
name: GET_TOOL_NAME,
|
|
749
1061
|
title: "Get Documentation",
|
|
750
|
-
description:
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
1062
|
+
description: GET_DOCUMENTATION_TOOL_DESCRIPTION,
|
|
1063
|
+
schema: getDocumentationToolSchema(options)
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
async function addGetDocumentationTool(server, enabled, options) {
|
|
1067
|
+
server.tool({
|
|
1068
|
+
...getDocumentationToolMetadata(options),
|
|
756
1069
|
enabled
|
|
757
1070
|
}, async (input) => {
|
|
758
1071
|
try {
|
|
@@ -778,9 +1091,19 @@ Example: id="button" returns Primary, Secondary, Large stories with code like <B
|
|
|
778
1091
|
isError: true
|
|
779
1092
|
};
|
|
780
1093
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1094
|
+
let component;
|
|
1095
|
+
let docsEntry;
|
|
1096
|
+
if (ctx?.resolveEntry && !source?.url) {
|
|
1097
|
+
const resolved = await ctx.resolveEntry(id, source);
|
|
1098
|
+
if (resolved?.kind === "component") component = resolved.component;
|
|
1099
|
+
else if (resolved?.kind === "doc") docsEntry = resolved.doc;
|
|
1100
|
+
} else {
|
|
1101
|
+
const { componentManifest, docsManifest } = await getManifests(ctx?.request, ctx?.manifestProvider, source);
|
|
1102
|
+
const componentEntry = componentManifest.components[id];
|
|
1103
|
+
const docEntry = docsManifest?.docs[id];
|
|
1104
|
+
if (componentEntry) component = await resolveComponentEntry(componentEntry, ctx?.request, ctx?.manifestProvider, source);
|
|
1105
|
+
else if (docEntry) docsEntry = await resolveDoc(docEntry, ctx?.request, ctx?.manifestProvider, source);
|
|
1106
|
+
}
|
|
784
1107
|
if (!component && !docsEntry) {
|
|
785
1108
|
const suffix = storybookId ? ` in source "${storybookId}"` : "";
|
|
786
1109
|
await ctx?.onGetDocumentation?.({
|
|
@@ -842,4 +1165,4 @@ const createStorybookMcpHandler = async (options = {}) => {
|
|
|
842
1165
|
};
|
|
843
1166
|
|
|
844
1167
|
//#endregion
|
|
845
|
-
export { COMPONENT_MANIFEST_PATH, ComponentManifestMap, DOCS_MANIFEST_PATH, DocsManifestMap, GET_STORY_TOOL_NAME, GET_TOOL_NAME, LIST_TOOL_NAME, instructions_default as STORYBOOK_MCP_INSTRUCTIONS, addGetDocumentationTool, addGetStoryDocumentationTool, addListAllDocumentationTool, createStorybookMcpHandler, getMultiSourceManifests };
|
|
1168
|
+
export { COMPONENT_MANIFEST_PATH, ComponentManifestMap, DOCS_MANIFEST_PATH, DocsManifestMap, GET_STORY_TOOL_NAME, GET_TOOL_NAME, LIST_TOOL_NAME, RequiresOwnMcpError, instructions_default as STORYBOOK_MCP_INSTRUCTIONS, adaptCoreComponent, adaptCoreDoc, adaptCoreStories, addGetDocumentationTool, addGetStoryDocumentationTool, addListAllDocumentationTool, createStorybookMcpHandler, getDocumentationToolMetadata, getListAllDocumentationToolMetadata, getMultiSourceManifests, getStoryDocumentationToolMetadata, resolveComponentEntry, resolveComponentStories, resolveDoc };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region src/instructions.md
|
|
2
|
+
var instructions_default = "## Documentation Workflow\n\n**CRITICAL: Never hallucinate component properties!** Before using ANY property on a component (even common-sounding ones like `shadow`), you MUST verify it is documented via these tools. If it is not documented, it does not exist — never assume props from naming conventions or other libraries; report it to the user instead.\n\n1. Call **list-all-documentation** once at the start of the task to discover available component and docs IDs.\n2. Call **get-documentation** with an `id` from that list to retrieve full component docs, props, usage examples, and stories.\n3. Call **get-documentation-for-story** for extra docs on a story variant not covered by the component docs.\n\nOnly use properties explicitly documented or shown in example stories. Only reference IDs returned by these tools; never guess IDs.\n\n## Multi-Source Requests\n\n- With multiple sources configured, **list-all-documentation** returns entries from every source; pass `storybookId` to **get-documentation** to scope one.\n";
|
|
3
|
+
|
|
4
|
+
//#endregion
|
|
5
|
+
export { instructions_default as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tmcp/adapter-valibot": "^0.1.5",
|
|
29
29
|
"@tmcp/transport-http": "^0.8.5",
|
|
30
|
-
"tmcp": "^1.19.
|
|
30
|
+
"tmcp": "^1.19.4",
|
|
31
31
|
"valibot": "1.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tmcp/transport-stdio": "^0.4.
|
|
34
|
+
"@tmcp/transport-stdio": "^0.4.3",
|
|
35
35
|
"react-docgen": "^8.0.2",
|
|
36
36
|
"react-docgen-typescript": "^2.4.0",
|
|
37
37
|
"srvx": "^0.8.16",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
//#region src/instructions.md
|
|
2
|
-
var instructions_default = "## Documentation Workflow\n\n1. Call **list-all-documentation** once at the start of the task to discover available component and docs IDs.\n2. Call **get-documentation** with an `id` from that list to retrieve full component docs, props, usage examples, and stories.\n3. Call **get-documentation-for-story** when you need additional docs from a specific story variant that was not included in the initial component documentation.\n\nUse `withStoryIds: true` on **list-all-documentation** when you also need story IDs for inputs to other tools.\n\n## Verification Rules\n\n- Never assume component props, variants, or API shape. Retrieve documentation before using a component.\n- If a component or prop is not documented, do not invent it. Report that it was not found.\n- Only reference IDs returned by **list-all-documentation**. Do not guess IDs.\n\n## Multi-Source Requests\n\n- When multiple Storybook sources are configured, **list-all-documentation** returns entries from all sources.\n- Use `storybookId` in **get-documentation** when you need to scope a request to one source.\n";
|
|
3
|
-
|
|
4
|
-
//#endregion
|
|
5
|
-
export { instructions_default as t };
|