@storybook/mcp 11.0.0-beta.0 → 11.0.0-beta.2

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
@@ -333,6 +333,8 @@ await addGetStoryDocumentationTool(server);
333
333
 
334
334
  After registration, wire your own transport and pass `StorybookContext` per request so tools can resolve manifests (`request`, `manifestProvider`, and optional `sources`).
335
335
 
336
+ Each tool's input schema follows the `sources` of the request being served: when they compose several Storybooks (at least one source has a `url`), `docs-show` and `docs-show-story` take an optional `storybookId`; otherwise they do not. Pass `options.multiSource` to fix the shape at registration instead.
337
+
336
338
  #### `addListAllDocumentationTool`
337
339
 
338
340
  Type:
@@ -358,7 +360,7 @@ Type:
358
360
 
359
361
  Registers [documentation lookup](https://storybook.js.org/docs/next/ai/mcp/overview/#docs-show) by component/docs `id`.
360
362
 
361
- When `options.multiSource` is `true`, the tool schema takes an optional `storybookId` input, defaulting to `local`.
363
+ When `options.multiSource` is `true`, the tool schema takes an optional `storybookId` input, defaulting to `local`. When it is omitted, the schema follows the request's `sources`.
362
364
 
363
365
  #### `addGetStoryDocumentationTool`
364
366
 
package/dist/index.d.ts CHANGED
@@ -501,6 +501,56 @@ interface Args {
501
501
  [name: string]: any;
502
502
  }
503
503
  type StrictArgTypes<TArgs = Args> = { [name in keyof TArgs]: StrictInputType }; //#endregion
504
+ //#region code/core/.dts-emit/code/core/src/docs-tools/snippetTemplate.d.ts
505
+ /**
506
+ * The contract between a story-docs provider, which writes a story's `template`, and the preview,
507
+ * which fills it with the story's current args so its snippet follows the controls.
508
+ *
509
+ * A template is the story's static snippet split into segments: code as written, and holes. A hole
510
+ * is a place an arg prints, with the `text` the static snippet prints there. Joining every segment,
511
+ * with each hole's `text`, gives the static snippet; see {@link stripHoles}.
512
+ *
513
+ * {@link fillTemplate} prints a hole whose arg still holds its initial value as its `text`, so
514
+ * nothing the controls did not change moves. The renderer prints only a changed value, for the
515
+ * place its hole describes.
516
+ *
517
+ * Core does not know any place: a renderer types its own as a union of {@link HolePlace}s, and shares
518
+ * that type between its provider, which writes the holes, and its {@link PrintHole}, which prints
519
+ * them. A hole is flat: the place's own fields stand next to the fields core reads, `arg`, `spread`,
520
+ * `text` and `space`, which a place therefore does not use, such as
521
+ * `{ kind: 'attr', arg: 'label', text: ' label="Go"', space: ' ' }`.
522
+ */
523
+ type SnippetTemplate<Place extends HolePlace = HolePlace> = (string | TemplateHole<Place>)[];
524
+ /**
525
+ * Where a hole stands in a renderer's code, such as an attribute or a text node: its `kind` and the
526
+ * renderer's own fields for it, named other than `arg`, `spread`, `text` and `space`.
527
+ */
528
+ interface HolePlace {
529
+ /** Tells the renderer's places apart. */
530
+ kind: string;
531
+ }
532
+ /**
533
+ * A hole as its renderer prints it: its place, and which args it reads. A hole reads one `arg`, or,
534
+ * as a `spread` hole, every arg a control set, of which the renderer prints those the place does not
535
+ * print already.
536
+ */
537
+ type HoleRef<Place extends HolePlace = HolePlace> = Place & ({
538
+ arg: string;
539
+ spread?: never;
540
+ } | {
541
+ spread: true;
542
+ arg?: never;
543
+ });
544
+ /** A hole of a {@link SnippetTemplate}. */
545
+ type TemplateHole<Place extends HolePlace = HolePlace> = HoleRef<Place> & {
546
+ /** What the static snippet prints here, with the `space` before it, if any. */text: string;
547
+ /**
548
+ * Printed before what the renderer prints here, unless that is empty, such as the whitespace
549
+ * before an attribute, so a cleared attribute leaves no gap. It is part of `text` already: a hole
550
+ * whose `text` is empty gets it from its provider, any other one from {@link withHoleSpace}.
551
+ */
552
+ space?: string;
553
+ }; //#endregion
504
554
  //#region code/core/.dts-emit/code/core/src/shared/open-service/services/story-docs/types.d.ts
505
555
  /** Free-form error attached to a story snippet entry. */
506
556
  interface StoryDocsError {
@@ -517,10 +567,18 @@ interface StoryDoc {
517
567
  /**
518
568
  * What a static pass could not resolve, in the source text it was written as. Next to a
519
569
  * `snippet` it marks the example as partial; on its own it says why no static snippet could be
520
- * produced at all. An `error` means the provider itself failed.
570
+ * produced at all. A filled template leaves out the same code, so it is shown with it too. An
571
+ * `error` means the provider itself failed.
521
572
  */
522
573
  warning?: string;
523
574
  error?: StoryDocsError;
575
+ /**
576
+ * The static `snippet` split into code and holes, each a place an arg prints with what the
577
+ * snippet prints there; see `SnippetTemplate`. Joining its segments gives the snippet. Once the
578
+ * args differ from the story's initial args, the preview fills it through the renderer's
579
+ * `parameters.docs.source.printHole`, so the snippet follows the controls.
580
+ */
581
+ template?: SnippetTemplate;
524
582
  }
525
583
  /** Story docs keyed by story id for O(1) lookup and fine-grained open-service subscriptions. */
526
584
  type StoryDocsById = Record<string, StoryDoc>; //#endregion
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_czeu09dq2sh from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_czeu09dq2sh from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_czeu09dq2sh from "node:module";
1
+ import CJS_COMPAT_NODE_URL_13ic3rxdehgk from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_13ic3rxdehgk from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_13ic3rxdehgk from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_czeu09dq2sh.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_czeu09dq2sh.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_czeu09dq2sh.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_13ic3rxdehgk.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_13ic3rxdehgk.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_13ic3rxdehgk.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: "11.0.0-beta.0",
27
+ version: "11.0.0-beta.2",
28
28
  description: "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
29
29
  keywords: [
30
30
  "mcp",
@@ -91,7 +91,7 @@ function kebabCase(str) {
91
91
  return words(str).map((word) => word.toLowerCase()).join("-");
92
92
  }
93
93
 
94
- // ../../core/dist/_browser-chunks/chunk-QQVAH3EE.js
94
+ // ../../core/dist/_browser-chunks/chunk-FQ7UEN7J.js
95
95
  function parseToolsetMethodId(methodId) {
96
96
  let separator = methodId.indexOf(".");
97
97
  if (separator <= 0 || separator !== methodId.lastIndexOf(".") || separator === methodId.length - 1)
@@ -129,7 +129,7 @@ function getToolName(context) {
129
129
  };
130
130
  }
131
131
 
132
- // ../../core/dist/_browser-chunks/chunk-7OC3MZ62.js
132
+ // ../../core/dist/_browser-chunks/chunk-5IH5DW4C.js
133
133
  function defineToolset(definition) {
134
134
  for (let [methodName, method] of Object.entries(definition.methods)) {
135
135
  let input = method.input;
@@ -1083,7 +1083,7 @@ function formatSubcomponentsSection(subcomponents) {
1083
1083
  }
1084
1084
  return parts;
1085
1085
  }
1086
- function formatComponentManifest(componentManifest) {
1086
+ function formatComponentManifest(componentManifest, showStoryTool = "docs show-story") {
1087
1087
  let parts = [], parsedDocgen = getParsedDocgen(componentManifest), jsDocTags = getComponentTags(componentManifest, parsedDocgen);
1088
1088
  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));
1089
1089
  let { apiDescription } = componentManifest;
@@ -1095,7 +1095,9 @@ function formatComponentManifest(componentManifest) {
1095
1095
  for (let story of storiesToShow)
1096
1096
  parts.push(`### ${story.name}`), parts.push(""), story.id && (parts.push(`Story ID: ${story.id}`), parts.push("")), parts.push(...formatStoryContent(story, componentManifest.import)), parts.push("");
1097
1097
  if (remainingStories.length > 0) {
1098
- storiesToShow.length > 0 && (parts.push("### Other Stories"), parts.push(""));
1098
+ storiesToShow.length > 0 && (parts.push("### Other Stories"), parts.push("")), parts.push(
1099
+ `Get the code of one of these stories with the ${showStoryTool} tool and its story ID.`
1100
+ ), parts.push("");
1099
1101
  for (let story of remainingStories) {
1100
1102
  let summary = extractSummary(story), summaryPart = summary ? `: ${summary}` : "", storyLabel = story.id ? `${story.name} (${story.id})` : story.name;
1101
1103
  parts.push(`- ${storyLabel}${summaryPart}`);
@@ -1655,7 +1657,7 @@ function isDocsShowStoryError(output) {
1655
1657
  return kind !== "found" && kind !== "notice";
1656
1658
  }
1657
1659
  function describeList(ctx2) {
1658
- return `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 \u2014 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 ${getToolName(ctx2)(DOCS_METHOD_REFS.show)}, referencing only IDs returned here \u2014 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.`;
1660
+ return `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 \u2014 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 ${getToolName(ctx2)(DOCS_METHOD_REFS.show)}, referencing only IDs returned here \u2014 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 only when you need the story IDs of many components; the show tool already lists the story IDs of one component.`;
1659
1661
  }
1660
1662
  function describeShow(ctx2) {
1661
1663
  return `Get documentation for a UI component or docs entry.
@@ -1689,7 +1691,7 @@ function formatEntryNotFound({ id, storybookId, suggestions = [], unreadableSour
1689
1691
  ].join(`
1690
1692
  `);
1691
1693
  }
1692
- function formatResolvedElsewhere({ id, storybookId, resolvedStorybookId }, ctx2) {
1694
+ function formatResolvedElsewhere(id, { storybookId, resolvedStorybookId }, ctx2) {
1693
1695
  let scope = ctx2.transport === "cli" ? `--storybookId ${resolvedStorybookId}` : `storybookId "${resolvedStorybookId}"`;
1694
1696
  return `> "${id}" is not in source "${storybookId}"; showing it from source "${resolvedStorybookId}". Pass ${scope} on follow-up calls for this source.`;
1695
1697
  }
@@ -1702,8 +1704,11 @@ function renderShow(data, ctx2) {
1702
1704
  case "entry-missing":
1703
1705
  return formatEntryNotFound(data, ctx2);
1704
1706
  case "found": {
1705
- let documentation = resolution.entry.kind === "doc" ? formatDocsManifest(resolution.entry.doc) : formatComponentManifest(resolution.entry.component);
1706
- return data.resolvedStorybookId ? `${formatResolvedElsewhere(data, ctx2)}
1707
+ let documentation = resolution.entry.kind === "doc" ? formatDocsManifest(resolution.entry.doc) : formatComponentManifest(
1708
+ resolution.entry.component,
1709
+ getToolName(ctx2)(DOCS_METHOD_REFS.showStory)
1710
+ );
1711
+ return data.resolvedStorybookId ? `${formatResolvedElsewhere(data.id, data, ctx2)}
1707
1712
 
1708
1713
  ${documentation}` : documentation;
1709
1714
  }
@@ -1727,8 +1732,12 @@ function renderShowStory(resolution, data, ctx2) {
1727
1732
  let availableStories = formatAvailableStories(resolution.component.stories);
1728
1733
  return data.storyId !== void 0 ? `Story not found: "${data.storyId}" for component "${resolution.component.id}". Available stories: ${availableStories}` : `Story "${data.storyName}" not found for component "${data.componentId}". Available stories: ${availableStories}`;
1729
1734
  }
1730
- case "found":
1731
- return formatStoryDocumentation(resolution.component, resolution.story.name);
1735
+ case "found": {
1736
+ let documentation = formatStoryDocumentation(resolution.component, resolution.story.name);
1737
+ return data.resolvedStorybookId ? `${formatResolvedElsewhere(resolution.component.id, data, ctx2)}
1738
+
1739
+ ${documentation}` : documentation;
1740
+ }
1732
1741
  default:
1733
1742
  return resolution;
1734
1743
  }
@@ -1805,18 +1814,22 @@ function createDocsToolset(options) {
1805
1814
  }, showStorySchema = multiSource ? strictObject({ ...showStoryFields, ...storybookIdField }) : strictObject(showStoryFields), access = (storybookId, ctx2) => multiSource ? selectSource(sources, storybookId, ctx2) : { access: docsAccess }, sourceAccesses = multiSource ? sources.map(({ source, access: sourceAccess }) => ({
1806
1815
  storybookId: source.id,
1807
1816
  access: sourceAccess
1808
- })) : [{ access: docsAccess }], recoverMissedId = async (id, requestedStorybookId) => {
1809
- let others = sourceAccesses.filter((source) => source.storybookId !== requestedStorybookId), hits = (await Promise.all(
1810
- others.map(async (source) => ({
1811
- source,
1812
- entry: await source.access.resolve(id).catch(() => {
1817
+ })) : [{ access: docsAccess }], resolveInOtherSource = async (id, requestedStorybookId) => {
1818
+ let others = sourceAccesses.filter((source2) => source2.storybookId !== requestedStorybookId), hits = (await Promise.all(
1819
+ others.map(async (source2) => ({
1820
+ source: source2,
1821
+ entry: await source2.access.resolve(id).catch(() => {
1813
1822
  })
1814
1823
  }))
1815
- )).filter(({ entry }) => entry !== void 0);
1816
- if (hits.length === 1) {
1817
- let [{ source, entry }] = hits;
1818
- return { entry, resolvedStorybookId: source.storybookId };
1819
- }
1824
+ )).filter(({ entry: entry2 }) => entry2 !== void 0);
1825
+ if (hits.length !== 1)
1826
+ return;
1827
+ let [{ source, entry }] = hits;
1828
+ return { entry, resolvedStorybookId: source.storybookId };
1829
+ }, recoverMissedId = async (id, requestedStorybookId) => {
1830
+ let elsewhere = await resolveInOtherSource(id, requestedStorybookId);
1831
+ if (elsewhere)
1832
+ return elsewhere;
1820
1833
  let listings = await Promise.all(sourceAccesses.map(readEntries)), suggestions = suggestEntries(
1821
1834
  id,
1822
1835
  listings.flatMap(({ entries }) => entries).filter((entry) => entry.id !== id || entry.storybookId !== requestedStorybookId)
@@ -1838,7 +1851,7 @@ function createDocsToolset(options) {
1838
1851
  pipe(
1839
1852
  boolean(),
1840
1853
  description(
1841
- "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."
1854
+ "When true, includes story sub-bullets under each component with story name and story ID. This makes the list much longer: leave it off to look up components, and use it only to discover story IDs for downstream story-focused workflows without filesystem lookup."
1842
1855
  )
1843
1856
  ),
1844
1857
  !1
@@ -1889,11 +1902,14 @@ function createDocsToolset(options) {
1889
1902
  title: "Get Documentation for Story",
1890
1903
  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. Identify the story by its story ID (preferred), or by componentId plus storyName.",
1891
1904
  handler: async (input, ctx2) => {
1892
- let { storyId, componentId, storyName, storybookId } = input, request = { storyId, componentId, storyName, storybookId }, resolveId = storyId !== void 0 ? componentIdOfStoryId(storyId) : componentId !== void 0 && storyName !== void 0 ? componentId : void 0, selected = resolveId !== void 0 ? access(storybookId, ctx2) : {}, data = selected.access && resolveId !== void 0 ? { ...request, ...await resolveFromSource(selected.access, resolveId) } : { ...request, sourceError: selected.sourceError }, resolution = resolveShowStory(data), markdown = renderShowStory(resolution, data, ctx2), telemetry = {
1905
+ let { storyId, componentId, storyName, storybookId } = input, request = { storyId, componentId, storyName, storybookId }, resolveId = storyId !== void 0 ? componentIdOfStoryId(storyId) : componentId !== void 0 && storyName !== void 0 ? componentId : void 0, selected = resolveId !== void 0 ? access(storybookId, ctx2) : {}, data = selected.access && resolveId !== void 0 ? { ...request, ...await resolveFromSource(selected.access, resolveId) } : { ...request, sourceError: selected.sourceError };
1906
+ multiSource && resolveId !== void 0 && resolveShowStory(data).kind === "component-missing" && (data = { ...data, ...await resolveInOtherSource(resolveId, storybookId) });
1907
+ let resolution = resolveShowStory(data), markdown = renderShowStory(resolution, data, ctx2), telemetry = {
1893
1908
  payload: {
1894
1909
  found: resolution.kind === "found",
1895
1910
  storyId: resolution.kind === "found" ? resolution.story.id : storyId,
1896
1911
  lookup: storyId !== void 0 ? "storyId" : "name",
1912
+ resolvedElsewhere: data.resolvedStorybookId !== void 0,
1897
1913
  resultTokenCount: estimateTokens(markdown)
1898
1914
  }
1899
1915
  };
@@ -1947,9 +1963,12 @@ var LIST_TOOL_NAME = toMcpToolName("docs.list"), GET_TOOL_NAME = toMcpToolName("
1947
1963
  throw new Error("Open services are not available in a hosted Storybook.");
1948
1964
  }
1949
1965
  };
1966
+ function isComposition(sources) {
1967
+ return !!sources?.some((source) => source.url);
1968
+ }
1950
1969
  function getSources(context) {
1951
1970
  let sources = context?.sources;
1952
- if (sources?.some((source) => source.url))
1971
+ if (isComposition(sources))
1953
1972
  return createCompositionDocsSources({
1954
1973
  sources,
1955
1974
  manifestProvider: context?.manifestProvider,
@@ -1993,8 +2012,22 @@ function getDocumentationToolMetadata(options) {
1993
2012
  function getStoryDocumentationToolMetadata(options) {
1994
2013
  return toolMetadata("docs.showStory", !!options?.multiSource);
1995
2014
  }
1996
- function registerTool(server, metadata, handler) {
1997
- server.tool(metadata, handler);
2015
+ function requestMetadata(server, method, options) {
2016
+ let single = toolMetadata(method, !1), composed = toolMetadata(method, !0), current = () => options?.multiSource ?? isComposition(server.ctx.custom?.sources) ? composed : single, { name, title, description: description3 } = current();
2017
+ return {
2018
+ name,
2019
+ title,
2020
+ description: description3,
2021
+ get schema() {
2022
+ return current().schema;
2023
+ },
2024
+ get outputSchema() {
2025
+ return current().outputSchema;
2026
+ }
2027
+ };
2028
+ }
2029
+ function registerTool(server, metadata, enabled, handler) {
2030
+ enabled !== void 0 && Object.assign(metadata, { enabled }), server.tool(metadata, handler);
1998
2031
  }
1999
2032
  function outputSchemaOf(definition) {
2000
2033
  return definition.output;
@@ -2042,7 +2075,8 @@ async function call(server, method, input) {
2042
2075
  async function addListAllDocumentationTool(server, enabled, options) {
2043
2076
  registerTool(
2044
2077
  server,
2045
- { ...getListAllDocumentationToolMetadata(options), enabled },
2078
+ requestMetadata(server, "docs.list", options),
2079
+ enabled,
2046
2080
  async (input) => {
2047
2081
  let context = server.ctx.custom, { data, result } = await call(server, "list", input), listing = data, manifests = listing && selectReportedManifests(listing);
2048
2082
  return manifests && await context?.onListAllDocumentation?.({
@@ -2057,7 +2091,8 @@ async function addListAllDocumentationTool(server, enabled, options) {
2057
2091
  async function addGetDocumentationTool(server, enabled, options) {
2058
2092
  registerTool(
2059
2093
  server,
2060
- { ...getDocumentationToolMetadata(options), enabled },
2094
+ requestMetadata(server, "docs.show", options),
2095
+ enabled,
2061
2096
  async (input) => {
2062
2097
  let context = server.ctx.custom, { data, result } = await call(server, "show", input);
2063
2098
  if (data) {
@@ -2079,7 +2114,8 @@ async function addGetDocumentationTool(server, enabled, options) {
2079
2114
  async function addGetStoryDocumentationTool(server, enabled, options) {
2080
2115
  registerTool(
2081
2116
  server,
2082
- { ...getStoryDocumentationToolMetadata(options), enabled },
2117
+ requestMetadata(server, "docs.showStory", options),
2118
+ enabled,
2083
2119
  async (input) => (await call(server, "showStory", input)).result
2084
2120
  );
2085
2121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/mcp",
3
- "version": "11.0.0-beta.0",
3
+ "version": "11.0.0-beta.2",
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": "11.0.0-beta.0",
52
+ "storybook": "11.0.0-beta.2",
53
53
  "tinyexec": "^1.0.2",
54
54
  "typescript": "^6.0.3"
55
55
  },