@storybook/mcp 0.6.1 → 0.7.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/dist/index.d.ts +42 -10
- package/dist/index.js +90 -35
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -91,9 +91,6 @@ declare const Doc: v.ObjectSchema<{
|
|
|
91
91
|
type Doc = v.InferOutput<typeof Doc>;
|
|
92
92
|
declare const ComponentManifest: v.ObjectSchema<{
|
|
93
93
|
readonly id: v.StringSchema<undefined>;
|
|
94
|
-
readonly path: v.StringSchema<undefined>;
|
|
95
|
-
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
96
|
-
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
97
94
|
readonly stories: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
98
95
|
readonly id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
99
96
|
readonly snippet: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -106,8 +103,21 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
106
103
|
readonly message: v.StringSchema<undefined>;
|
|
107
104
|
}, undefined>, undefined>;
|
|
108
105
|
}, undefined>, undefined>, undefined>;
|
|
109
|
-
readonly
|
|
110
|
-
|
|
106
|
+
readonly subcomponents: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
107
|
+
readonly path: v.StringSchema<undefined>;
|
|
108
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
109
|
+
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
110
|
+
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
111
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
|
|
112
|
+
readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
|
|
113
|
+
readonly name: v.StringSchema<undefined>;
|
|
114
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
115
|
+
readonly jsDocTags: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
|
|
116
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
117
|
+
readonly name: v.StringSchema<undefined>;
|
|
118
|
+
readonly message: v.StringSchema<undefined>;
|
|
119
|
+
}, undefined>, undefined>;
|
|
120
|
+
}, undefined>, undefined>, undefined>;
|
|
111
121
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
112
122
|
readonly id: v.StringSchema<undefined>;
|
|
113
123
|
readonly name: v.StringSchema<undefined>;
|
|
@@ -120,6 +130,12 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
120
130
|
readonly message: v.StringSchema<undefined>;
|
|
121
131
|
}, undefined>, undefined>;
|
|
122
132
|
}, undefined>, undefined>, undefined>;
|
|
133
|
+
readonly path: v.StringSchema<undefined>;
|
|
134
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
135
|
+
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
136
|
+
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
137
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
|
|
138
|
+
readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
|
|
123
139
|
readonly name: v.StringSchema<undefined>;
|
|
124
140
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
125
141
|
readonly jsDocTags: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
|
|
@@ -133,9 +149,6 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
133
149
|
readonly v: v.NumberSchema<undefined>;
|
|
134
150
|
readonly components: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
135
151
|
readonly id: v.StringSchema<undefined>;
|
|
136
|
-
readonly path: v.StringSchema<undefined>;
|
|
137
|
-
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
138
|
-
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
139
152
|
readonly stories: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
140
153
|
readonly id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
141
154
|
readonly snippet: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -148,8 +161,21 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
148
161
|
readonly message: v.StringSchema<undefined>;
|
|
149
162
|
}, undefined>, undefined>;
|
|
150
163
|
}, undefined>, undefined>, undefined>;
|
|
151
|
-
readonly
|
|
152
|
-
|
|
164
|
+
readonly subcomponents: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
165
|
+
readonly path: v.StringSchema<undefined>;
|
|
166
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
167
|
+
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
168
|
+
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
169
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
|
|
170
|
+
readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
|
|
171
|
+
readonly name: v.StringSchema<undefined>;
|
|
172
|
+
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
173
|
+
readonly jsDocTags: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
|
|
174
|
+
readonly error: v.OptionalSchema<v.ObjectSchema<{
|
|
175
|
+
readonly name: v.StringSchema<undefined>;
|
|
176
|
+
readonly message: v.StringSchema<undefined>;
|
|
177
|
+
}, undefined>, undefined>;
|
|
178
|
+
}, undefined>, undefined>, undefined>;
|
|
153
179
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
154
180
|
readonly id: v.StringSchema<undefined>;
|
|
155
181
|
readonly name: v.StringSchema<undefined>;
|
|
@@ -162,6 +188,12 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
162
188
|
readonly message: v.StringSchema<undefined>;
|
|
163
189
|
}, undefined>, undefined>;
|
|
164
190
|
}, undefined>, undefined>, undefined>;
|
|
191
|
+
readonly path: v.StringSchema<undefined>;
|
|
192
|
+
readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
193
|
+
readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
194
|
+
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
195
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
|
|
196
|
+
readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
|
|
165
197
|
readonly name: v.StringSchema<undefined>;
|
|
166
198
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
167
199
|
readonly jsDocTags: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ 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.7.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
|
|
@@ -41,15 +41,21 @@ const Doc = v.object({
|
|
|
41
41
|
summary: v.optional(v.string()),
|
|
42
42
|
error: v.optional(Error$1)
|
|
43
43
|
});
|
|
44
|
-
const
|
|
44
|
+
const BaseComponentProperties = v.object({
|
|
45
45
|
...BaseManifest.entries,
|
|
46
|
-
id: v.string(),
|
|
47
46
|
path: v.string(),
|
|
48
47
|
summary: v.optional(v.string()),
|
|
49
48
|
import: v.optional(v.string()),
|
|
50
|
-
stories: v.optional(v.array(Story)),
|
|
51
49
|
reactDocgen: v.optional(v.any()),
|
|
52
50
|
reactDocgenTypescript: v.optional(v.any()),
|
|
51
|
+
reactComponentMeta: v.optional(v.any())
|
|
52
|
+
});
|
|
53
|
+
const SubcomponentManifest = v.object({ ...BaseComponentProperties.entries });
|
|
54
|
+
const ComponentManifest = v.object({
|
|
55
|
+
...BaseComponentProperties.entries,
|
|
56
|
+
id: v.string(),
|
|
57
|
+
stories: v.optional(v.array(Story)),
|
|
58
|
+
subcomponents: v.optional(v.record(v.string(), SubcomponentManifest)),
|
|
53
59
|
docs: v.optional(v.record(v.string(), Doc))
|
|
54
60
|
});
|
|
55
61
|
const ComponentManifestMap = v.object({
|
|
@@ -266,8 +272,8 @@ const parseReactDocgen = (reactDocgen) => {
|
|
|
266
272
|
* RDT uses flat type strings (prop.type.name / prop.type.raw) instead of react-docgen's
|
|
267
273
|
* nested tsType structure, so no serialization is needed.
|
|
268
274
|
*/
|
|
269
|
-
const
|
|
270
|
-
const props =
|
|
275
|
+
const parseComponentDocLike = (componentDoc) => {
|
|
276
|
+
const props = componentDoc.props ?? {};
|
|
271
277
|
return { props: Object.fromEntries(Object.entries(props).map(([propName, prop]) => [propName, {
|
|
272
278
|
description: prop.description || void 0,
|
|
273
279
|
type: prop.type?.raw ?? prop.type?.name,
|
|
@@ -275,6 +281,8 @@ const parseReactDocgenTypescript = (reactDocgenTypescript) => {
|
|
|
275
281
|
required: prop.required
|
|
276
282
|
}])) };
|
|
277
283
|
};
|
|
284
|
+
const parseReactDocgenTypescript = (reactDocgenTypescript) => parseComponentDocLike(reactDocgenTypescript);
|
|
285
|
+
const parseReactComponentMeta = (reactComponentMeta) => parseComponentDocLike(reactComponentMeta);
|
|
278
286
|
|
|
279
287
|
//#endregion
|
|
280
288
|
//#region src/utils/dedent.ts
|
|
@@ -381,11 +389,13 @@ function extractSummary(item, maxLength = MAX_SUMMARY_LENGTH) {
|
|
|
381
389
|
if (item.description) return item.description.length > maxLength ? `${item.description.slice(0, maxLength)}...` : item.description;
|
|
382
390
|
}
|
|
383
391
|
/**
|
|
384
|
-
* Extract parsed docgen from a component manifest, preferring reactDocgen over
|
|
392
|
+
* Extract parsed docgen from a component manifest, preferring reactDocgen over
|
|
393
|
+
* reactDocgenTypescript over reactComponentMeta.
|
|
385
394
|
*/
|
|
386
395
|
function getParsedDocgen(componentManifest) {
|
|
387
396
|
if (componentManifest.reactDocgen) return parseReactDocgen(componentManifest.reactDocgen);
|
|
388
397
|
if (componentManifest.reactDocgenTypescript) return parseReactDocgenTypescript(componentManifest.reactDocgenTypescript);
|
|
398
|
+
if (componentManifest.reactComponentMeta) return parseReactComponentMeta(componentManifest.reactComponentMeta);
|
|
389
399
|
}
|
|
390
400
|
/**
|
|
391
401
|
* Formats a story's content (description + code snippet) into markdown.
|
|
@@ -406,6 +416,77 @@ function formatStoryContent(story, importStatement) {
|
|
|
406
416
|
parts.push("```");
|
|
407
417
|
return parts;
|
|
408
418
|
}
|
|
419
|
+
function formatPropsSection(parsedDocgen, options = {}) {
|
|
420
|
+
const propEntries = parsedDocgen ? Object.entries(parsedDocgen.props) : [];
|
|
421
|
+
if (propEntries.length === 0) return [];
|
|
422
|
+
const title = options.title ?? "## Props";
|
|
423
|
+
const typeName = options.typeName ?? "Props";
|
|
424
|
+
const parts = [];
|
|
425
|
+
parts.push(title);
|
|
426
|
+
parts.push("");
|
|
427
|
+
parts.push("```");
|
|
428
|
+
parts.push(`export type ${typeName} = {`);
|
|
429
|
+
for (const [propName, propInfo] of propEntries) {
|
|
430
|
+
const type = propInfo.type ?? "any";
|
|
431
|
+
const isRequired = propInfo.required ?? true;
|
|
432
|
+
const hasDefault = propInfo.defaultValue !== void 0;
|
|
433
|
+
if (propInfo.description !== void 0) {
|
|
434
|
+
parts.push(" /**");
|
|
435
|
+
parts.push(` ${propInfo.description}`);
|
|
436
|
+
parts.push(" */");
|
|
437
|
+
}
|
|
438
|
+
let propLine = ` ${propName}`;
|
|
439
|
+
if (!isRequired) propLine += "?";
|
|
440
|
+
propLine += `: ${type}`;
|
|
441
|
+
if (hasDefault) propLine += ` = ${propInfo.defaultValue}`;
|
|
442
|
+
propLine += ";";
|
|
443
|
+
parts.push(propLine);
|
|
444
|
+
}
|
|
445
|
+
parts.push("}");
|
|
446
|
+
parts.push("```");
|
|
447
|
+
parts.push("");
|
|
448
|
+
return parts;
|
|
449
|
+
}
|
|
450
|
+
function formatSubcomponentsSection(subcomponents) {
|
|
451
|
+
if (!subcomponents || Object.keys(subcomponents).length === 0) return [];
|
|
452
|
+
const parts = [];
|
|
453
|
+
parts.push("## Subcomponents");
|
|
454
|
+
parts.push("");
|
|
455
|
+
for (const [key, subcomponent] of Object.entries(subcomponents)) {
|
|
456
|
+
parts.push(`### ${subcomponent.name || key}`);
|
|
457
|
+
parts.push("");
|
|
458
|
+
if (subcomponent.summary) {
|
|
459
|
+
parts.push(subcomponent.summary);
|
|
460
|
+
parts.push("");
|
|
461
|
+
}
|
|
462
|
+
if (subcomponent.description) {
|
|
463
|
+
parts.push(subcomponent.description);
|
|
464
|
+
parts.push("");
|
|
465
|
+
}
|
|
466
|
+
if (subcomponent.import) {
|
|
467
|
+
parts.push("```");
|
|
468
|
+
parts.push(subcomponent.import);
|
|
469
|
+
parts.push("```");
|
|
470
|
+
parts.push("");
|
|
471
|
+
}
|
|
472
|
+
if (subcomponent.error) {
|
|
473
|
+
parts.push(`Error: ${subcomponent.error.name}`);
|
|
474
|
+
parts.push("");
|
|
475
|
+
parts.push("```");
|
|
476
|
+
parts.push(subcomponent.error.message);
|
|
477
|
+
parts.push("```");
|
|
478
|
+
parts.push("");
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
const parsedDocgen = getParsedDocgen(subcomponent);
|
|
482
|
+
const typeName = `${(subcomponent.name || key).replace(/\W+/g, "")}Props`;
|
|
483
|
+
parts.push(...formatPropsSection(parsedDocgen, {
|
|
484
|
+
title: "#### Props",
|
|
485
|
+
typeName
|
|
486
|
+
}));
|
|
487
|
+
}
|
|
488
|
+
return parts;
|
|
489
|
+
}
|
|
409
490
|
/**
|
|
410
491
|
* Format a single component manifest into markdown.
|
|
411
492
|
*/
|
|
@@ -419,6 +500,7 @@ function formatComponentManifest(componentManifest) {
|
|
|
419
500
|
parts.push(componentManifest.description);
|
|
420
501
|
parts.push("");
|
|
421
502
|
}
|
|
503
|
+
parts.push(...formatSubcomponentsSection(componentManifest.subcomponents));
|
|
422
504
|
const parsedDocgen = getParsedDocgen(componentManifest);
|
|
423
505
|
if (componentManifest.stories && componentManifest.stories.length > 0) {
|
|
424
506
|
parts.push("## Stories");
|
|
@@ -449,34 +531,7 @@ function formatComponentManifest(componentManifest) {
|
|
|
449
531
|
parts.push("");
|
|
450
532
|
}
|
|
451
533
|
}
|
|
452
|
-
|
|
453
|
-
const propEntries = Object.entries(parsedDocgen.props);
|
|
454
|
-
if (propEntries.length > 0) {
|
|
455
|
-
parts.push("## Props");
|
|
456
|
-
parts.push("");
|
|
457
|
-
parts.push("```");
|
|
458
|
-
parts.push("export type Props = {");
|
|
459
|
-
for (const [propName, propInfo] of propEntries) {
|
|
460
|
-
const type = propInfo.type ?? "any";
|
|
461
|
-
const isRequired = propInfo.required ?? true;
|
|
462
|
-
const hasDefault = propInfo.defaultValue !== void 0;
|
|
463
|
-
if (propInfo.description !== void 0) {
|
|
464
|
-
parts.push(" /**");
|
|
465
|
-
parts.push(` ${propInfo.description}`);
|
|
466
|
-
parts.push(" */");
|
|
467
|
-
}
|
|
468
|
-
let propLine = ` ${propName}`;
|
|
469
|
-
if (!isRequired) propLine += "?";
|
|
470
|
-
propLine += `: ${type}`;
|
|
471
|
-
if (hasDefault) propLine += ` = ${propInfo.defaultValue}`;
|
|
472
|
-
propLine += ";";
|
|
473
|
-
parts.push(propLine);
|
|
474
|
-
}
|
|
475
|
-
parts.push("}");
|
|
476
|
-
parts.push("```");
|
|
477
|
-
parts.push("");
|
|
478
|
-
}
|
|
479
|
-
}
|
|
534
|
+
parts.push(...formatPropsSection(parsedDocgen));
|
|
480
535
|
if (componentManifest.docs && Object.keys(componentManifest.docs).length > 0) {
|
|
481
536
|
const docsWithContent = Object.values(componentManifest.docs).filter((doc) => doc.content.trim().length > 0);
|
|
482
537
|
if (docsWithContent.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tmcp/adapter-valibot": "^0.1.
|
|
29
|
-
"@tmcp/transport-http": "^0.8.
|
|
30
|
-
"tmcp": "^1.
|
|
28
|
+
"@tmcp/adapter-valibot": "^0.1.5",
|
|
29
|
+
"@tmcp/transport-http": "^0.8.5",
|
|
30
|
+
"tmcp": "^1.19.3",
|
|
31
31
|
"valibot": "1.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tmcp/transport-stdio": "^0.4.
|
|
34
|
+
"@tmcp/transport-stdio": "^0.4.2",
|
|
35
35
|
"react-docgen": "^8.0.2",
|
|
36
36
|
"react-docgen-typescript": "^2.4.0",
|
|
37
37
|
"srvx": "^0.8.16",
|