@storybook/addon-mcp 11.0.0-beta.2 → 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_az3l6xmq8mt from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_az3l6xmq8mt from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_az3l6xmq8mt 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_az3l6xmq8mt.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_az3l6xmq8mt.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_az3l6xmq8mt.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.2",
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",
@@ -951,7 +951,7 @@ var OAuthResourceMetadata = v2.object({
951
951
  constructor(url2) {
952
952
  super(`Authentication failed for ${url2}. Your token may be invalid or expired.`), this.name = "AuthenticationError";
953
953
  }
954
- }, CompositionAuth = class {
954
+ }, REF_PROBE_TIMEOUT_MS = 3e3, CompositionAuth = class {
955
955
  #authRequirement = null;
956
956
  #authRequiredUrls = [];
957
957
  #refsWithManifests = [];
@@ -960,22 +960,30 @@ var OAuthResourceMetadata = v2.object({
960
960
  #authErrors = /* @__PURE__ */ new WeakMap();
961
961
  /** Initialize by checking which refs require authentication and have manifests. */
962
962
  async initialize(refs) {
963
- for (let ref of refs)
964
- try {
965
- let result = await this.#checkRef(ref.url);
966
- if (result === "manifest-not-found") {
967
- logger4.warn(
968
- `[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.`
969
- );
970
- continue;
971
- }
972
- if (result === "manifest-invalid") {
973
- logger4.warn(
974
- `[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.`
975
- );
976
- continue;
977
- }
978
- 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")
979
987
  if (this.#authRequiredUrls.push(ref.url), !this.#authRequirement)
980
988
  this.#authRequirement = result;
981
989
  else {
@@ -984,11 +992,7 @@ var OAuthResourceMetadata = v2.object({
984
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.`
985
993
  );
986
994
  }
987
- } catch (error) {
988
- logger4.warn(
989
- `[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.`
990
- );
991
- }
995
+ }
992
996
  }
993
997
  get requiresAuth() {
994
998
  return this.#authRequiredUrls.length > 0;
@@ -1088,7 +1092,8 @@ var OAuthResourceMetadata = v2.object({
1088
1092
  */
1089
1093
  async #checkRef(refUrl) {
1090
1094
  let response = await fetch(`${refUrl}/manifests/components.json`, {
1091
- headers: { Accept: "application/json" }
1095
+ headers: { Accept: "application/json" },
1096
+ signal: AbortSignal.timeout(REF_PROBE_TIMEOUT_MS)
1092
1097
  }), authReq = await this.#parseAuthFromResponse(response);
1093
1098
  if (authReq) return authReq;
1094
1099
  let noManifestReason = "manifest-not-found";
@@ -1108,7 +1113,8 @@ var OAuthResourceMetadata = v2.object({
1108
1113
  let response = await fetch(`${refUrl}/mcp`, {
1109
1114
  method: "POST",
1110
1115
  headers: { "Content-Type": "application/json" },
1111
- 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)
1112
1118
  });
1113
1119
  return this.#parseAuthFromResponse(response);
1114
1120
  }
@@ -1118,7 +1124,8 @@ var OAuthResourceMetadata = v2.object({
1118
1124
  return (await fetch(`${origin}/mcp`, {
1119
1125
  method: "POST",
1120
1126
  headers: { "Content-Type": "application/json" },
1121
- 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)
1122
1129
  })).status === 401;
1123
1130
  } catch {
1124
1131
  return !1;
@@ -1131,7 +1138,9 @@ var OAuthResourceMetadata = v2.object({
1131
1138
  if (!wwwAuth) return null;
1132
1139
  let match = wwwAuth.match(/resource_metadata="([^"]+)"/);
1133
1140
  if (!match?.[1]) return null;
1134
- 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
+ });
1135
1144
  if (!resourceResponse.ok)
1136
1145
  return logger4.warn(
1137
1146
  `[addon-mcp] Failed to fetch OAuth resource metadata from ${resourceMetadataUrl}: ${resourceResponse.status}`
@@ -1141,7 +1150,9 @@ var OAuthResourceMetadata = v2.object({
1141
1150
  return logger4.warn(
1142
1151
  `[addon-mcp] Invalid OAuth resource metadata from ${resourceMetadataUrl}: ${resourceResult.issues.map((i) => i.message).join(", ")}`
1143
1152
  ), null;
1144
- 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
+ });
1145
1156
  if (!serverResponse.ok)
1146
1157
  return logger4.warn(
1147
1158
  `[addon-mcp] Failed to fetch OAuth server metadata from ${serverMetadataUrl}: ${serverResponse.status}`
@@ -1195,7 +1206,28 @@ async function getStoryIndex(options) {
1195
1206
  }
1196
1207
 
1197
1208
  // src/preset.ts
1198
- 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) => {
1199
1231
  let addonOptions = v3.parse(AddonOptions, {
1200
1232
  endpoint: options.endpoint,
1201
1233
  toolsets: options.toolsets ?? {}
@@ -1218,32 +1250,32 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1218
1250
  } catch {
1219
1251
  }
1220
1252
  return res.writeHead(403, { "Content-Type": "text/plain" }), res.end("Invalid origin"), !0;
1221
- }, 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({
1222
- storyIndex: { getIndex: () => getStoryIndex(options) },
1223
- getManifests: () => loadManifests(options.presets)
1224
- }) : void 0, createManifestProvider;
1225
- 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));
1226
- let manifestAccessFor = (req) => ({
1227
- manifestProvider: createManifestProvider?.(req),
1228
- localAccess
1229
- });
1230
- app.get("/.well-known/oauth-protected-resource", (_req, res) => {
1231
- 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}`);
1232
1262
  if (!wellKnown) {
1233
1263
  res.writeHead(404), res.end("Not found");
1234
1264
  return;
1235
1265
  }
1236
1266
  res.writeHead(200, { "Content-Type": "application/json" }), res.end(JSON.stringify(wellKnown));
1237
1267
  });
1238
- let requireAuth = (req, res) => {
1268
+ let requireAuth = (req, res, compositionAuth) => {
1239
1269
  let token = extractBearerToken(req.headers.authorization);
1240
1270
  return compositionAuth.requiresAuth && !token ? (res.writeHead(401, {
1241
1271
  "Content-Type": "text/plain",
1242
1272
  "WWW-Authenticate": compositionAuth.buildWwwAuthenticate(baseUrl)
1243
1273
  }), res.end("401 - Unauthorized"), !0) : !1;
1244
1274
  };
1245
- app.post(endpoint, (req, res) => {
1246
- 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))
1247
1279
  return mcpServerHandler({
1248
1280
  req,
1249
1281
  res,
@@ -1253,22 +1285,16 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1253
1285
  basePath,
1254
1286
  endpoint,
1255
1287
  sources,
1256
- ...manifestAccessFor(req),
1288
+ ...manifestAccess,
1257
1289
  compositionAuth
1258
1290
  });
1259
1291
  });
1260
- let {
1261
- moduleGraphSupported,
1262
- docsEnabled,
1263
- docsHasManifests,
1264
- docsFeatureEnabled,
1265
- testSupported,
1266
- a11yEnabled: a11yEnabled2
1267
- } = getEffectiveToolAvailability2(rawAvailability, { multiSource }), isDevEnabled = addonOptions.toolsets?.dev ?? !0, isDocsEnabled = docsEnabled && (addonOptions.toolsets?.docs ?? !0), isTestEnabled = testSupported && (addonOptions.toolsets?.test ?? !0);
1268
- return app.get(endpoint, (req, res) => {
1292
+ let isDevEnabled = addonOptions.toolsets?.dev ?? !0;
1293
+ return app.get(endpoint, async (req, res) => {
1269
1294
  if (rejectDisallowedOrigin(req, res)) return;
1295
+ let { sources, compositionAuth, manifestAccess, availability } = await composition;
1270
1296
  if (!req.headers.accept?.includes("text/html"))
1271
- return requireAuth(req, res) ? void 0 : mcpServerHandler({
1297
+ return requireAuth(req, res, compositionAuth) ? void 0 : mcpServerHandler({
1272
1298
  req,
1273
1299
  res,
1274
1300
  options,
@@ -1277,9 +1303,17 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
1277
1303
  basePath,
1278
1304
  endpoint,
1279
1305
  sources,
1280
- ...manifestAccessFor(req),
1306
+ ...manifestAccess,
1281
1307
  compositionAuth
1282
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);
1283
1317
  res.writeHead(200, { "Content-Type": "text/html" });
1284
1318
  let docsNotice = "";
1285
1319
  docsHasManifests ? docsFeatureEnabled || (docsNotice = `<div class="toolset-notice">
@@ -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.2",
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.2",
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.2",
46
- "@storybook/addon-vitest": "11.0.0-beta.2",
47
- "storybook": "11.0.0-beta.2",
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.2",
52
- "storybook": "^11.0.0-beta.2"
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": {