@storybook/addon-mcp 11.0.0-alpha.4 → 11.0.0-alpha.6
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_beh7n2jjxhf from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_beh7n2jjxhf from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_beh7n2jjxhf from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_beh7n2jjxhf.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_beh7n2jjxhf.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_beh7n2jjxhf.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-alpha.
|
|
21
|
+
version: "11.0.0-alpha.6",
|
|
22
22
|
description: "Help agents automatically write and test stories for your UI components",
|
|
23
23
|
keywords: [
|
|
24
24
|
"ai",
|
|
@@ -111,9 +111,7 @@ async function collectTelemetry({
|
|
|
111
111
|
mcpSessionId: server.ctx.sessionId,
|
|
112
112
|
clientInfo: server.ctx.sessionInfo?.clientInfo,
|
|
113
113
|
clientCapabilities: server.ctx.sessionInfo?.clientCapabilities,
|
|
114
|
-
|
|
115
|
-
// header; everything else is a direct MCP client.
|
|
116
|
-
transport: server.ctx.custom?.cliClient ? "cli" : "mcp",
|
|
114
|
+
transport: "mcp",
|
|
117
115
|
...payload
|
|
118
116
|
});
|
|
119
117
|
} catch (error) {
|
|
@@ -127,7 +125,7 @@ import { getEffectiveToolAvailability, getToolAvailability } from "storybook/int
|
|
|
127
125
|
import { buildServerInstructions } from "storybook/internal/skills";
|
|
128
126
|
|
|
129
127
|
// src/constants.ts
|
|
130
|
-
var
|
|
128
|
+
var DEFAULT_MCP_ENDPOINT = "/mcp";
|
|
131
129
|
|
|
132
130
|
// src/tools/tool-registry.ts
|
|
133
131
|
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
@@ -279,8 +277,6 @@ async function buildStorybookStoryInstructions(options, {
|
|
|
279
277
|
transport: "mcp",
|
|
280
278
|
framework: inputs.framework,
|
|
281
279
|
renderer: inputs.renderer,
|
|
282
|
-
changeDetectionEnabled: inputs.changeDetectionEnabled,
|
|
283
|
-
reviewEnabled: inputs.reviewEnabled,
|
|
284
280
|
testSupported: (toolsets?.test ?? !0) && (addonVitestAvailable ?? inputs.testSupported),
|
|
285
281
|
a11yEnabled: a11yEnabled2 ?? inputs.a11yEnabled,
|
|
286
282
|
docsEnabled: (toolsets?.docs ?? !0) && (docsEnabled ?? inputs.docsEnabled)
|
|
@@ -512,7 +508,8 @@ function registerToolsetTool(server, options, enabled) {
|
|
|
512
508
|
}
|
|
513
509
|
|
|
514
510
|
// src/tools/tool-registry.ts
|
|
515
|
-
var isToolsetEnabled = (toolset, toolsets) => toolsets?.[toolset] ?? !0, isToolAvailable = (definition, context) => definition.available?.(context) ?? !0
|
|
511
|
+
var isToolsetEnabled = (toolset, toolsets) => toolsets?.[toolset] ?? !0, isToolAvailable = (definition, context) => definition.available?.(context) ?? !0;
|
|
512
|
+
var createToolsetEnabled = (server, toolset) => () => server.ctx.custom?.toolsets?.[toolset] ?? !0;
|
|
516
513
|
function fromToolset(definition) {
|
|
517
514
|
let { options, available, ...rest } = definition;
|
|
518
515
|
return {
|
|
@@ -588,19 +585,10 @@ var docsToolDefinitions = [
|
|
|
588
585
|
register: (server, { availability, toolsets }, enabled) => addGetUIBuildingInstructionsTool(server, enabled, {
|
|
589
586
|
docsEnabled: isToolsetEnabled("docs", toolsets) && availability.docsEnabled,
|
|
590
587
|
addonVitestAvailable: availability.testSupported
|
|
591
|
-
}),
|
|
592
|
-
getLocalTool: ({ availability, toolsets, options }) => ({
|
|
593
|
-
call: async () => ({ content: [{ type: "text", text: await buildStorybookStoryInstructions(options, {
|
|
594
|
-
toolsets,
|
|
595
|
-
a11yEnabled: availability.a11yEnabled,
|
|
596
|
-
addonVitestAvailable: availability.testSupported,
|
|
597
|
-
docsEnabled: isToolsetEnabled("docs", toolsets) && availability.docsEnabled
|
|
598
|
-
}) }] })
|
|
599
588
|
})
|
|
600
589
|
},
|
|
601
590
|
fromToolset({
|
|
602
591
|
toolset: "dev",
|
|
603
|
-
available: ({ availability }) => availability.changeDetectionEnabled,
|
|
604
592
|
options: { method: "stories.changed", mcpEventName: "tool:getChangedStories" }
|
|
605
593
|
}),
|
|
606
594
|
fromToolset({
|
|
@@ -610,7 +598,6 @@ var docsToolDefinitions = [
|
|
|
610
598
|
}),
|
|
611
599
|
fromToolset({
|
|
612
600
|
toolset: "dev",
|
|
613
|
-
available: ({ availability }) => availability.reviewEnabled,
|
|
614
601
|
options: {
|
|
615
602
|
method: "review.create",
|
|
616
603
|
mcpEventName: "tool:displayReview",
|
|
@@ -631,33 +618,6 @@ function dropToolIfToolsetMissing(name, error) {
|
|
|
631
618
|
throw error;
|
|
632
619
|
logger3.error(`Skipping MCP tool "${name}", its backing toolset is not registered: ${error}`);
|
|
633
620
|
}
|
|
634
|
-
function resolveDefinitionOrDrop(name, resolve) {
|
|
635
|
-
try {
|
|
636
|
-
return resolve();
|
|
637
|
-
} catch (error) {
|
|
638
|
-
return dropToolIfToolsetMissing(name, error);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
function getAddonToolMetadata(context) {
|
|
642
|
-
return addonToolDefinitions.filter((definition) => isMetadataToolEnabled(definition, context)).flatMap((definition) => {
|
|
643
|
-
let metadata = resolveDefinitionOrDrop(
|
|
644
|
-
definition.name,
|
|
645
|
-
() => definition.getMetadata(context)
|
|
646
|
-
);
|
|
647
|
-
return metadata ? [metadata] : [];
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
function getAddonLocalTools(context) {
|
|
651
|
-
return Object.fromEntries(
|
|
652
|
-
addonToolDefinitions.filter((definition) => isMetadataToolEnabled(definition, context)).flatMap((definition) => {
|
|
653
|
-
let localTool = resolveDefinitionOrDrop(
|
|
654
|
-
definition.name,
|
|
655
|
-
() => definition.getLocalTool?.(context)
|
|
656
|
-
);
|
|
657
|
-
return localTool ? [[definition.name, localTool]] : [];
|
|
658
|
-
})
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
621
|
async function registerAddonMcpTools(server, context) {
|
|
662
622
|
isToolsetEnabled("dev", context.toolsets) && await addPreviewStoriesResource(server);
|
|
663
623
|
for (let definition of addonToolDefinitions)
|
|
@@ -675,9 +635,8 @@ async function registerAddonMcpTools(server, context) {
|
|
|
675
635
|
|
|
676
636
|
// src/mcp-handler.ts
|
|
677
637
|
var transport, origin, initialize, disableTelemetry, a11yEnabled, initializeMCPServer = async (options, multiSource) => {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
let rawAvailability = await getToolAvailability(options, { features: features2 }), availability = getEffectiveToolAvailability(rawAvailability, { multiSource });
|
|
638
|
+
disableTelemetry = (await options.presets.apply("core", {}))?.disableTelemetry ?? !1;
|
|
639
|
+
let rawAvailability = await getToolAvailability(options), availability = getEffectiveToolAvailability(rawAvailability, { multiSource });
|
|
681
640
|
a11yEnabled = availability.a11yEnabled;
|
|
682
641
|
let server, serverOptions = {
|
|
683
642
|
adapter: new ValibotJsonSchemaAdapter(),
|
|
@@ -687,9 +646,7 @@ var transport, origin, initialize, disableTelemetry, a11yEnabled, initializeMCPS
|
|
|
687
646
|
devEnabled: server?.ctx.custom?.toolsets?.dev ?? !0,
|
|
688
647
|
testSupported: (server?.ctx.custom?.toolsets?.test ?? !0) && availability.testSupported,
|
|
689
648
|
docsEnabled: (server?.ctx.custom?.toolsets?.docs ?? !0) && availability.docsEnabled,
|
|
690
|
-
|
|
691
|
-
moduleGraphSupported: availability.moduleGraphSupported,
|
|
692
|
-
reviewEnabled: availability.reviewEnabled
|
|
649
|
+
moduleGraphSupported: availability.moduleGraphSupported
|
|
693
650
|
});
|
|
694
651
|
},
|
|
695
652
|
capabilities: {
|
|
@@ -726,7 +683,6 @@ var transport, origin, initialize, disableTelemetry, a11yEnabled, initializeMCPS
|
|
|
726
683
|
options,
|
|
727
684
|
endpoint,
|
|
728
685
|
toolsets: getToolsets(webRequest, addonOptions),
|
|
729
|
-
cliClient: webRequest.headers.get(STORYBOOK_MCP_PROXY_HEADER) === "true",
|
|
730
686
|
origin,
|
|
731
687
|
disableTelemetry,
|
|
732
688
|
a11yEnabled,
|
|
@@ -819,13 +775,15 @@ var isLiteralEndpointPathname = (endpoint) => {
|
|
|
819
775
|
});
|
|
820
776
|
|
|
821
777
|
// src/preset.ts
|
|
822
|
-
import * as
|
|
778
|
+
import * as v3 from "valibot";
|
|
823
779
|
import {
|
|
824
780
|
createLocalDocsAccess,
|
|
825
|
-
getEffectiveToolAvailability as
|
|
826
|
-
getToolAvailability as
|
|
781
|
+
getEffectiveToolAvailability as getEffectiveToolAvailability2,
|
|
782
|
+
getToolAvailability as getToolAvailability2,
|
|
783
|
+
isValidHost,
|
|
827
784
|
loadManifests
|
|
828
785
|
} from "storybook/internal/core-server";
|
|
786
|
+
import { isWebContainer } from "storybook/internal/common";
|
|
829
787
|
|
|
830
788
|
// src/template.html
|
|
831
789
|
var template_default = `<!doctype html>
|
|
@@ -1033,22 +991,14 @@ var template_default = `<!doctype html>
|
|
|
1033
991
|
<ul class="toolset-tools">
|
|
1034
992
|
<li><code>stories-preview</code></li>
|
|
1035
993
|
<li><code>get-storybook-story-instructions</code></li>
|
|
1036
|
-
<li>
|
|
1037
|
-
<code>stories-changed</code>
|
|
1038
|
-
<span class="toolset-status {{CHANGE_DETECTION_STATUS}}"
|
|
1039
|
-
>{{CHANGE_DETECTION_STATUS}}</span
|
|
1040
|
-
>
|
|
1041
|
-
</li>
|
|
994
|
+
<li><code>stories-changed</code></li>
|
|
1042
995
|
<li>
|
|
1043
996
|
<code>stories-find-by-component</code>
|
|
1044
997
|
<span class="toolset-status {{STORIES_BY_COMPONENT_STATUS}}"
|
|
1045
998
|
>{{STORIES_BY_COMPONENT_STATUS}}</span
|
|
1046
999
|
>
|
|
1047
1000
|
</li>
|
|
1048
|
-
<li>
|
|
1049
|
-
<code>review-create</code>
|
|
1050
|
-
<span class="toolset-status {{REVIEW_STATUS}}">{{REVIEW_STATUS}}</span>
|
|
1051
|
-
</li>
|
|
1001
|
+
<li><code>review-create</code></li>
|
|
1052
1002
|
</ul>
|
|
1053
1003
|
{{DEV_NOTICE}}
|
|
1054
1004
|
</div>
|
|
@@ -1187,7 +1137,7 @@ var OAuthResourceMetadata = v2.object({
|
|
|
1187
1137
|
* Create a manifest provider for multi-source mode.
|
|
1188
1138
|
*
|
|
1189
1139
|
* Remote sources are fetched over HTTP with auth and caching; the local source fetches from
|
|
1190
|
-
* `localOrigin`. In `
|
|
1140
|
+
* `localOrigin`. In `docgenServer` mode core 404s the local `/manifests/*.json`, and
|
|
1191
1141
|
* the composition reads that source through its own access instead of this provider.
|
|
1192
1142
|
*/
|
|
1193
1143
|
createManifestProvider(localOrigin) {
|
|
@@ -1319,9 +1269,6 @@ function extractBearerToken(authHeader) {
|
|
|
1319
1269
|
|
|
1320
1270
|
// src/auth/resolve-composition-sources.ts
|
|
1321
1271
|
import { getRefsFromConfig } from "storybook/internal/core-server";
|
|
1322
|
-
import { ComponentManifestMap as ComponentManifestMap2 } from "storybook/internal/toolsets-docs";
|
|
1323
|
-
import * as v3 from "valibot";
|
|
1324
|
-
var MANIFEST_PROBE_TIMEOUT_MS = 3e3;
|
|
1325
1272
|
async function resolveCompositionSources(options) {
|
|
1326
1273
|
let refs = await getRefsFromConfig(options), compositionAuth = new CompositionAuth();
|
|
1327
1274
|
if (refs.length === 0)
|
|
@@ -1335,127 +1282,10 @@ async function resolveCompositionSources(options) {
|
|
|
1335
1282
|
multiSource: sources.some((source) => !!source.url)
|
|
1336
1283
|
};
|
|
1337
1284
|
}
|
|
1338
|
-
async function resolveServerlessCompositionSources(options) {
|
|
1339
|
-
let refs = await getRefsFromConfig(options), refsWithManifests = await Promise.all(
|
|
1340
|
-
refs.map(
|
|
1341
|
-
async (ref) => await hasServerlessComponentManifestSource(ref.url) ? ref : void 0
|
|
1342
|
-
)
|
|
1343
|
-
), sources = [
|
|
1344
|
-
{ id: "local", title: "Local" },
|
|
1345
|
-
...refsWithManifests.filter((ref) => !!ref).map((ref) => ({
|
|
1346
|
-
id: ref.id,
|
|
1347
|
-
title: ref.title,
|
|
1348
|
-
url: ref.url
|
|
1349
|
-
}))
|
|
1350
|
-
];
|
|
1351
|
-
return {
|
|
1352
|
-
refs,
|
|
1353
|
-
sources,
|
|
1354
|
-
multiSource: sources.some((source) => !!source.url)
|
|
1355
|
-
};
|
|
1356
|
-
}
|
|
1357
|
-
async function hasServerlessComponentManifestSource(refUrl) {
|
|
1358
|
-
let controller = new AbortController(), timeout = setTimeout(() => controller.abort(), MANIFEST_PROBE_TIMEOUT_MS);
|
|
1359
|
-
try {
|
|
1360
|
-
let response = await fetch(
|
|
1361
|
-
new URL("manifests/components.json", `${refUrl.replace(/\/$/, "")}/`),
|
|
1362
|
-
{
|
|
1363
|
-
headers: { Accept: "application/json" },
|
|
1364
|
-
signal: controller.signal
|
|
1365
|
-
}
|
|
1366
|
-
);
|
|
1367
|
-
if (response.status === 401 && hasOAuthResourceMetadataChallenge(response))
|
|
1368
|
-
return !0;
|
|
1369
|
-
if (!response.ok)
|
|
1370
|
-
return !1;
|
|
1371
|
-
let text = await response.text();
|
|
1372
|
-
return v3.safeParse(v3.pipe(v3.string(), v3.parseJson(), ComponentManifestMap2), text).success;
|
|
1373
|
-
} catch {
|
|
1374
|
-
return !1;
|
|
1375
|
-
} finally {
|
|
1376
|
-
clearTimeout(timeout);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
function hasOAuthResourceMetadataChallenge(response) {
|
|
1380
|
-
return /resource_metadata="[^"]+"/.test(response.headers.get("WWW-Authenticate") ?? "");
|
|
1381
|
-
}
|
|
1382
1285
|
|
|
1383
1286
|
// src/preset.ts
|
|
1384
1287
|
import { logger as logger7 } from "storybook/internal/node-logger";
|
|
1385
1288
|
|
|
1386
|
-
// src/storybook-ai-metadata.ts
|
|
1387
|
-
import { ValibotJsonSchemaAdapter as ValibotJsonSchemaAdapter2 } from "@tmcp/adapter-valibot";
|
|
1388
|
-
import * as v4 from "valibot";
|
|
1389
|
-
import {
|
|
1390
|
-
getEffectiveToolAvailability as getEffectiveToolAvailability2,
|
|
1391
|
-
getToolAvailability as getToolAvailability2,
|
|
1392
|
-
isModuleGraphSupportedByBuilder
|
|
1393
|
-
} from "storybook/internal/core-server";
|
|
1394
|
-
import { buildServerInstructions as buildServerInstructions2 } from "storybook/internal/skills";
|
|
1395
|
-
var createEmptyInputSchema = () => ({ type: "object", properties: {} });
|
|
1396
|
-
async function buildStorybookAiMetadata(options, existingMetadata) {
|
|
1397
|
-
let toolsets = v4.parse(AddonOptions, {
|
|
1398
|
-
endpoint: options.endpoint,
|
|
1399
|
-
toolsets: options.toolsets ?? {}
|
|
1400
|
-
}).toolsets, features2 = await options.presets.apply("features", {}), devEnabled = toolsets?.dev ?? !0, moduleGraphSupported = await isModuleGraphSupportedByBuilder(options), availability = await getToolAvailability2(options, {
|
|
1401
|
-
features: features2,
|
|
1402
|
-
moduleGraphSupported
|
|
1403
|
-
}), testSupported = (toolsets?.test ?? !0) && availability.testSupported, docsToolsetEnabled = toolsets?.docs ?? !0, multiSource = docsToolsetEnabled ? (await resolveServerlessCompositionSources(options)).multiSource : !1, registryAvailability = getEffectiveToolAvailability2(availability, { multiSource }), docsEnabled = docsToolsetEnabled && registryAvailability.docsEnabled, registryContext = { availability: registryAvailability, multiSource, toolsets }, toolMetadata = getAddonToolMetadata(registryContext), localTools = {
|
|
1404
|
-
...existingMetadata?.localTools,
|
|
1405
|
-
...getAddonLocalTools({ ...registryContext, options })
|
|
1406
|
-
};
|
|
1407
|
-
return {
|
|
1408
|
-
instructions: joinInstructions(
|
|
1409
|
-
existingMetadata?.instructions,
|
|
1410
|
-
buildServerInstructions2({
|
|
1411
|
-
transport: "mcp",
|
|
1412
|
-
devEnabled,
|
|
1413
|
-
testSupported,
|
|
1414
|
-
docsEnabled,
|
|
1415
|
-
changeDetectionEnabled: availability.changeDetectionEnabled,
|
|
1416
|
-
moduleGraphSupported: availability.moduleGraphSupported,
|
|
1417
|
-
reviewEnabled: availability.reviewEnabled
|
|
1418
|
-
})
|
|
1419
|
-
),
|
|
1420
|
-
tools: mergeToolDescriptors(
|
|
1421
|
-
existingMetadata?.tools ?? [],
|
|
1422
|
-
await toToolDescriptors(toolMetadata)
|
|
1423
|
-
),
|
|
1424
|
-
localTools
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
async function toToolDescriptors(toolMetadata) {
|
|
1428
|
-
let adapter = new ValibotJsonSchemaAdapter2();
|
|
1429
|
-
return Promise.all(
|
|
1430
|
-
toolMetadata.map(async ({ schema, outputSchema, ...metadata }) => ({
|
|
1431
|
-
...metadata,
|
|
1432
|
-
inputSchema: schema ? await toJsonSchema(adapter, schema) : createEmptyInputSchema(),
|
|
1433
|
-
...outputSchema ? { outputSchema: await toJsonSchema(adapter, outputSchema) } : {}
|
|
1434
|
-
}))
|
|
1435
|
-
);
|
|
1436
|
-
}
|
|
1437
|
-
async function toJsonSchema(adapter, schema) {
|
|
1438
|
-
return await adapter.toJsonSchema(
|
|
1439
|
-
schema
|
|
1440
|
-
);
|
|
1441
|
-
}
|
|
1442
|
-
function joinInstructions(...sections) {
|
|
1443
|
-
let uniqueSections = [], seen = /* @__PURE__ */ new Set();
|
|
1444
|
-
for (let section of sections) {
|
|
1445
|
-
let trimmed = section?.trim();
|
|
1446
|
-
trimmed && !seen.has(trimmed) && (seen.add(trimmed), uniqueSections.push(trimmed));
|
|
1447
|
-
}
|
|
1448
|
-
return uniqueSections.join(`
|
|
1449
|
-
|
|
1450
|
-
`);
|
|
1451
|
-
}
|
|
1452
|
-
function mergeToolDescriptors(...groups) {
|
|
1453
|
-
let toolsByName = /* @__PURE__ */ new Map();
|
|
1454
|
-
for (let tool of groups.flat())
|
|
1455
|
-
toolsByName.has(tool.name) && toolsByName.delete(tool.name), toolsByName.set(tool.name, tool);
|
|
1456
|
-
return [...toolsByName.values()];
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
1289
|
// src/utils/get-story-index.ts
|
|
1460
1290
|
import { logger as logger6 } from "storybook/internal/node-logger";
|
|
1461
1291
|
async function getStoryIndex(options) {
|
|
@@ -1472,10 +1302,27 @@ async function getStoryIndex(options) {
|
|
|
1472
1302
|
|
|
1473
1303
|
// src/preset.ts
|
|
1474
1304
|
var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotations, path.join(import.meta.dirname, "preview.js")], experimental_devServer = async (app, options) => {
|
|
1475
|
-
let addonOptions =
|
|
1305
|
+
let addonOptions = v3.parse(AddonOptions, {
|
|
1476
1306
|
endpoint: options.endpoint,
|
|
1477
1307
|
toolsets: options.toolsets ?? {}
|
|
1478
|
-
}), origin2 = `http://localhost:${options.port}`, endpoint = addonOptions.endpoint ?? DEFAULT_MCP_ENDPOINT,
|
|
1308
|
+
}), origin2 = `http://localhost:${options.port}`, endpoint = addonOptions.endpoint ?? DEFAULT_MCP_ENDPOINT, core = await options.presets.apply("core", {}), hostValidation = {
|
|
1309
|
+
host: options.host,
|
|
1310
|
+
allowedHosts: core?.allowedHosts,
|
|
1311
|
+
localAddress: options.localAddress,
|
|
1312
|
+
networkAddress: options.networkAddress
|
|
1313
|
+
}, skipOriginValidation = isWebContainer(), rejectDisallowedOrigin = (req, res) => {
|
|
1314
|
+
if (skipOriginValidation)
|
|
1315
|
+
return !1;
|
|
1316
|
+
let { origin: requestOrigin } = req.headers;
|
|
1317
|
+
if (!requestOrigin)
|
|
1318
|
+
return !1;
|
|
1319
|
+
try {
|
|
1320
|
+
if (isValidHost(new URL(requestOrigin).host, hostValidation))
|
|
1321
|
+
return !1;
|
|
1322
|
+
} catch {
|
|
1323
|
+
}
|
|
1324
|
+
return res.writeHead(403, { "Content-Type": "text/plain" }), res.end("Invalid origin"), !0;
|
|
1325
|
+
}, 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({
|
|
1479
1326
|
storyIndex: { getIndex: () => getStoryIndex(options) },
|
|
1480
1327
|
getManifests: () => loadManifests(options.presets)
|
|
1481
1328
|
}) : void 0, createManifestProvider;
|
|
@@ -1500,7 +1347,7 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
|
|
|
1500
1347
|
}), res.end("401 - Unauthorized"), !0) : !1;
|
|
1501
1348
|
};
|
|
1502
1349
|
app.post(endpoint, (req, res) => {
|
|
1503
|
-
if (!requireAuth(req, res))
|
|
1350
|
+
if (!rejectDisallowedOrigin(req, res) && !requireAuth(req, res) && !rejectNonJsonBody(req, res))
|
|
1504
1351
|
return mcpServerHandler({
|
|
1505
1352
|
req,
|
|
1506
1353
|
res,
|
|
@@ -1514,15 +1361,14 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
|
|
|
1514
1361
|
});
|
|
1515
1362
|
let {
|
|
1516
1363
|
moduleGraphSupported,
|
|
1517
|
-
changeDetectionEnabled,
|
|
1518
|
-
reviewEnabled,
|
|
1519
1364
|
docsEnabled,
|
|
1520
1365
|
docsHasManifests,
|
|
1521
1366
|
docsFeatureEnabled,
|
|
1522
1367
|
testSupported,
|
|
1523
1368
|
a11yEnabled: a11yEnabled2
|
|
1524
|
-
} =
|
|
1369
|
+
} = getEffectiveToolAvailability2(rawAvailability, { multiSource }), isDevEnabled = addonOptions.toolsets?.dev ?? !0, isDocsEnabled = docsEnabled && (addonOptions.toolsets?.docs ?? !0), isTestEnabled = testSupported && (addonOptions.toolsets?.test ?? !0);
|
|
1525
1370
|
return app.get(endpoint, (req, res) => {
|
|
1371
|
+
if (rejectDisallowedOrigin(req, res)) return;
|
|
1526
1372
|
if (!req.headers.accept?.includes("text/html"))
|
|
1527
1373
|
return requireAuth(req, res) ? void 0 : mcpServerHandler({
|
|
1528
1374
|
req,
|
|
@@ -1540,34 +1386,32 @@ var previewAnnotations = async (existingAnnotations = []) => [...existingAnnotat
|
|
|
1540
1386
|
This toolset requires enabling the component manifest feature.
|
|
1541
1387
|
<a target="_blank" href="https://github.com/storybookjs/storybook/tree/next/code/addons/mcp">Learn how to enable it</a>
|
|
1542
1388
|
</div>`) : docsNotice = docsFeatureEnabled ? `<div class="toolset-notice">
|
|
1543
|
-
This toolset requires a components manifest, which your framework does not generate. On <code>@storybook/vue3-vite</code>, also enable <code>
|
|
1389
|
+
This toolset requires a components manifest, which your framework does not generate. On <code>@storybook/vue3-vite</code>, also enable <code>docgenServer</code>.
|
|
1544
1390
|
<a target="_blank" href="https://storybook.js.org/docs/ai/mcp/overview#framework-support">See which frameworks are supported</a>
|
|
1545
1391
|
</div>` : `<div class="toolset-notice">
|
|
1546
|
-
This toolset requires a components manifest, which is generated by the React frameworks, <code>@storybook/angular-vite</code> and <code>@storybook/vue3-vite</code>. Enable the <code>componentsManifest</code> feature, plus <code>
|
|
1392
|
+
This toolset requires a components manifest, which is generated by the React frameworks, <code>@storybook/angular-vite</code> and <code>@storybook/vue3-vite</code>. Enable the <code>componentsManifest</code> feature, plus <code>docgenServer</code> on <code>@storybook/vue3-vite</code>.
|
|
1547
1393
|
<a target="_blank" href="https://storybook.js.org/docs/ai/mcp/overview#framework-support">Learn how to enable it</a>
|
|
1548
1394
|
</div>`;
|
|
1549
1395
|
let testNoticeLines = [
|
|
1550
1396
|
!testSupported && 'This toolset requires Storybook 10.3.0+ with <code>@storybook/addon-vitest</code>. <a target="_blank" href="https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#install-and-set-up">Learn how to set it up</a>',
|
|
1551
1397
|
!a11yEnabled2 && 'Add <code>@storybook/addon-a11y</code> for accessibility testing. <a target="_blank" href="https://storybook.js.org/docs/writing-tests/accessibility-testing">Learn more</a>'
|
|
1552
1398
|
].filter(Boolean), testNotice = testNoticeLines.length ? `<div class="toolset-notice">${testNoticeLines.join("<br>")}</div>` : "", a11yBadge = a11yEnabled2 ? ' <span class="toolset-status enabled">+ accessibility</span>' : "", devNoticeLines = isDevEnabled ? [
|
|
1553
|
-
!moduleGraphSupported && "<code>stories-find-by-component</code> requires a dev server with a builder that supports the module graph (Vite or Webpack 5)."
|
|
1554
|
-
|
|
1555
|
-
].filter(Boolean) : ["The <code>dev</code> toolset is disabled via addon options."], devNotice = devNoticeLines.length ? `<div class="toolset-notice">${devNoticeLines.join("<br>")}</div>` : "", statusWord = (enabled) => enabled ? "enabled" : "disabled", html = template_default.replaceAll("{{DEV_STATUS}}", isDevEnabled ? "enabled" : "disabled").replaceAll(
|
|
1399
|
+
!moduleGraphSupported && "<code>stories-find-by-component</code> requires a dev server with a builder that supports the module graph (Vite or Webpack 5)."
|
|
1400
|
+
].filter(Boolean) : ["The <code>dev</code> toolset is disabled via addon options."], devNotice = devNoticeLines.length ? `<div class="toolset-notice">${devNoticeLines.join("<br>")}</div>` : "", html = template_default.replaceAll("{{DEV_STATUS}}", isDevEnabled ? "enabled" : "disabled").replaceAll(
|
|
1556
1401
|
"{{STORIES_BY_COMPONENT_STATUS}}",
|
|
1557
|
-
|
|
1558
|
-
).
|
|
1402
|
+
isDevEnabled && moduleGraphSupported ? "enabled" : "disabled"
|
|
1403
|
+
).replace("{{DEV_NOTICE}}", devNotice).replaceAll("{{DOCS_STATUS}}", isDocsEnabled ? "enabled" : "disabled").replace("{{DOCS_NOTICE}}", docsNotice).replaceAll("{{TEST_STATUS}}", isTestEnabled ? "enabled" : "disabled").replace("{{TEST_NOTICE}}", testNotice).replace(
|
|
1559
1404
|
"{{MANIFEST_DEBUGGER_LINK}}",
|
|
1560
1405
|
rawAvailability.docsEnabled ? '<p>View the <a href="/manifests/components.html">component manifest debugger</a>.</p>' : ""
|
|
1561
1406
|
).replace("{{A11Y_BADGE}}", a11yBadge);
|
|
1562
1407
|
res.end(html);
|
|
1563
1408
|
}), app;
|
|
1564
|
-
},
|
|
1409
|
+
}, features = async (existingFeatures) => ({
|
|
1565
1410
|
...existingFeatures,
|
|
1566
1411
|
componentsManifest: !0
|
|
1567
1412
|
});
|
|
1568
1413
|
export {
|
|
1569
1414
|
experimental_devServer,
|
|
1570
|
-
experimental_storybookAi,
|
|
1571
1415
|
features,
|
|
1572
1416
|
previewAnnotations
|
|
1573
1417
|
};
|
|
@@ -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-alpha.
|
|
7
|
+
version: "11.0.0-alpha.6",
|
|
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-alpha.
|
|
3
|
+
"version": "11.0.0-alpha.6",
|
|
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-alpha.
|
|
46
|
-
"@storybook/addon-vitest": "11.0.0-alpha.
|
|
47
|
-
"storybook": "11.0.0-alpha.
|
|
45
|
+
"@storybook/addon-a11y": "11.0.0-alpha.6",
|
|
46
|
+
"@storybook/addon-vitest": "11.0.0-alpha.6",
|
|
47
|
+
"storybook": "11.0.0-alpha.6",
|
|
48
48
|
"typescript": "^6.0.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@storybook/addon-vitest": "^11.0.0-alpha.
|
|
52
|
-
"storybook": "^11.0.0-alpha.
|
|
51
|
+
"@storybook/addon-vitest": "^11.0.0-alpha.6",
|
|
52
|
+
"storybook": "^11.0.0-alpha.6"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@storybook/addon-vitest": {
|