@storybook/addon-mcp 0.3.4 → 0.4.0
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 +42 -12
- package/dist/preview-stories-app-script.js +1 -1
- package/package.json +5 -5
package/dist/preset.js
CHANGED
|
@@ -9,13 +9,13 @@ import { stringify } from "picoquery";
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { normalizeStoryPath } from "storybook/internal/common";
|
|
11
11
|
import { storyNameFromExport } from "storybook/internal/csf";
|
|
12
|
-
import { ComponentManifestMap, DocsManifestMap, GET_TOOL_NAME, LIST_TOOL_NAME, addGetDocumentationTool, addGetStoryDocumentationTool, addListAllDocumentationTool } from "@storybook/mcp";
|
|
12
|
+
import { ComponentManifestMap, DocsManifestMap, GET_TOOL_NAME, LIST_TOOL_NAME, STORYBOOK_MCP_INSTRUCTIONS, addGetDocumentationTool, addGetStoryDocumentationTool, addListAllDocumentationTool } from "@storybook/mcp";
|
|
13
13
|
import fs from "node:fs/promises";
|
|
14
14
|
import { buffer } from "node:stream/consumers";
|
|
15
15
|
|
|
16
16
|
//#region package.json
|
|
17
17
|
var name = "@storybook/addon-mcp";
|
|
18
|
-
var version = "0.
|
|
18
|
+
var version = "0.4.0";
|
|
19
19
|
var description = "Help agents automatically write and test stories for your UI components";
|
|
20
20
|
|
|
21
21
|
//#endregion
|
|
@@ -768,7 +768,7 @@ const getManifestStatus = async (options) => {
|
|
|
768
768
|
options.presets.apply("experimental_manifests", void 0, { manifestEntries: [] }),
|
|
769
769
|
options.presets.apply("experimental_componentManifestGenerator")
|
|
770
770
|
]);
|
|
771
|
-
const hasManifests =
|
|
771
|
+
const hasManifests = manifests && "components" in manifests || !!legacyComponentManifestGenerator;
|
|
772
772
|
const hasFeatureFlag = !!(features?.componentsManifest ?? features?.experimentalComponentsManifest);
|
|
773
773
|
return {
|
|
774
774
|
available: hasFeatureFlag && hasManifests,
|
|
@@ -831,6 +831,25 @@ function estimateTokens(text) {
|
|
|
831
831
|
return tokenCount;
|
|
832
832
|
}
|
|
833
833
|
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region src/instructions/dev-instructions.md
|
|
836
|
+
var dev_instructions_default = "## UI Building and Story Writing Workflow\n\n- Before creating or editing components or stories, call **get-storybook-story-instructions**.\n- Treat that tool's output as the source of truth for framework-specific imports, story patterns, and testing conventions.\n- After changing any component or story, call **preview-stories**.\n- Always include every returned preview URL in your user-facing response so the user can verify the visual result.\n";
|
|
837
|
+
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/instructions/test-instructions.md
|
|
840
|
+
var test_instructions_default = "## Validation Workflow\n\n- After each component or story change, run **run-story-tests**.\n- Use focused runs while iterating, then run a broad pass before final handoff when scope is unclear or wide.\n- Fix failing tests before reporting success. Do not report completion while story tests are failing.\n";
|
|
841
|
+
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region src/instructions/build-server-instructions.ts
|
|
844
|
+
function buildServerInstructions(options) {
|
|
845
|
+
const sections = ["Follow these workflows when working with UI and/or Storybook."];
|
|
846
|
+
if (options.devEnabled) sections.push(dev_instructions_default.trim());
|
|
847
|
+
if (options.testEnabled) sections.push(test_instructions_default.trim());
|
|
848
|
+
if (options.docsEnabled) sections.push(STORYBOOK_MCP_INSTRUCTIONS.trim());
|
|
849
|
+
if (sections.length === 1) return "";
|
|
850
|
+
return sections.join("\n\n");
|
|
851
|
+
}
|
|
852
|
+
|
|
834
853
|
//#endregion
|
|
835
854
|
//#region src/mcp-handler.ts
|
|
836
855
|
let transport;
|
|
@@ -840,17 +859,29 @@ let disableTelemetry;
|
|
|
840
859
|
let a11yEnabled;
|
|
841
860
|
const initializeMCPServer = async (options, multiSource) => {
|
|
842
861
|
disableTelemetry = (await options.presets.apply("core", {}))?.disableTelemetry ?? false;
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
862
|
+
const addonVitestConstants = await getAddonVitestConstants();
|
|
863
|
+
const manifestStatus = await getManifestStatus(options);
|
|
864
|
+
a11yEnabled = await isAddonA11yEnabled(options);
|
|
865
|
+
let server;
|
|
866
|
+
const serverOptions = {
|
|
848
867
|
adapter: new ValibotJsonSchemaAdapter(),
|
|
868
|
+
get instructions() {
|
|
869
|
+
return buildServerInstructions({
|
|
870
|
+
devEnabled: server?.ctx.custom?.toolsets?.dev ?? true,
|
|
871
|
+
testEnabled: (server?.ctx.custom?.toolsets?.test ?? true) && !!addonVitestConstants,
|
|
872
|
+
docsEnabled: (server?.ctx.custom?.toolsets?.docs ?? true) && manifestStatus.available
|
|
873
|
+
});
|
|
874
|
+
},
|
|
849
875
|
capabilities: {
|
|
850
876
|
tools: { listChanged: true },
|
|
851
877
|
resources: { listChanged: true }
|
|
852
878
|
}
|
|
853
|
-
}
|
|
879
|
+
};
|
|
880
|
+
server = new McpServer({
|
|
881
|
+
name,
|
|
882
|
+
version,
|
|
883
|
+
description
|
|
884
|
+
}, serverOptions).withContext();
|
|
854
885
|
if (!disableTelemetry) server.on("initialize", async () => {
|
|
855
886
|
await collectTelemetry({
|
|
856
887
|
event: "session:initialized",
|
|
@@ -859,9 +890,8 @@ const initializeMCPServer = async (options, multiSource) => {
|
|
|
859
890
|
});
|
|
860
891
|
await addPreviewStoriesTool(server);
|
|
861
892
|
await addGetUIBuildingInstructionsTool(server);
|
|
862
|
-
a11yEnabled = await isAddonA11yEnabled(options);
|
|
863
893
|
await addRunStoryTestsTool(server, { a11yEnabled });
|
|
864
|
-
if (
|
|
894
|
+
if (manifestStatus.available) {
|
|
865
895
|
logger.info("Experimental components manifest feature detected - registering component tools");
|
|
866
896
|
const contextAwareEnabled = () => server.ctx.custom?.toolsets?.docs ?? true;
|
|
867
897
|
await addListAllDocumentationTool(server, contextAwareEnabled);
|
|
@@ -1298,7 +1328,7 @@ const experimental_devServer = async (app, options) => {
|
|
|
1298
1328
|
This toolset is only supported in React-based setups.
|
|
1299
1329
|
</div>`;
|
|
1300
1330
|
else if (!manifestStatus.hasFeatureFlag) docsNotice = `<div class="toolset-notice">
|
|
1301
|
-
This toolset requires enabling the
|
|
1331
|
+
This toolset requires enabling the component manifest feature.
|
|
1302
1332
|
<a target="_blank" href="https://github.com/storybookjs/mcp/tree/main/packages/addon-mcp#docs-tools-experimental">Learn how to enable it</a>
|
|
1303
1333
|
</div>`;
|
|
1304
1334
|
const testNoticeLines = [!addonVitestConstants && `This toolset requires Storybook 10.3.0+ with <code>@storybook/addon-vitest</code>. <a target="_blank" href="https://storybook.js.org/docs/writing-tests/test-addon">Learn how to set it up</a>`, !a11yEnabled && `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>`].filter(Boolean);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Help agents automatically write and test stories for your UI components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"picoquery": "^2.5.0",
|
|
35
35
|
"tmcp": "^1.16.0",
|
|
36
36
|
"valibot": "1.2.0",
|
|
37
|
-
"@storybook/mcp": "0.
|
|
37
|
+
"@storybook/mcp": "0.6.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@storybook/addon-a11y": "10.3.0-alpha.
|
|
41
|
-
"@storybook/addon-vitest": "10.3.0-alpha.
|
|
42
|
-
"storybook": "10.3.0-alpha.
|
|
40
|
+
"@storybook/addon-a11y": "10.3.0-alpha.16",
|
|
41
|
+
"@storybook/addon-vitest": "10.3.0-alpha.16",
|
|
42
|
+
"storybook": "10.3.0-alpha.16"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@storybook/addon-vitest": "^9.1.16 || ^10.0.0 || ^10.1.0-0 || ^10.2.0-0 || ^10.3.0-0 || ^10.4.0-0",
|