@storybook/mcp 0.3.0 → 0.4.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 +10 -0
- package/dist/index.js +26 -4
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "tmcp";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
import { Documentation } from "react-docgen";
|
|
4
|
+
import { ComponentDoc } from "react-docgen-typescript";
|
|
4
5
|
|
|
5
6
|
//#region src/types.d.ts
|
|
6
7
|
/**
|
|
@@ -94,6 +95,13 @@ declare const Doc: v.ObjectSchema<{
|
|
|
94
95
|
}, undefined>, undefined>;
|
|
95
96
|
}, undefined>;
|
|
96
97
|
type Doc = v.InferOutput<typeof Doc>;
|
|
98
|
+
/**
|
|
99
|
+
* Component documentation from react-docgen-typescript, extended with export name.
|
|
100
|
+
* Matches the shape produced by Storybook's manifest generator.
|
|
101
|
+
*/
|
|
102
|
+
type ComponentDocWithExportName = ComponentDoc & {
|
|
103
|
+
exportName: string;
|
|
104
|
+
};
|
|
97
105
|
declare const ComponentManifest: v.ObjectSchema<{
|
|
98
106
|
readonly id: v.StringSchema<undefined>;
|
|
99
107
|
readonly path: v.StringSchema<undefined>;
|
|
@@ -112,6 +120,7 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
112
120
|
}, undefined>, undefined>;
|
|
113
121
|
}, undefined>, undefined>, undefined>;
|
|
114
122
|
readonly reactDocgen: v.OptionalSchema<v.CustomSchema<Documentation, undefined>, undefined>;
|
|
123
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.CustomSchema<ComponentDocWithExportName, undefined>, undefined>;
|
|
115
124
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
116
125
|
readonly id: v.StringSchema<undefined>;
|
|
117
126
|
readonly name: v.StringSchema<undefined>;
|
|
@@ -153,6 +162,7 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
153
162
|
}, undefined>, undefined>;
|
|
154
163
|
}, undefined>, undefined>, undefined>;
|
|
155
164
|
readonly reactDocgen: v.OptionalSchema<v.CustomSchema<Documentation, undefined>, undefined>;
|
|
165
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.CustomSchema<ComponentDocWithExportName, undefined>, undefined>;
|
|
156
166
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
157
167
|
readonly id: v.StringSchema<undefined>;
|
|
158
168
|
readonly name: v.StringSchema<undefined>;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as v from "valibot";
|
|
|
5
5
|
|
|
6
6
|
//#region package.json
|
|
7
7
|
var name = "@storybook/mcp";
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.4.0";
|
|
9
9
|
var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
@@ -48,6 +48,7 @@ const ComponentManifest = v.object({
|
|
|
48
48
|
import: v.optional(v.string()),
|
|
49
49
|
stories: v.optional(v.array(Story)),
|
|
50
50
|
reactDocgen: v.optional(v.custom(() => true)),
|
|
51
|
+
reactDocgenTypescript: v.optional(v.custom(() => true)),
|
|
51
52
|
docs: v.optional(v.record(v.string(), Doc))
|
|
52
53
|
});
|
|
53
54
|
const ComponentManifestMap = v.object({
|
|
@@ -254,6 +255,20 @@ const parseReactDocgen = (reactDocgen) => {
|
|
|
254
255
|
required: prop.required
|
|
255
256
|
}])) };
|
|
256
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* Parse react-docgen-typescript output into the same simplified ParsedDocgen format.
|
|
260
|
+
* RDT uses flat type strings (prop.type.name / prop.type.raw) instead of react-docgen's
|
|
261
|
+
* nested tsType structure, so no serialization is needed.
|
|
262
|
+
*/
|
|
263
|
+
const parseReactDocgenTypescript = (reactDocgenTypescript) => {
|
|
264
|
+
const props = reactDocgenTypescript.props ?? {};
|
|
265
|
+
return { props: Object.fromEntries(Object.entries(props).map(([propName, prop]) => [propName, {
|
|
266
|
+
description: prop.description || void 0,
|
|
267
|
+
type: prop.type?.raw ?? prop.type?.name,
|
|
268
|
+
defaultValue: prop.defaultValue?.value,
|
|
269
|
+
required: prop.required
|
|
270
|
+
}])) };
|
|
271
|
+
};
|
|
257
272
|
|
|
258
273
|
//#endregion
|
|
259
274
|
//#region src/utils/dedent.ts
|
|
@@ -357,6 +372,13 @@ function extractSummary(item, maxLength = MAX_SUMMARY_LENGTH) {
|
|
|
357
372
|
if (item.description) return item.description.length > maxLength ? `${item.description.slice(0, maxLength)}...` : item.description;
|
|
358
373
|
}
|
|
359
374
|
/**
|
|
375
|
+
* Extract parsed docgen from a component manifest, preferring reactDocgen over reactDocgenTypescript.
|
|
376
|
+
*/
|
|
377
|
+
function getParsedDocgen(componentManifest) {
|
|
378
|
+
if (componentManifest.reactDocgen) return parseReactDocgen(componentManifest.reactDocgen);
|
|
379
|
+
if (componentManifest.reactDocgenTypescript) return parseReactDocgenTypescript(componentManifest.reactDocgenTypescript);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
360
382
|
* Formats a story's content (description + code snippet) into markdown.
|
|
361
383
|
* Reusable helper for both formatComponentManifest and formatStoryDocumentation.
|
|
362
384
|
*/
|
|
@@ -388,11 +410,12 @@ function formatComponentManifest(componentManifest) {
|
|
|
388
410
|
parts.push(componentManifest.description);
|
|
389
411
|
parts.push("");
|
|
390
412
|
}
|
|
413
|
+
const parsedDocgen = getParsedDocgen(componentManifest);
|
|
391
414
|
if (componentManifest.stories && componentManifest.stories.length > 0) {
|
|
392
415
|
parts.push("## Stories");
|
|
393
416
|
parts.push("");
|
|
394
417
|
const storiesWithSnippets = componentManifest.stories.filter((s) => s.snippet);
|
|
395
|
-
const hasProps =
|
|
418
|
+
const hasProps = parsedDocgen && Object.keys(parsedDocgen.props).length > 0;
|
|
396
419
|
const storiesToShow = hasProps ? storiesWithSnippets.slice(0, MAX_STORIES_TO_SHOW) : storiesWithSnippets;
|
|
397
420
|
const remainingStories = hasProps ? storiesWithSnippets.slice(MAX_STORIES_TO_SHOW) : [];
|
|
398
421
|
for (const story of storiesToShow) {
|
|
@@ -412,8 +435,7 @@ function formatComponentManifest(componentManifest) {
|
|
|
412
435
|
parts.push("");
|
|
413
436
|
}
|
|
414
437
|
}
|
|
415
|
-
if (
|
|
416
|
-
const parsedDocgen = parseReactDocgen(componentManifest.reactDocgen);
|
|
438
|
+
if (parsedDocgen) {
|
|
417
439
|
const propEntries = Object.entries(parsedDocgen.props);
|
|
418
440
|
if (propEntries.length > 0) {
|
|
419
441
|
parts.push("## Props");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@tmcp/transport-stdio": "^0.4.1",
|
|
35
35
|
"react-docgen": "^8.0.2",
|
|
36
|
+
"react-docgen-typescript": "^2.4.0",
|
|
36
37
|
"srvx": "^0.8.16",
|
|
37
38
|
"tinyexec": "^1.0.2"
|
|
38
39
|
},
|