@storybook/mcp 10.6.0-alpha.6 → 10.6.0-alpha.8

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 CHANGED
@@ -6,6 +6,11 @@ Learn more about Storybook at [storybook.js.org](https://storybook.js.org/?ref=r
6
6
 
7
7
  ## Self-hosting `@storybook/mcp`
8
8
 
9
+ This package is a library: the tarball ships one module and no executable. It declares no `bin`,
10
+ starts no process, and has no CLI. You register its tools on an MCP server you own, using the
11
+ snippets below. If you want a running Storybook MCP server with no code at all, use the dev server
12
+ instead — `storybook dev` serves one at `/mcp` through `@storybook/addon-mcp`.
13
+
9
14
  ### Prerequisites
10
15
 
11
16
  - Node.js 20+
@@ -15,7 +20,10 @@ Learn more about Storybook at [storybook.js.org](https://storybook.js.org/?ref=r
15
20
 
16
21
  ### Example implementation
17
22
 
18
- In-repo local server: [`serve.ts`](./serve.ts) (Node process that loads manifests from a directory or URL).
23
+ The Storybook repository has a local HTTP server built on this package,
24
+ [`serve.ts`](https://github.com/storybookjs/storybook/blob/next/code/lib/mcp/serve.ts), that loads
25
+ manifests from a directory or URL. It is a development harness and is not part of the published
26
+ package.
19
27
 
20
28
  The snippets below cover the common self-hosting patterns.
21
29
 
package/dist/index.d.ts CHANGED
@@ -50,6 +50,8 @@ declare const ComponentManifestV0: v.ObjectSchema<{
50
50
  readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
51
51
  readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
52
52
  readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
53
+ readonly apiDescription: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
54
+ readonly renderer: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
53
55
  readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
54
56
  readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
55
57
  readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
@@ -77,6 +79,8 @@ declare const ComponentManifestV0: v.ObjectSchema<{
77
79
  readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
78
80
  readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
79
81
  readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
82
+ readonly apiDescription: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
83
+ readonly renderer: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
80
84
  readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
81
85
  readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
82
86
  readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
@@ -171,6 +175,8 @@ declare const ComponentManifestMap: v.VariantSchema<"v", [v.ObjectSchema<{
171
175
  readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
172
176
  readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
173
177
  readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
178
+ readonly apiDescription: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
179
+ readonly renderer: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
174
180
  readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
175
181
  readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
176
182
  readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
@@ -198,6 +204,8 @@ declare const ComponentManifestMap: v.VariantSchema<"v", [v.ObjectSchema<{
198
204
  readonly path: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
199
205
  readonly summary: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
200
206
  readonly import: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
207
+ readonly apiDescription: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
208
+ readonly renderer: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
201
209
  readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
202
210
  readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
203
211
  readonly reactComponentMeta: v.OptionalSchema<v.AnySchema, undefined>;
@@ -500,9 +508,9 @@ interface StoryDoc {
500
508
  description?: string;
501
509
  summary?: string;
502
510
  /**
503
- * Why the snippet is an incomplete example: what a static pass could not resolve, in the source
504
- * text it was written as. A story that carries this still carries a `snippet`; an `error` means
505
- * there is no snippet at all.
511
+ * What a static pass could not resolve, in the source text it was written as. Next to a
512
+ * `snippet` it marks the example as partial; on its own it says why no static snippet could be
513
+ * produced at all. An `error` means the provider itself failed.
506
514
  */
507
515
  warning?: string;
508
516
  error?: StoryDocsError;
@@ -533,6 +541,14 @@ interface DocgenPayload {
533
541
  jsDocTags: DocgenJsDocTags;
534
542
  /** Renderer-converted argTypes derived from integration-specific docgen data at write time. */
535
543
  argTypes?: StrictArgTypes;
544
+ /**
545
+ * Framework-authored API documentation in Markdown, rendered verbatim in place of the props
546
+ * section. Prefer `##` level headings for sections (Inputs, Outputs, Props, Events, Slots) and TS
547
+ * types for structured data.
548
+ */
549
+ apiDescription?: string;
550
+ /** Renderer id (e.g. `angular`), so a consumer knows which template syntax the component takes. */
551
+ renderer?: string;
536
552
  subcomponents?: Record<string, DocgenSubcomponent>;
537
553
  error?: DocgenError;
538
554
  [key: string]: unknown;
@@ -547,6 +563,10 @@ interface DocgenSubcomponent {
547
563
  jsDocTags: DocgenJsDocTags;
548
564
  /** Renderer-converted argTypes derived from integration-specific docgen data at write time. */
549
565
  argTypes?: StrictArgTypes;
566
+ /** See {@link DocgenPayload.apiDescription}. */
567
+ apiDescription?: string;
568
+ /** See {@link DocgenPayload.renderer}. */
569
+ renderer?: string;
550
570
  error?: DocgenError;
551
571
  [key: string]: unknown;
552
572
  } //#endregion
@@ -568,8 +588,8 @@ type MdxDoc = {
568
588
  * Adapts the `experimentalDocgenServer` open-service payloads into the manifest formatter's
569
589
  * {@link ComponentManifest}/{@link Doc} shapes.
570
590
  *
571
- * Only `argTypes` is dropped: prop types still come from `reactComponentMeta` and
572
- * the `react*` docgen-engine fields, which are passed through unchanged.
591
+ * Only `argTypes` is dropped: the props section comes from `apiDescription` when the framework
592
+ * authored one, else from the `react*` docgen-engine fields. All of those pass through unchanged.
573
593
  */
574
594
  /**
575
595
  * A component assembled from the `core/docgen` payload plus the `core/story-docs` stories and
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_agl2fsgyaqs from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_agl2fsgyaqs from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_agl2fsgyaqs from "node:module";
1
+ import CJS_COMPAT_NODE_URL_k1lte63wj9c from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_k1lte63wj9c from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_k1lte63wj9c from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_agl2fsgyaqs.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_agl2fsgyaqs.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_agl2fsgyaqs.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_k1lte63wj9c.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_k1lte63wj9c.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_k1lte63wj9c.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -24,7 +24,7 @@ import { HttpTransport } from "@tmcp/transport-http";
24
24
  // package.json
25
25
  var package_default = {
26
26
  name: "@storybook/mcp",
27
- version: "10.6.0-alpha.6",
27
+ version: "10.6.0-alpha.8",
28
28
  description: "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
29
29
  keywords: [
30
30
  "mcp",
@@ -850,9 +850,10 @@ var parseReactDocgen = (reactDocgen) => {
850
850
  ])
851
851
  )
852
852
  };
853
- }, parseComponentDocLike = (componentDoc) => {
854
- let props = componentDoc.props ?? {};
855
- return {
853
+ }, tagValues = (value) => Array.isArray(value) ? value.flatMap(tagValues) : value == null ? [""] : [typeof value == "object" ? JSON.stringify(value) : String(value)], parseComponentDocLike = (componentDoc) => {
854
+ let props = componentDoc.props ?? {}, tags = Object.fromEntries(
855
+ Object.entries(componentDoc.tags ?? {}).map(([tagName, value]) => [tagName, tagValues(value)])
856
+ ), parsedDocgen = {
856
857
  props: Object.fromEntries(
857
858
  Object.entries(props).map(([propName, prop]) => [
858
859
  propName,
@@ -867,7 +868,20 @@ var parseReactDocgen = (reactDocgen) => {
867
868
  ])
868
869
  )
869
870
  };
870
- }, parseReactDocgenTypescript = (reactDocgenTypescript) => parseComponentDocLike(reactDocgenTypescript), parseReactComponentMeta = (reactComponentMeta) => parseComponentDocLike(reactComponentMeta), MAX_STORIES_TO_SHOW = 3;
871
+ return Object.keys(tags).length > 0 && (parsedDocgen.tags = tags), parsedDocgen;
872
+ }, parseReactDocgenTypescript = (reactDocgenTypescript) => parseComponentDocLike(reactDocgenTypescript), parseReactComponentMeta = (reactComponentMeta) => parseComponentDocLike(reactComponentMeta), MAX_STORIES_TO_SHOW = 3, TOP_JSDOC_TAG_NAMES = /* @__PURE__ */ new Set(["deprecated"]), EXAMPLE_JSDOC_TAG_NAME = "example", HIDDEN_JSDOC_TAG_NAMES = /* @__PURE__ */ new Set([
873
+ // Asks for the component to be hidden, so echoing it back is the opposite of the intent.
874
+ "ignore",
875
+ // Consumed by `extractComponentDescription` as the description, which is rendered on its own.
876
+ "desc",
877
+ "description",
878
+ // Storybook's own description override, consumed alongside `desc`.
879
+ "describe",
880
+ // Consumed into the `summary` field, which the component listing already prints.
881
+ "summary",
882
+ // Consumed into the import statement printed above every story snippet.
883
+ "import"
884
+ ]);
871
885
  function formatComponentLine(component) {
872
886
  let summary = component.summary ?? (component.description ? component.description.length > 90 ? `${component.description.slice(0, 90)}...` : component.description : void 0);
873
887
  return summary ? `- ${component.name} (${component.id}): ${summary}` : `- ${component.name} (${component.id})`;
@@ -893,6 +907,42 @@ function getParsedDocgen(componentManifest) {
893
907
  if (componentManifest.reactComponentMeta)
894
908
  return parseReactComponentMeta(componentManifest.reactComponentMeta);
895
909
  }
910
+ function getNonEmptyJsDocTags(jsDocTags) {
911
+ return jsDocTags && Object.keys(jsDocTags).length > 0 ? jsDocTags : void 0;
912
+ }
913
+ function getComponentTags(componentManifest, parsedDocgen) {
914
+ return getNonEmptyJsDocTags(componentManifest.jsDocTags) ?? parsedDocgen?.tags;
915
+ }
916
+ function formatTagName(tagName) {
917
+ return tagName.charAt(0).toUpperCase() + tagName.slice(1);
918
+ }
919
+ function formatJsDocTagBlockquote(tagName, values) {
920
+ let described = values.filter((value) => value.trim());
921
+ return (described.length > 0 ? described : [""]).flatMap((value) => {
922
+ let [firstLine, ...remainingLines] = value.trim().split(`
923
+ `), label = formatTagName(tagName);
924
+ return [
925
+ firstLine ? `> **${label}:** ${firstLine}` : `> **${label}**`,
926
+ ...remainingLines.map((line) => line ? `> ${line}` : ">")
927
+ ];
928
+ });
929
+ }
930
+ function isTopJsDocTag(tagName) {
931
+ return TOP_JSDOC_TAG_NAMES.has(tagName);
932
+ }
933
+ function isGenericJsDocTag(tagName) {
934
+ return !TOP_JSDOC_TAG_NAMES.has(tagName) && tagName !== EXAMPLE_JSDOC_TAG_NAME && !HIDDEN_JSDOC_TAG_NAMES.has(tagName);
935
+ }
936
+ function formatJsDocTags(jsDocTags, includeTag) {
937
+ let parts = [];
938
+ for (let [tagName, values] of Object.entries(jsDocTags ?? {}))
939
+ includeTag(tagName) && parts.push(...formatJsDocTagBlockquote(tagName, values));
940
+ return parts.length > 0 && parts.push(""), parts;
941
+ }
942
+ function formatExampleJsDocTags(jsDocTags) {
943
+ let examples = jsDocTags?.[EXAMPLE_JSDOC_TAG_NAME];
944
+ return !examples || examples.length === 0 ? [] : examples.flatMap((example) => ["**Example:**", "```", example, "```", ""]);
945
+ }
896
946
  function formatStoryContent(story, importStatement) {
897
947
  let parts = [];
898
948
  return story.description && (parts.push(story.description), parts.push("")), parts.push("```"), importStatement && (parts.push(importStatement), parts.push("")), parts.push(story.snippet ?? ""), parts.push("```"), parts;
@@ -911,32 +961,46 @@ function formatPropsSection(parsedDocgen, options = {}) {
911
961
  }
912
962
  return parts.push("}"), parts.push("```"), parts.push(""), parts;
913
963
  }
964
+ var FENCE_LINE = /^\s*(?:```|~~~)/, HEADING_LINE = /^(#{1,4}) /;
965
+ function demoteHeadings(markdown) {
966
+ let inFence = !1;
967
+ return markdown.split(`
968
+ `).map((line) => FENCE_LINE.test(line) ? (inFence = !inFence, line) : inFence ? line : line.replace(HEADING_LINE, "##$1 ")).join(`
969
+ `);
970
+ }
914
971
  function formatSubcomponentsSection(subcomponents) {
915
972
  if (!subcomponents || Object.keys(subcomponents).length === 0)
916
973
  return [];
917
974
  let parts = [];
918
975
  parts.push("## Subcomponents"), parts.push("");
919
976
  for (let [key, subcomponent] of Object.entries(subcomponents)) {
920
- if (parts.push(`### ${subcomponent.name || key}`), parts.push(""), subcomponent.summary && (parts.push(subcomponent.summary), parts.push("")), subcomponent.description && (parts.push(subcomponent.description), parts.push("")), subcomponent.import && (parts.push("```"), parts.push(subcomponent.import), parts.push("```"), parts.push("")), subcomponent.error) {
977
+ let parsedDocgen = getParsedDocgen(subcomponent), jsDocTags = getComponentTags(subcomponent, parsedDocgen);
978
+ if (parts.push(`### ${subcomponent.name || key}`), parts.push(""), parts.push(...formatJsDocTags(jsDocTags, isTopJsDocTag)), subcomponent.summary && (parts.push(subcomponent.summary), parts.push("")), subcomponent.description && (parts.push(subcomponent.description), parts.push("")), parts.push(...formatJsDocTags(jsDocTags, isGenericJsDocTag)), parts.push(...formatExampleJsDocTags(jsDocTags)), subcomponent.import && (parts.push("```"), parts.push(subcomponent.import), parts.push("```"), parts.push("")), subcomponent.error) {
921
979
  parts.push(`Error: ${subcomponent.error.name}`), parts.push(""), parts.push("```"), parts.push(subcomponent.error.message), parts.push("```"), parts.push("");
922
980
  continue;
923
981
  }
924
- let parsedDocgen = getParsedDocgen(subcomponent), typeName = `${(subcomponent.name || key).replace(/\W+/g, "")}Props`;
982
+ if (subcomponent.apiDescription) {
983
+ parts.push(demoteHeadings(subcomponent.apiDescription)), parts.push("");
984
+ continue;
985
+ }
986
+ let typeName = `${(subcomponent.name || key).replace(/\W+/g, "")}Props`;
925
987
  parts.push(...formatPropsSection(parsedDocgen, { title: "#### Props", typeName }));
926
988
  }
927
989
  return parts;
928
990
  }
929
991
  function formatComponentManifest(componentManifest) {
930
- let parts = [];
931
- parts.push(`# ${componentManifest.name}`), parts.push(""), parts.push(`ID: ${componentManifest.id}`), parts.push(""), componentManifest.description && (parts.push(componentManifest.description), parts.push("")), parts.push(...formatSubcomponentsSection(componentManifest.subcomponents));
932
- let parsedDocgen = getParsedDocgen(componentManifest), stories = Array.isArray(componentManifest.stories) ? componentManifest.stories : [];
992
+ let parts = [], parsedDocgen = getParsedDocgen(componentManifest), jsDocTags = getComponentTags(componentManifest, parsedDocgen);
993
+ parts.push(`# ${componentManifest.name}`), parts.push(""), parts.push(`ID: ${componentManifest.id}`), parts.push(""), parts.push(...formatJsDocTags(jsDocTags, isTopJsDocTag)), componentManifest.description && (parts.push(componentManifest.description), parts.push("")), parts.push(...formatJsDocTags(jsDocTags, isGenericJsDocTag)), parts.push(...formatExampleJsDocTags(jsDocTags)), parts.push(...formatSubcomponentsSection(componentManifest.subcomponents));
994
+ let { apiDescription } = componentManifest;
995
+ apiDescription && (parts.push(apiDescription), parts.push(""));
996
+ let stories = Array.isArray(componentManifest.stories) ? componentManifest.stories : [];
933
997
  if (stories.length > 0) {
934
998
  parts.push("## Stories"), parts.push("");
935
- let storiesWithSnippets = stories.filter((s) => s.snippet), hasProps = parsedDocgen && Object.keys(parsedDocgen.props).length > 0, storiesToShow = hasProps ? storiesWithSnippets.slice(0, MAX_STORIES_TO_SHOW) : storiesWithSnippets, remainingStories = hasProps ? storiesWithSnippets.slice(MAX_STORIES_TO_SHOW) : [];
999
+ let storiesWithSnippets = stories.filter((s) => s.snippet), storiesToShow = apiDescription || parsedDocgen && Object.keys(parsedDocgen.props).length > 0 ? storiesWithSnippets.slice(0, MAX_STORIES_TO_SHOW) : storiesWithSnippets, shown = new Set(storiesToShow), remainingStories = stories.filter((story) => !shown.has(story));
936
1000
  for (let story of storiesToShow)
937
1001
  parts.push(`### ${story.name}`), parts.push(""), story.id && (parts.push(`Story ID: ${story.id}`), parts.push("")), parts.push(...formatStoryContent(story, componentManifest.import)), parts.push("");
938
1002
  if (remainingStories.length > 0) {
939
- storiesToShow.length > 0 && parts.push("### Other Stories"), parts.push("");
1003
+ storiesToShow.length > 0 && (parts.push("### Other Stories"), parts.push(""));
940
1004
  for (let story of remainingStories) {
941
1005
  let summary = extractSummary(story), summaryPart = summary ? `: ${summary}` : "", storyLabel = story.id ? `${story.name} (${story.id})` : story.name;
942
1006
  parts.push(`- ${storyLabel}${summaryPart}`);
@@ -944,7 +1008,7 @@ function formatComponentManifest(componentManifest) {
944
1008
  parts.push("");
945
1009
  }
946
1010
  }
947
- if (parts.push(...formatPropsSection(parsedDocgen)), componentManifest.docs && Object.keys(componentManifest.docs).length > 0) {
1011
+ if (apiDescription || parts.push(...formatPropsSection(parsedDocgen)), componentManifest.docs && Object.keys(componentManifest.docs).length > 0) {
948
1012
  let docsWithContent = Object.values(componentManifest.docs).filter(
949
1013
  (doc) => (doc.content ?? "").trim().length > 0
950
1014
  );
@@ -1011,11 +1075,12 @@ function formatMultiSourceManifestsToLists(sources, options = {}) {
1011
1075
  }
1012
1076
  function formatStoryDocumentation(componentManifest, storyName) {
1013
1077
  let story = Array.isArray(componentManifest.stories) ? componentManifest.stories.find((s) => s.name === storyName) : void 0;
1014
- if (!story || !story.snippet)
1078
+ if (!story)
1015
1079
  return "";
1016
1080
  let parts = [];
1017
- return parts.push(`# ${componentManifest.name} - ${story.name}`), parts.push(""), parts.push(...formatStoryContent(story, componentManifest.import)), parts.join(`
1018
- `).trim();
1081
+ return parts.push(`# ${componentManifest.name} - ${story.name}`), parts.push(""), story.snippet ? (parts.push(...formatStoryContent(story, componentManifest.import)), parts.join(`
1082
+ `).trim()) : (story.id && (parts.push(`Story ID: ${story.id}`), parts.push("")), story.description && (parts.push(story.description), parts.push("")), parts.push("No code snippet was extracted for this story."), parts.join(`
1083
+ `).trim());
1019
1084
  }
1020
1085
  var ARG_TYPES_KEY = "argTypes";
1021
1086
  function adaptCoreStories(stories) {
@@ -1059,6 +1124,9 @@ var JSDocTag = record(string(), array(string())), ManifestErrorSchema = object({
1059
1124
  path: optional(string()),
1060
1125
  summary: optional(string()),
1061
1126
  import: optional(string()),
1127
+ // Framework-authored Markdown, rendered in place of the props section derived from `react*`.
1128
+ apiDescription: optional(string()),
1129
+ renderer: optional(string()),
1062
1130
  // Mirrors the docgen-engine payloads, which the parsers narrow structurally at runtime.
1063
1131
  reactDocgen: optional(any()),
1064
1132
  reactDocgenTypescript: optional(any()),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/mcp",
3
- "version": "10.6.0-alpha.6",
3
+ "version": "10.6.0-alpha.8",
4
4
  "description": "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
5
5
  "keywords": [
6
6
  "mcp",
@@ -49,7 +49,7 @@
49
49
  "react-docgen": "^8.0.2",
50
50
  "react-docgen-typescript": "^2.4.0",
51
51
  "srvx": "^0.8.16",
52
- "storybook": "10.6.0-alpha.6",
52
+ "storybook": "10.6.0-alpha.8",
53
53
  "tinyexec": "^1.0.2",
54
54
  "typescript": "^6.0.3"
55
55
  },