@storybook/addon-mcp 11.0.0-alpha.0 → 11.0.0-alpha.1

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_drkyweaumbf from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_drkyweaumbf from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_drkyweaumbf from "node:module";
1
+ import CJS_COMPAT_NODE_URL_a7i0o8czlgi from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_a7i0o8czlgi from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_a7i0o8czlgi from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_drkyweaumbf.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_drkyweaumbf.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_drkyweaumbf.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_a7i0o8czlgi.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_a7i0o8czlgi.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_a7i0o8czlgi.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.0",
21
+ version: "11.0.0-alpha.1",
22
22
  description: "Help agents automatically write and test stories for your UI components",
23
23
  keywords: [
24
24
  "ai",
@@ -420,6 +420,8 @@ import { logger as logger2 } from "storybook/internal/node-logger";
420
420
  import { OpenServiceToolsetOutputMismatchError } from "storybook/internal/server-errors";
421
421
  import {
422
422
  getToolset,
423
+ invokeToolsetMethod,
424
+ parseToolsetMethodId,
423
425
  resolveToolsetDescription,
424
426
  toMcpToolName as toMcpToolName2
425
427
  } from "storybook/open-service";
@@ -445,14 +447,10 @@ function resolveToolsetOrigin(context) {
445
447
 
446
448
  // src/tools/toolset-tools.ts
447
449
  function resolveToolset(options, server) {
448
- if (options.resolveToolset)
449
- return options.resolveToolset(server);
450
- let [toolsetId] = options.method.split(".");
451
- return getToolset(toolsetId);
450
+ return options.resolveToolset ? options.resolveToolset(server) : getToolset(parseToolsetMethodId(options.method).toolsetId);
452
451
  }
453
452
  function resolveMethod(toolset, options) {
454
- let [, methodName] = options.method.split(".");
455
- return toolset.methods[methodName];
453
+ return toolset.methods[parseToolsetMethodId(options.method).methodName];
456
454
  }
457
455
  function isAgentFacingError(error) {
458
456
  return error instanceof Error && error.agentFacing === !0;
@@ -466,25 +464,25 @@ async function toStructuredContent(outputSchema, data) {
466
464
  return result.value;
467
465
  }
468
466
  function buildContext(server) {
469
- let custom = server.ctx.custom;
470
467
  return {
471
468
  transport: "mcp",
472
469
  // The toolset origin is the complete UI base URL, including any deployment subpath.
473
- origin: resolveToolsetOrigin(custom ?? {}),
474
- getService: (serviceId, serviceOptions) => getService(serviceId, serviceOptions),
475
- telemetry: custom?.disableTelemetry ? void 0 : async (event, payload) => {
476
- await collectTelemetry({
477
- event,
478
- server,
479
- ...payload
480
- });
481
- }
470
+ origin: resolveToolsetOrigin(server.ctx.custom ?? {}),
471
+ getService: (serviceId, serviceOptions) => getService(serviceId, serviceOptions)
482
472
  };
483
473
  }
474
+ async function reportToolsetTelemetry(server, event, report) {
475
+ if (!report || server.ctx.custom?.disableTelemetry)
476
+ return;
477
+ let { payload, toolset, tool } = report;
478
+ await collectTelemetry({ event, server, ...payload, toolset, tool });
479
+ }
484
480
  async function callToolsetMethod(server, options, input) {
485
- let toolset = resolveToolset(options, server), method = resolveMethod(toolset, options), ctx = buildContext(server);
481
+ let toolset = resolveToolset(options, server), { methodName } = parseToolsetMethodId(options.method), method = toolset.methods[methodName];
486
482
  try {
487
- let outcome = await method.handler(input, ctx), structuredContent = await toStructuredContent(method.output, outcome.data);
483
+ let outcome = await invokeToolsetMethod(toolset, methodName, input, buildContext(server));
484
+ await reportToolsetTelemetry(server, options.mcpEventName, outcome.telemetry);
485
+ let structuredContent = await toStructuredContent(method.output, outcome.data);
488
486
  return {
489
487
  content: (Array.isArray(outcome.markdown) ? outcome.markdown : [outcome.markdown]).map((text) => ({ type: "text", text })),
490
488
  ...structuredContent !== void 0 ? { structuredContent } : {},
@@ -545,8 +543,17 @@ function compositionDocsToolset(server) {
545
543
  })
546
544
  });
547
545
  }
546
+ var DOCS_EVENT_NAMES = {
547
+ "docs.list": "tool:listAllDocumentation",
548
+ "docs.show": "tool:getDocumentation",
549
+ "docs.showStory": "tool:getDocumentationForStory"
550
+ };
548
551
  function docsToolDefinition(method) {
549
- let forContext = (context) => context.multiSource ? { method, resolveToolset: (server) => compositionDocsToolset(server) } : { method };
552
+ let forContext = (context) => ({
553
+ method,
554
+ mcpEventName: DOCS_EVENT_NAMES[method],
555
+ ...context.multiSource ? { resolveToolset: (server) => compositionDocsToolset(server) } : {}
556
+ });
550
557
  return {
551
558
  name: toMcpToolName3(method),
552
559
  toolset: "docs",
@@ -566,6 +573,7 @@ var docsToolDefinitions = [
566
573
  toolset: "dev",
567
574
  options: {
568
575
  method: "stories.preview",
576
+ mcpEventName: "tool:previewStories",
569
577
  extras: { _meta: { ui: { resourceUri: PREVIEW_STORIES_RESOURCE_URI } } }
570
578
  }
571
579
  }),
@@ -596,12 +604,12 @@ var docsToolDefinitions = [
596
604
  fromToolset({
597
605
  toolset: "dev",
598
606
  available: ({ availability }) => availability.changeDetectionEnabled,
599
- options: { method: "stories.changed" }
607
+ options: { method: "stories.changed", mcpEventName: "tool:getChangedStories" }
600
608
  }),
601
609
  fromToolset({
602
610
  toolset: "dev",
603
611
  available: ({ availability }) => availability.moduleGraphSupported,
604
- options: { method: "stories.findByComponent" }
612
+ options: { method: "stories.findByComponent", mcpEventName: "tool:getStoriesByComponent" }
605
613
  }),
606
614
  fromToolset({
607
615
  toolset: "dev",
@@ -612,13 +620,14 @@ var docsToolDefinitions = [
612
620
  wrapEnabled: (server, { availability }, enabled) => async () => (await enabled?.() ?? !0) && (server.ctx.custom?.reviewEnabled ?? availability.reviewEnabled),
613
621
  options: {
614
622
  method: "review.create",
623
+ mcpEventName: "tool:displayReview",
615
624
  wrapSchema: withFriendlyErrors
616
625
  }
617
626
  }),
618
627
  fromToolset({
619
628
  toolset: "test",
620
629
  available: ({ availability }) => availability.testSupported,
621
- options: { method: "test.run" }
630
+ options: { method: "test.run", mcpEventName: "tool:runStoryTests" }
622
631
  }),
623
632
  // Docs run on the core docs toolset in both modes. A composition builds its toolset per request,
624
633
  // because the sources it reads and the provider that fetches them belong to the request.
@@ -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.0",
7
+ version: "11.0.0-alpha.1",
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.0",
3
+ "version": "11.0.0-alpha.1",
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.0",
46
- "@storybook/addon-vitest": "11.0.0-alpha.0",
47
- "storybook": "11.0.0-alpha.0",
45
+ "@storybook/addon-a11y": "11.0.0-alpha.1",
46
+ "@storybook/addon-vitest": "11.0.0-alpha.1",
47
+ "storybook": "11.0.0-alpha.1",
48
48
  "typescript": "^6.0.3"
49
49
  },
50
50
  "peerDependencies": {
51
- "@storybook/addon-vitest": "^11.0.0-alpha.0",
52
- "storybook": "^11.0.0-alpha.0"
51
+ "@storybook/addon-vitest": "^11.0.0-alpha.1",
52
+ "storybook": "^11.0.0-alpha.1"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@storybook/addon-vitest": {