@storybook/mcp 0.3.0 → 0.4.1

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 CHANGED
@@ -1,17 +1,13 @@
1
1
  import { McpServer } from "tmcp";
2
2
  import * as v from "valibot";
3
- import { Documentation } from "react-docgen";
4
3
 
5
4
  //#region src/types.d.ts
6
5
  /**
7
6
  * Represents a single Storybook source (local or remote).
8
7
  */
9
8
  type Source = {
10
- /** Unique identifier for this source (e.g., 'local', 'tetra') */
11
- id: string;
12
- /** Human-readable title (e.g., 'Local', 'Tetra Design System') */
13
- title: string;
14
- /** Remote URL, undefined for local source */
9
+ /** Unique identifier for this source (e.g., 'local', 'tetra') */id: string; /** Human-readable title (e.g., 'Local', 'Tetra Design System') */
10
+ title: string; /** Remote URL, undefined for local source */
15
11
  url?: string;
16
12
  };
17
13
  /**
@@ -20,8 +16,7 @@ type Source = {
20
16
  type SourceManifests = {
21
17
  source: Source;
22
18
  componentManifest: ComponentManifestMap;
23
- docsManifest?: DocsManifestMap;
24
- /** Error message if fetching this source failed */
19
+ docsManifest?: DocsManifestMap; /** Error message if fetching this source failed */
25
20
  error?: string;
26
21
  };
27
22
  /**
@@ -55,8 +50,7 @@ type StorybookContext = {
55
50
  onListAllDocumentation?: (params: {
56
51
  context: StorybookContext;
57
52
  manifests: AllManifests;
58
- resultText: string;
59
- /** Present in multi-source mode — all source manifests including errors */
53
+ resultText: string; /** Present in multi-source mode — all source manifests including errors */
60
54
  sources?: SourceManifests[];
61
55
  }) => void | Promise<void>;
62
56
  /**
@@ -111,7 +105,8 @@ declare const ComponentManifest: v.ObjectSchema<{
111
105
  readonly message: v.StringSchema<undefined>;
112
106
  }, undefined>, undefined>;
113
107
  }, undefined>, undefined>, undefined>;
114
- readonly reactDocgen: v.OptionalSchema<v.CustomSchema<Documentation, undefined>, undefined>;
108
+ readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
109
+ readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
115
110
  readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
116
111
  readonly id: v.StringSchema<undefined>;
117
112
  readonly name: v.StringSchema<undefined>;
@@ -152,7 +147,8 @@ declare const ComponentManifestMap: v.ObjectSchema<{
152
147
  readonly message: v.StringSchema<undefined>;
153
148
  }, undefined>, undefined>;
154
149
  }, undefined>, undefined>, undefined>;
155
- readonly reactDocgen: v.OptionalSchema<v.CustomSchema<Documentation, undefined>, undefined>;
150
+ readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
151
+ readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
156
152
  readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
157
153
  readonly id: v.StringSchema<undefined>;
158
154
  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.3.0";
8
+ var version = "0.4.1";
9
9
  var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
10
10
 
11
11
  //#endregion
@@ -47,7 +47,8 @@ const ComponentManifest = v.object({
47
47
  summary: v.optional(v.string()),
48
48
  import: v.optional(v.string()),
49
49
  stories: v.optional(v.array(Story)),
50
- reactDocgen: v.optional(v.custom(() => true)),
50
+ reactDocgen: v.optional(v.any()),
51
+ reactDocgenTypescript: v.optional(v.any()),
51
52
  docs: v.optional(v.record(v.string(), Doc))
52
53
  });
53
54
  const ComponentManifestMap = v.object({
@@ -106,11 +107,11 @@ const errorToMCPContent = (error) => {
106
107
  /**
107
108
  * Parses a JSON string and validates it against a Valibot schema
108
109
  */
109
- function parseManifest({ jsonString, schema, name: name$1, url }) {
110
+ function parseManifest({ jsonString, schema, name, url }) {
110
111
  try {
111
112
  return v.parse(v.pipe(v.string(), v.parseJson(), schema), jsonString);
112
113
  } catch (error) {
113
- throw new ManifestGetError(`Failed to parse ${name$1} manifest:
114
+ throw new ManifestGetError(`Failed to parse ${name} manifest:
114
115
  ${error instanceof v.ValiError ? error.issues.map((i) => i.message).join("\n") : String(error)}`, url);
115
116
  }
116
117
  }
@@ -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
@@ -286,8 +301,8 @@ function dedent(templ, ...values) {
286
301
  const endentations = string.match(/(?:^|\n)( *)$/);
287
302
  const endentation = endentations ? endentations[1] : "";
288
303
  let indentedValue = value;
289
- if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map((str, i$1) => {
290
- return i$1 === 0 ? str : `${endentation}${str}`;
304
+ if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map((str, i) => {
305
+ return i === 0 ? str : `${endentation}${str}`;
291
306
  }).join("\n");
292
307
  string += `${String(indentedValue)}${strings[i + 1]}`;
293
308
  });
@@ -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 = componentManifest.reactDocgen && Object.keys(componentManifest.reactDocgen.props ?? {}).length > 0;
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 (componentManifest.reactDocgen) {
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");
@@ -541,7 +563,7 @@ async function addListAllDocumentationTool(server, enabled) {
541
563
  const ctx = server.ctx.custom;
542
564
  if (ctx?.sources?.some((s) => s.url)) {
543
565
  const multiSourceManifests = await getMultiSourceManifests(ctx.sources, ctx.request, ctx.manifestProvider);
544
- const lists$1 = formatMultiSourceManifestsToLists(multiSourceManifests);
566
+ const lists = formatMultiSourceManifestsToLists(multiSourceManifests);
545
567
  const firstSuccess = multiSourceManifests.find((m) => !m.error);
546
568
  if (firstSuccess) await ctx.onListAllDocumentation?.({
547
569
  context: ctx,
@@ -549,12 +571,12 @@ async function addListAllDocumentationTool(server, enabled) {
549
571
  componentManifest: firstSuccess.componentManifest,
550
572
  docsManifest: firstSuccess.docsManifest
551
573
  },
552
- resultText: lists$1,
574
+ resultText: lists,
553
575
  sources: multiSourceManifests
554
576
  });
555
577
  return { content: [{
556
578
  type: "text",
557
- text: lists$1
579
+ text: lists
558
580
  }] };
559
581
  }
560
582
  const manifests = await getManifests(ctx?.request, ctx?.manifestProvider);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/mcp",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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
  },