@storybook/addon-mcp 11.0.0-beta.1 → 11.0.0-beta.3

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/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_rlwf2gdkln from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_rlwf2gdkln from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_rlwf2gdkln from "node:module";
1
+ import CJS_COMPAT_NODE_URL_bda14rmqte7 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_bda14rmqte7 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_bda14rmqte7 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_rlwf2gdkln.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_rlwf2gdkln.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_rlwf2gdkln.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_bda14rmqte7.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_bda14rmqte7.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_bda14rmqte7.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -18,7 +18,7 @@ import { HttpTransport } from "@tmcp/transport-http";
18
18
  // package.json
19
19
  var package_default = {
20
20
  name: "@storybook/addon-mcp",
21
- version: "11.0.0-beta.1",
21
+ version: "11.0.0-beta.3",
22
22
  description: "Help agents automatically write and test stories for your UI components",
23
23
  keywords: [
24
24
  "ai",
@@ -170,118 +170,6 @@ function withFriendlyErrors(schema) {
170
170
  };
171
171
  }
172
172
 
173
- // src/tools/get-storybook-story-instructions.ts
174
- import { resolveSkillInputs } from "storybook/internal/core-server";
175
- import { buildStoryInstructions } from "storybook/internal/skills";
176
-
177
- // src/utils/errors.ts
178
- var errorToMCPContent = (error) => ({
179
- content: [
180
- {
181
- type: "text",
182
- text: `Error: ${error instanceof Error ? error.message : String(error)}`
183
- }
184
- ],
185
- isError: !0
186
- });
187
-
188
- // src/tools/tool-names.ts
189
- import { toMcpToolName } from "storybook/open-service";
190
- var PREVIEW_STORIES_TOOL_NAME = toMcpToolName("stories.preview"), GET_CHANGED_STORIES_TOOL_NAME = toMcpToolName("stories.changed"), GET_STORIES_BY_COMPONENT_TOOL_NAME = toMcpToolName("stories.findByComponent"), RUN_STORY_TESTS_TOOL_NAME = toMcpToolName("test.run"), DISPLAY_REVIEW_TOOL_NAME = toMcpToolName("review.create"), GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME = "get-storybook-story-instructions";
191
-
192
- // src/tools/get-storybook-story-instructions.ts
193
- async function addGetUIBuildingInstructionsTool(server, enabled = () => server.ctx.custom?.toolsets?.dev ?? !0, {
194
- docsEnabled = !1,
195
- addonVitestAvailable = !1
196
- } = {}) {
197
- server.tool(
198
- {
199
- name: GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME,
200
- title: "Storybook Story Development Instructions",
201
- get description() {
202
- let testSupported = (server.ctx.custom?.toolsets?.test ?? !0) && addonVitestAvailable, a11yAvailable = testSupported && (server.ctx.custom?.a11yEnabled ?? !1);
203
- return getStorybookStoryInstructionsDescription({
204
- testSupported,
205
- a11yAvailable
206
- });
207
- },
208
- enabled
209
- },
210
- async () => {
211
- try {
212
- let { options, disableTelemetry: disableTelemetry2 } = server.ctx.custom ?? {};
213
- if (!options)
214
- throw new Error("Options are required in addon context");
215
- return disableTelemetry2 || await collectTelemetry({
216
- event: "tool:getUIBuildingInstructions",
217
- server,
218
- toolset: "dev"
219
- }), {
220
- content: [{ type: "text", text: await buildStorybookStoryInstructions(options, {
221
- toolsets: server.ctx.custom?.toolsets,
222
- a11yEnabled: server.ctx.custom?.a11yEnabled,
223
- addonVitestAvailable,
224
- docsEnabled
225
- }) }]
226
- };
227
- } catch (error) {
228
- return errorToMCPContent(error);
229
- }
230
- }
231
- );
232
- }
233
- function getStorybookStoryInstructionsDescription({
234
- testSupported,
235
- a11yAvailable
236
- }) {
237
- return `Get comprehensive instructions for writing, testing, and fixing Storybook stories (.stories.tsx, .stories.ts, .stories.jsx, .stories.js, .stories.svelte, .stories.vue files).
238
-
239
- CRITICAL: You MUST call this tool before:
240
- - Creating new Storybook stories or story files
241
- - Updating or modifying existing Storybook stories
242
- - Adding new story variants or exports to story files
243
- - Editing any file matching *.stories.* patterns
244
- - Writing components that will need stories
245
- - Editing anything that changes how the UI looks \u2014 components, styles, CSS, themes, colors, or design tokens; a shared file with no stories of its own still changes its consumers' stories${testSupported ? `
246
- - Running story tests or fixing test failures` : ""}${a11yAvailable ? `
247
- - Handling accessibility (a11y) violations in stories (fix semantic issues directly; ask before visual/design changes)` : ""}
248
-
249
- This tool provides essential Storybook-specific guidance including:
250
- - How to structure stories correctly for Storybook 9
251
- - Required imports (Meta, StoryObj from framework package)
252
- - Test utility imports (from 'storybook/test')
253
- - Story naming conventions and best practices
254
- - Play function patterns for interactive testing
255
- - Mocking strategies for external dependencies
256
- - Story variants and coverage requirements${testSupported ? `
257
- - How to handle test failures${a11yAvailable ? " and accessibility violations" : ""}` : ""}
258
-
259
- Even if you're familiar with Storybook, call this tool to ensure you're following the correct patterns, import paths, and conventions for this specific Storybook setup.`;
260
- }
261
- function getStorybookStoryInstructionsToolMetadata(options) {
262
- return {
263
- name: GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME,
264
- title: "Storybook Story Development Instructions",
265
- description: getStorybookStoryInstructionsDescription(options)
266
- };
267
- }
268
- async function buildStorybookStoryInstructions(options, {
269
- toolsets,
270
- a11yEnabled: a11yEnabled2,
271
- addonVitestAvailable,
272
- docsEnabled
273
- } = {}) {
274
- let inputs = await resolveSkillInputs(options);
275
- return buildStoryInstructions({
276
- transport: "mcp",
277
- framework: inputs.framework,
278
- renderer: inputs.renderer,
279
- testSupported: (toolsets?.test ?? !0) && (addonVitestAvailable ?? inputs.testSupported),
280
- a11yEnabled: a11yEnabled2 ?? inputs.a11yEnabled,
281
- docsEnabled: (toolsets?.docs ?? !0) && (docsEnabled ?? inputs.docsEnabled)
282
- });
283
- }
284
-
285
173
  // src/tools/preview-stories.ts
286
174
  import url from "node:url";
287
175
  import fs from "node:fs/promises";
@@ -361,6 +249,10 @@ var preview_stories_app_template_default = `<!doctype html>
361
249
  </html>
362
250
  `;
363
251
 
252
+ // src/tools/tool-names.ts
253
+ import { toMcpToolName } from "storybook/open-service";
254
+ var PREVIEW_STORIES_TOOL_NAME = toMcpToolName("stories.preview"), GET_CHANGED_STORIES_TOOL_NAME = toMcpToolName("stories.changed"), GET_STORIES_BY_COMPONENT_TOOL_NAME = toMcpToolName("stories.findByComponent"), RUN_STORY_TESTS_TOOL_NAME = toMcpToolName("test.run"), DISPLAY_REVIEW_TOOL_NAME = toMcpToolName("review.create");
255
+
364
256
  // src/tools/preview-stories.ts
365
257
  var PREVIEW_STORIES_RESOURCE_URI = `ui://${PREVIEW_STORIES_TOOL_NAME}/preview.html`;
366
258
  async function addPreviewStoriesResource(server) {
@@ -419,6 +311,17 @@ import {
419
311
  toMcpToolName as toMcpToolName2
420
312
  } from "storybook/open-service";
421
313
 
314
+ // src/utils/errors.ts
315
+ var errorToMCPContent = (error) => ({
316
+ content: [
317
+ {
318
+ type: "text",
319
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`
320
+ }
321
+ ],
322
+ isError: !0
323
+ });
324
+
422
325
  // src/utils/base-url.ts
423
326
  function toBaseUrl(origin, basePath) {
424
327
  return `${origin}${basePath.replace(/\/$/, "")}`;
@@ -576,21 +479,6 @@ var docsToolDefinitions = [
576
479
  extras: { _meta: { ui: { resourceUri: PREVIEW_STORIES_RESOURCE_URI } } }
577
480
  }
578
481
  }),
579
- {
580
- name: GET_UI_BUILDING_INSTRUCTIONS_TOOL_NAME,
581
- toolset: "dev",
582
- getMetadata: ({ availability, toolsets }) => {
583
- let testSupported = isToolsetEnabled("test", toolsets) && availability.testSupported;
584
- return getStorybookStoryInstructionsToolMetadata({
585
- testSupported,
586
- a11yAvailable: testSupported && availability.a11yEnabled
587
- });
588
- },
589
- register: (server, { availability, toolsets }, enabled) => addGetUIBuildingInstructionsTool(server, enabled, {
590
- docsEnabled: isToolsetEnabled("docs", toolsets) && availability.docsEnabled,
591
- addonVitestAvailable: availability.testSupported
592
- })
593
- },
594
482
  fromToolset({
595
483
  toolset: "dev",
596
484
  options: { method: "stories.changed", mcpEventName: "tool:getChangedStories" }
@@ -646,11 +534,9 @@ var transport, initialize, disableTelemetry, a11yEnabled, initializeMCPServer =
646
534
  adapter: new ValibotJsonSchemaAdapter(),
647
535
  get instructions() {
648
536
  return buildServerInstructions({
649
- transport: "mcp",
650
537
  devEnabled: server?.ctx.custom?.toolsets?.dev ?? !0,
651
538
  testSupported: (server?.ctx.custom?.toolsets?.test ?? !0) && availability.testSupported,
652
- docsEnabled: (server?.ctx.custom?.toolsets?.docs ?? !0) && availability.docsEnabled,
653
- moduleGraphSupported: availability.moduleGraphSupported
539
+ docsEnabled: (server?.ctx.custom?.toolsets?.docs ?? !0) && availability.docsEnabled
654
540
  });
655
541
  },
656
542
  capabilities: {
@@ -999,7 +885,6 @@ var template_default = `<!doctype html>
999
885
  </div>
1000
886
  <ul class="toolset-tools">
1001
887
  <li><code>stories-preview</code></li>
1002
- <li><code>get-storybook-story-instructions</code></li>
1003
888
  <li><code>stories-changed</code></li>
1004
889
  <li>
1005
890
  <code>stories-find-by-component</code>
@@ -1066,7 +951,7 @@ var OAuthResourceMetadata = v2.object({
1066
951
  constructor(url2) {
1067
952
  super(`Authentication failed for ${url2}. Your token may be invalid or expired.`), this.name = "AuthenticationError";
1068
953
  }
1069
- }, CompositionAuth = class {
954
+ }, REF_PROBE_TIMEOUT_MS = 3e3, CompositionAuth = class {
1070
955
  #authRequirement = null;
1071
956
  #authRequiredUrls = [];
1072
957
  #refsWithManifests = [];
@@ -1075,22 +960,30 @@ var OAuthResourceMetadata = v2.object({
1075
960
  #authErrors = /* @__PURE__ */ new WeakMap();
1076
961
  /** Initialize by checking which refs require authentication and have manifests. */
1077
962
  async initialize(refs) {
1078
- for (let ref of refs)
1079
- try {
1080
- let result = await this.#checkRef(ref.url);
1081
- if (result === "manifest-not-found") {
1082
- logger4.warn(
1083
- `[addon-mcp] Skipping composed ref "${ref.title}" (${ref.url}): components manifest not found at ${ref.url}/manifests/components.json. Enable the \`componentsManifest\` feature on that Storybook to compose it into MCP.`
1084
- );
1085
- continue;
1086
- }
1087
- if (result === "manifest-invalid") {
1088
- logger4.warn(
1089
- `[addon-mcp] Skipping composed ref "${ref.title}" (${ref.url}): its components manifest failed validation. This usually means a version mismatch between the composed Storybook and this one \u2014 upgrade the older side.`
1090
- );
1091
- continue;
1092
- }
1093
- if (this.#refsWithManifests.push(ref), result === "public") continue;
963
+ let outcomes = await Promise.allSettled(refs.map((ref) => this.#checkRef(ref.url)));
964
+ for (let [index, ref] of refs.entries()) {
965
+ let outcome = outcomes[index];
966
+ if (outcome.status === "rejected") {
967
+ let error = outcome.reason;
968
+ logger4.warn(
969
+ `[addon-mcp] Skipping composed ref "${ref.title}" (${ref.url}): the ref could not be reached (${error instanceof Error ? error.message : String(error)}). Refs are only checked at dev-server boot \u2014 restart Storybook once the ref is reachable.`
970
+ );
971
+ continue;
972
+ }
973
+ let result = outcome.value;
974
+ if (result === "manifest-not-found") {
975
+ logger4.warn(
976
+ `[addon-mcp] Skipping composed ref "${ref.title}" (${ref.url}): components manifest not found at ${ref.url}/manifests/components.json. Enable the \`componentsManifest\` feature on that Storybook to compose it into MCP.`
977
+ );
978
+ continue;
979
+ }
980
+ if (result === "manifest-invalid") {
981
+ logger4.warn(
982
+ `[addon-mcp] Skipping composed ref "${ref.title}" (${ref.url}): its components manifest failed validation. This usually means a version mismatch between the composed Storybook and this one \u2014 upgrade the older side.`
983
+ );
984
+ continue;
985
+ }
986
+ if (this.#refsWithManifests.push(ref), result !== "public")
1094
987
  if (this.#authRequiredUrls.push(ref.url), !this.#authRequirement)
1095
988
  this.#authRequirement = result;
1096
989
  else {
@@ -1099,11 +992,7 @@ var OAuthResourceMetadata = v2.object({
1099
992
  `[addon-mcp] Composed ref "${ref.title}" uses a different OAuth server (${newServer}) than the first authenticated ref (${existingServer}). Only the first OAuth server will be used for authentication.`
1100
993
  );
1101
994
  }
1102
- } catch (error) {
1103
- logger4.warn(
1104
- `[addon-mcp] Skipping composed ref "${ref.title}" (${ref.url}): the ref could not be reached (${error instanceof Error ? error.message : String(error)}). Refs are only checked at dev-server boot \u2014 restart Storybook once the ref is reachable.`
1105
- );
1106
- }
995
+ }
1107
996
  }
1108
997
  get requiresAuth() {
1109
998
  return this.#authRequiredUrls.length > 0;
@@ -1203,7 +1092,8 @@ var OAuthResourceMetadata = v2.object({
1203
1092
  */
1204
1093
  async #checkRef(refUrl) {
1205
1094
  let response = await fetch(`${refUrl}/manifests/components.json`, {
1206
- headers: { Accept: "application/json" }
1095
+ headers: { Accept: "application/json" },
1096
+ signal: AbortSignal.timeout(REF_PROBE_TIMEOUT_MS)
1207
1097
  }), authReq = await this.#parseAuthFromResponse(response);
1208
1098
  if (authReq) return authReq;
1209
1099
  let noManifestReason = "manifest-not-found";
@@ -1223,7 +1113,8 @@ var OAuthResourceMetadata = v2.object({
1223
1113
  let response = await fetch(`${refUrl}/mcp`, {
1224
1114
  method: "POST",
1225
1115
  headers: { "Content-Type": "application/json" },
1226
- body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })
1116
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }),
1117
+ signal: AbortSignal.timeout(REF_PROBE_TIMEOUT_MS)
1227
1118
  });
1228
1119
  return this.#parseAuthFromResponse(response);
1229
1120
  }
@@ -1233,7 +1124,8 @@ var OAuthResourceMetadata = v2.object({
1233
1124
  return (await fetch(`${origin}/mcp`, {
1234
1125
  method: "POST",
1235
1126
  headers: { "Content-Type": "application/json" },
1236
- body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })
1127
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }),
1128
+ signal: AbortSignal.timeout(REF_PROBE_TIMEOUT_MS)
1237
1129
  })).status === 401;
1238
1130
  } catch {
1239
1131
  return !1;
@@ -1246,7 +1138,9 @@ var OAuthResourceMetadata = v2.object({
1246
1138
  if (!wwwAuth) return null;
1247
1139
  let match = wwwAuth.match(/resource_metadata="([^"]+)"/);
1248
1140
  if (!match?.[1]) return null;
1249
- let resourceMetadataUrl = match[1], resourceResponse = await fetch(resourceMetadataUrl);
1141
+ let resourceMetadataUrl = match[1], resourceResponse = await fetch(resourceMetadataUrl, {
1142
+ signal: AbortSignal.timeout(REF_PROBE_TIMEOUT_MS)
1143
+ });
1250
1144
  if (!resourceResponse.ok)
1251
1145
  return logger4.warn(
1252
1146
  `[addon-mcp] Failed to fetch OAuth resource metadata from ${resourceMetadataUrl}: ${resourceResponse.status}`
@@ -1256,7 +1150,9 @@ var OAuthResourceMetadata = v2.object({
1256
1150
  return logger4.warn(
1257
1151
  `[addon-mcp] Invalid OAuth resource metadata from ${resourceMetadataUrl}: ${resourceResult.issues.map((i) => i.message).join(", ")}`
1258
1152
  ), null;
1259
- let serverMetadataUrl = `${resourceResult.output.authorization_servers[0]}/.well-known/oauth-authorization-server`, serverResponse = await fetch(serverMetadataUrl);
1153
+ let serverMetadataUrl = `${resourceResult.output.authorization_servers[0]}/.well-known/oauth-authorization-server`, serverResponse = await fetch(serverMetadataUrl, {
1154
+ signal: AbortSignal.timeout(REF_PROBE_TIMEOUT_MS)
1155
+ });
1260
1156
  if (!serverResponse.ok)
1261
1157
  return logger4.warn(
1262
1158
  `[addon-mcp] Failed to fetch OAuth server metadata from ${serverMetadataUrl}: ${serverResponse.status}`
@@ -1310,7 +1206,28 @@ async function getStoryIndex(options) {
1310
1206
  }
1311
1207
 
1312
1208
  // src/preset.ts
1313
- var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotations, path.join(import.meta.dirname, "preview.js")], experimental_devServer = async (app, options) => {
1209
+ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotations, path.join(import.meta.dirname, "preview.js")];
1210
+ function buildComposition({ refs, compositionAuth, sources, multiSource }, {
1211
+ options,
1212
+ baseUrl,
1213
+ rawAvailability
1214
+ }) {
1215
+ let localAccess = rawAvailability.docgenServer && refs.length > 0 ? createLocalDocsAccess({
1216
+ storyIndex: { getIndex: () => getStoryIndex(options) },
1217
+ getManifests: () => loadManifests(options.presets)
1218
+ }) : void 0;
1219
+ refs.length > 0 && (logger6.info(`Initialized composition with ${refs.length} remote Storybook(s)`), compositionAuth.requiresAuth && logger6.info(`Auth required for: ${compositionAuth.authUrls.join(", ")}`), logger6.info(`Sources: ${(sources ?? []).map((source) => source.id).join(", ")}`));
1220
+ let manifestProvider = refs.length > 0 ? compositionAuth.createManifestProvider(baseUrl) : void 0;
1221
+ return {
1222
+ sources,
1223
+ compositionAuth,
1224
+ manifestAccess: { manifestProvider, localAccess },
1225
+ // Same gates the MCP server uses to register these tools, so the page can't
1226
+ // claim a tool is available when it isn't (and vice versa).
1227
+ availability: getEffectiveToolAvailability2(rawAvailability, { multiSource })
1228
+ };
1229
+ }
1230
+ var experimental_devServer = async (app, options) => {
1314
1231
  let addonOptions = v3.parse(AddonOptions, {
1315
1232
  endpoint: options.endpoint,
1316
1233
  toolsets: options.toolsets ?? {}
@@ -1333,32 +1250,32 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1333
1250
  } catch {
1334
1251
  }
1335
1252
  return res.writeHead(403, { "Content-Type": "text/plain" }), res.end("Invalid origin"), !0;
1336
- }, rejectNonJsonBody = (req, res) => req.headers["content-type"]?.split(";")[0].trim().toLowerCase() === "application/json" ? !1 : (res.writeHead(415, { "Content-Type": "text/plain" }), res.end("Unsupported Media Type: Content-Type must be application/json"), !0), { refs, compositionAuth, sources, multiSource } = await resolveCompositionSources(options), rawAvailability = await getToolAvailability2(options), localAccess = rawAvailability.docgenServer && refs.length > 0 ? createLocalDocsAccess({
1337
- storyIndex: { getIndex: () => getStoryIndex(options) },
1338
- getManifests: () => loadManifests(options.presets)
1339
- }) : void 0, createManifestProvider;
1340
- refs.length > 0 && (logger6.info(`Initialized composition with ${refs.length} remote Storybook(s)`), compositionAuth.requiresAuth && logger6.info(`Auth required for: ${compositionAuth.authUrls.join(", ")}`), logger6.info(`Sources: ${(sources ?? []).map((s) => s.id).join(", ")}`), createManifestProvider = () => compositionAuth.createManifestProvider(baseUrl));
1341
- let manifestAccessFor = (req) => ({
1342
- manifestProvider: createManifestProvider?.(req),
1343
- localAccess
1344
- });
1345
- app.get("/.well-known/oauth-protected-resource", (_req, res) => {
1346
- let wellKnown = compositionAuth.buildWellKnown(`${baseUrl}${endpoint}`);
1253
+ }, rejectNonJsonBody = (req, res) => req.headers["content-type"]?.split(";")[0].trim().toLowerCase() === "application/json" ? !1 : (res.writeHead(415, { "Content-Type": "text/plain" }), res.end("Unsupported Media Type: Content-Type must be application/json"), !0), rawAvailability = await getToolAvailability2(options), composition = resolveCompositionSources(options).then(
1254
+ (resolved) => buildComposition(resolved, { options, baseUrl, rawAvailability })
1255
+ );
1256
+ composition.catch((error) => {
1257
+ logger6.error(
1258
+ `[addon-mcp] Composition setup failed: ${error instanceof Error ? error.message : String(error)}`
1259
+ );
1260
+ }), app.get("/.well-known/oauth-protected-resource", async (_req, res) => {
1261
+ let { compositionAuth } = await composition, wellKnown = compositionAuth.buildWellKnown(`${baseUrl}${endpoint}`);
1347
1262
  if (!wellKnown) {
1348
1263
  res.writeHead(404), res.end("Not found");
1349
1264
  return;
1350
1265
  }
1351
1266
  res.writeHead(200, { "Content-Type": "application/json" }), res.end(JSON.stringify(wellKnown));
1352
1267
  });
1353
- let requireAuth = (req, res) => {
1268
+ let requireAuth = (req, res, compositionAuth) => {
1354
1269
  let token = extractBearerToken(req.headers.authorization);
1355
1270
  return compositionAuth.requiresAuth && !token ? (res.writeHead(401, {
1356
1271
  "Content-Type": "text/plain",
1357
1272
  "WWW-Authenticate": compositionAuth.buildWwwAuthenticate(baseUrl)
1358
1273
  }), res.end("401 - Unauthorized"), !0) : !1;
1359
1274
  };
1360
- app.post(endpoint, (req, res) => {
1361
- if (!rejectDisallowedOrigin(req, res) && !requireAuth(req, res) && !rejectNonJsonBody(req, res))
1275
+ app.post(endpoint, async (req, res) => {
1276
+ if (rejectDisallowedOrigin(req, res)) return;
1277
+ let { sources, compositionAuth, manifestAccess } = await composition;
1278
+ if (!requireAuth(req, res, compositionAuth) && !rejectNonJsonBody(req, res))
1362
1279
  return mcpServerHandler({
1363
1280
  req,
1364
1281
  res,
@@ -1368,22 +1285,16 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1368
1285
  basePath,
1369
1286
  endpoint,
1370
1287
  sources,
1371
- ...manifestAccessFor(req),
1288
+ ...manifestAccess,
1372
1289
  compositionAuth
1373
1290
  });
1374
1291
  });
1375
- let {
1376
- moduleGraphSupported,
1377
- docsEnabled,
1378
- docsHasManifests,
1379
- docsFeatureEnabled,
1380
- testSupported,
1381
- a11yEnabled: a11yEnabled2
1382
- } = getEffectiveToolAvailability2(rawAvailability, { multiSource }), isDevEnabled = addonOptions.toolsets?.dev ?? !0, isDocsEnabled = docsEnabled && (addonOptions.toolsets?.docs ?? !0), isTestEnabled = testSupported && (addonOptions.toolsets?.test ?? !0);
1383
- return app.get(endpoint, (req, res) => {
1292
+ let isDevEnabled = addonOptions.toolsets?.dev ?? !0;
1293
+ return app.get(endpoint, async (req, res) => {
1384
1294
  if (rejectDisallowedOrigin(req, res)) return;
1295
+ let { sources, compositionAuth, manifestAccess, availability } = await composition;
1385
1296
  if (!req.headers.accept?.includes("text/html"))
1386
- return requireAuth(req, res) ? void 0 : mcpServerHandler({
1297
+ return requireAuth(req, res, compositionAuth) ? void 0 : mcpServerHandler({
1387
1298
  req,
1388
1299
  res,
1389
1300
  options,
@@ -1392,9 +1303,17 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1392
1303
  basePath,
1393
1304
  endpoint,
1394
1305
  sources,
1395
- ...manifestAccessFor(req),
1306
+ ...manifestAccess,
1396
1307
  compositionAuth
1397
1308
  });
1309
+ let {
1310
+ moduleGraphSupported,
1311
+ docsEnabled,
1312
+ docsHasManifests,
1313
+ docsFeatureEnabled,
1314
+ testSupported,
1315
+ a11yEnabled: a11yEnabled2
1316
+ } = availability, isDocsEnabled = docsEnabled && (addonOptions.toolsets?.docs ?? !0), isTestEnabled = testSupported && (addonOptions.toolsets?.test ?? !0);
1398
1317
  res.writeHead(200, { "Content-Type": "text/html" });
1399
1318
  let docsNotice = "";
1400
1319
  docsHasManifests ? docsFeatureEnabled || (docsNotice = `<div class="toolset-notice">
@@ -1421,12 +1340,13 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1421
1340
  ).replace("{{A11Y_BADGE}}", a11yBadge);
1422
1341
  res.end(html);
1423
1342
  }), app;
1424
- }, features = async (existingFeatures) => ({
1343
+ }, mcpToolsets = async (_value, options) => v3.parse(AddonOptions, { toolsets: options.toolsets ?? {} }).toolsets, features = async (existingFeatures) => ({
1425
1344
  ...existingFeatures,
1426
1345
  componentsManifest: !0
1427
1346
  });
1428
1347
  export {
1429
1348
  experimental_devServer,
1430
1349
  features,
1350
+ mcpToolsets,
1431
1351
  previewAnnotations
1432
1352
  };
@@ -4,7 +4,7 @@ var MCP_APP_PARAM = "mcp-app", MCP_APP_SIZE_CHANGED_EVENT = "storybook-mcp:size-
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@storybook/addon-mcp",
7
- version: "11.0.0-beta.1",
7
+ version: "11.0.0-beta.3",
8
8
  description: "Help agents automatically write and test stories for your UI components",
9
9
  keywords: [
10
10
  "ai",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-mcp",
3
- "version": "11.0.0-beta.1",
3
+ "version": "11.0.0-beta.3",
4
4
  "description": "Help agents automatically write and test stories for your UI components",
5
5
  "keywords": [
6
6
  "ai",
@@ -42,14 +42,14 @@
42
42
  "valibot": "^1.4.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@storybook/addon-a11y": "11.0.0-beta.1",
46
- "@storybook/addon-vitest": "11.0.0-beta.1",
47
- "storybook": "11.0.0-beta.1",
45
+ "@storybook/addon-a11y": "11.0.0-beta.3",
46
+ "@storybook/addon-vitest": "11.0.0-beta.3",
47
+ "storybook": "11.0.0-beta.3",
48
48
  "typescript": "^6.0.3"
49
49
  },
50
50
  "peerDependencies": {
51
- "@storybook/addon-vitest": "^11.0.0-beta.1",
52
- "storybook": "^11.0.0-beta.1"
51
+ "@storybook/addon-vitest": "^11.0.0-beta.3",
52
+ "storybook": "^11.0.0-beta.3"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@storybook/addon-vitest": {