@storybook/mcp 0.0.4 → 0.0.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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { McpServer } from "tmcp";
2
- import "valibot";
2
+ import * as v from "valibot";
3
+ import { Documentation } from "react-docgen";
3
4
 
4
5
  //#region src/types.d.ts
5
6
 
@@ -18,18 +19,109 @@ interface StorybookContext extends Record<string, unknown> {
18
19
  * The function receives the source URL and should return the manifest as a string.
19
20
  */
20
21
  manifestProvider?: (source: string) => Promise<string>;
22
+ /**
23
+ * Optional handler called when list-all-components tool is invoked.
24
+ * Receives the context and the component manifest.
25
+ */
26
+ onListAllComponents?: (params: {
27
+ context: StorybookContext;
28
+ manifest: ComponentManifestMap;
29
+ }) => void | Promise<void>;
30
+ /**
31
+ * Optional handler called when get-component-documentation tool is invoked.
32
+ * Receives the context, input parameters, and the found components.
33
+ */
34
+ onGetComponentDocumentation?: (params: {
35
+ context: StorybookContext;
36
+ input: {
37
+ componentIds: string[];
38
+ };
39
+ foundComponents: ComponentManifest[];
40
+ notFoundIds: string[];
41
+ }) => void | Promise<void>;
21
42
  }
43
+ declare const ComponentManifest: v.ObjectSchema<{
44
+ readonly id: v.StringSchema<undefined>;
45
+ readonly summary: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
46
+ readonly examples: v.ExactOptionalSchema<v.ArraySchema<v.ObjectSchema<{
47
+ readonly snippet: v.StringSchema<undefined>;
48
+ readonly name: v.StringSchema<undefined>;
49
+ readonly description: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
50
+ readonly import: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
51
+ readonly jsDocTags: v.ExactOptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
52
+ }, undefined>, undefined>, undefined>;
53
+ readonly reactDocgen: v.ExactOptionalSchema<v.CustomSchema<Documentation, undefined>, undefined>;
54
+ readonly name: v.StringSchema<undefined>;
55
+ readonly description: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
56
+ readonly import: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
57
+ readonly jsDocTags: v.ExactOptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
58
+ }, undefined>;
59
+ type ComponentManifest = v.InferOutput<typeof ComponentManifest>;
60
+ declare const ComponentManifestMap: v.ObjectSchema<{
61
+ readonly v: v.NumberSchema<undefined>;
62
+ readonly components: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
63
+ readonly id: v.StringSchema<undefined>;
64
+ readonly summary: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
65
+ readonly examples: v.ExactOptionalSchema<v.ArraySchema<v.ObjectSchema<{
66
+ readonly snippet: v.StringSchema<undefined>;
67
+ readonly name: v.StringSchema<undefined>;
68
+ readonly description: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
69
+ readonly import: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
70
+ readonly jsDocTags: v.ExactOptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
71
+ }, undefined>, undefined>, undefined>;
72
+ readonly reactDocgen: v.ExactOptionalSchema<v.CustomSchema<Documentation, undefined>, undefined>;
73
+ readonly name: v.StringSchema<undefined>;
74
+ readonly description: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
75
+ readonly import: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
76
+ readonly jsDocTags: v.ExactOptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>, undefined>;
77
+ }, undefined>, undefined>;
78
+ }, undefined>;
79
+ type ComponentManifestMap = v.InferOutput<typeof ComponentManifestMap>;
22
80
  //#endregion
23
81
  //#region src/tools/list-all-components.d.ts
24
82
  declare const LIST_TOOL_NAME = "list-all-components";
25
- declare function addListAllComponentsTool(server: McpServer<any, StorybookContext>): Promise<void>;
83
+ declare function addListAllComponentsTool(server: McpServer<any, StorybookContext>, enabled?: Parameters<McpServer<any, StorybookContext>['tool']>[0]['enabled']): Promise<void>;
26
84
  //#endregion
27
85
  //#region src/tools/get-component-documentation.d.ts
28
86
  declare const GET_TOOL_NAME = "get-component-documentation";
29
- declare function addGetComponentDocumentationTool(server: McpServer<any, StorybookContext>): Promise<void>;
87
+ declare function addGetComponentDocumentationTool(server: McpServer<any, StorybookContext>, enabled?: Parameters<McpServer<any, StorybookContext>['tool']>[0]['enabled']): Promise<void>;
30
88
  //#endregion
31
89
  //#region src/index.d.ts
90
+ type InitializeRequestParams = {
91
+ protocolVersion: string;
92
+ capabilities: {
93
+ experimental?: {} | undefined;
94
+ sampling?: {} | undefined;
95
+ elicitation?: {} | undefined;
96
+ roots?: {
97
+ listChanged?: boolean | undefined;
98
+ } | undefined;
99
+ };
100
+ clientInfo: {
101
+ icons?: {
102
+ src: string;
103
+ mimeType?: string | undefined;
104
+ sizes?: string[] | undefined;
105
+ }[] | undefined;
106
+ version: string;
107
+ websiteUrl?: string | undefined;
108
+ name: string;
109
+ title?: string | undefined;
110
+ };
111
+ };
112
+ /**
113
+ * Options for creating a Storybook MCP handler.
114
+ * Extends StorybookContext with server-level configuration.
115
+ */
116
+ interface StorybookMcpHandlerOptions extends StorybookContext {
117
+ /**
118
+ * Optional handler called when an MCP session is initialized.
119
+ * This is only valid at the handler creation level, not per-request.
120
+ * Receives the initialize request parameters from the MCP protocol.
121
+ */
122
+ onSessionInitialize?: (initializeRequestParams: InitializeRequestParams) => void | Promise<void>;
123
+ }
32
124
  type Handler = (req: Request, context?: StorybookContext) => Promise<Response>;
33
- declare const createStorybookMcpHandler: (options?: StorybookContext) => Promise<Handler>;
125
+ declare const createStorybookMcpHandler: (options?: StorybookMcpHandlerOptions) => Promise<Handler>;
34
126
  //#endregion
35
- export { GET_TOOL_NAME, LIST_TOOL_NAME, type StorybookContext, addGetComponentDocumentationTool, addListAllComponentsTool, createStorybookMcpHandler };
127
+ export { type ComponentManifest, type ComponentManifestMap, GET_TOOL_NAME, LIST_TOOL_NAME, type StorybookContext, StorybookMcpHandlerOptions, addGetComponentDocumentationTool, addListAllComponentsTool, createStorybookMcpHandler };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import * as v from "valibot";
5
5
 
6
6
  //#region package.json
7
7
  var name = "@storybook/mcp";
8
- var version = "0.0.4";
8
+ var version = "0.0.6";
9
9
  var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
10
10
 
11
11
  //#endregion
@@ -241,16 +241,23 @@ function formatComponentManifestMapToList(manifest) {
241
241
  //#endregion
242
242
  //#region src/tools/list-all-components.ts
243
243
  const LIST_TOOL_NAME = "list-all-components";
244
- async function addListAllComponentsTool(server) {
244
+ async function addListAllComponentsTool(server, enabled) {
245
245
  server.tool({
246
246
  name: LIST_TOOL_NAME,
247
247
  title: "List All Components",
248
- description: "List all available UI components from the component library"
248
+ description: "List all available UI components from the component library",
249
+ enabled
249
250
  }, async () => {
250
251
  try {
252
+ const manifest = await getManifest(server.ctx.custom?.source, server.ctx.custom?.manifestProvider);
253
+ const componentList = formatComponentManifestMapToList(manifest);
254
+ await server.ctx.custom?.onListAllComponents?.({
255
+ context: server.ctx.custom,
256
+ manifest
257
+ });
251
258
  return { content: [{
252
259
  type: "text",
253
- text: formatComponentManifestMapToList(await getManifest(server.ctx.custom?.source, server.ctx.custom?.manifestProvider))
260
+ text: componentList
254
261
  }] };
255
262
  } catch (error) {
256
263
  return errorToMCPContent(error);
@@ -262,23 +269,26 @@ async function addListAllComponentsTool(server) {
262
269
  //#region src/tools/get-component-documentation.ts
263
270
  const GET_TOOL_NAME = "get-component-documentation";
264
271
  const GetComponentDocumentationInput = v.object({ componentIds: v.pipe(v.array(v.string()), v.minLength(1, "At least one component ID is required")) });
265
- async function addGetComponentDocumentationTool(server) {
272
+ async function addGetComponentDocumentationTool(server, enabled) {
266
273
  server.tool({
267
274
  name: GET_TOOL_NAME,
268
275
  title: "Get Documentation for Components",
269
276
  description: "Get detailed documentation for specific UI components",
270
- schema: GetComponentDocumentationInput
277
+ schema: GetComponentDocumentationInput,
278
+ enabled
271
279
  }, async (input) => {
272
280
  try {
273
281
  const manifest = await getManifest(server.ctx.custom?.source, server.ctx.custom?.manifestProvider);
274
282
  const content = [];
275
283
  const notFoundIds = [];
284
+ const foundComponents = [];
276
285
  for (const componentId of input.componentIds) {
277
286
  const component = manifest.components[componentId];
278
287
  if (!component) {
279
288
  notFoundIds.push(componentId);
280
289
  continue;
281
290
  }
291
+ foundComponents.push(component);
282
292
  content.push({
283
293
  type: "text",
284
294
  text: formatComponentManifest(component)
@@ -293,6 +303,12 @@ async function addGetComponentDocumentationTool(server) {
293
303
  text: `${severity}: ${componentWord} not found: ${notFoundIds.join(", ")}`
294
304
  });
295
305
  }
306
+ await server.ctx.custom?.onGetComponentDocumentation?.({
307
+ context: server.ctx.custom,
308
+ input: { componentIds: input.componentIds },
309
+ foundComponents,
310
+ notFoundIds
311
+ });
296
312
  return {
297
313
  content,
298
314
  ...allNotFound && { isError: true }
@@ -315,15 +331,16 @@ const createStorybookMcpHandler = async (options = {}) => {
315
331
  adapter,
316
332
  capabilities: { tools: { listChanged: true } }
317
333
  }).withContext();
334
+ if (options.onSessionInitialize) server.on("initialize", options.onSessionInitialize);
318
335
  await addListAllComponentsTool(server);
319
336
  await addGetComponentDocumentationTool(server);
320
337
  const transport = new HttpTransport(server, { path: null });
321
338
  return (async (req, context) => {
322
- const source = context?.source ?? options.source;
323
- const manifestProvider = context?.manifestProvider ?? options.manifestProvider;
324
339
  return await transport.respond(req, {
325
- source,
326
- manifestProvider
340
+ source: context?.source ?? options.source,
341
+ manifestProvider: context?.manifestProvider ?? options.manifestProvider,
342
+ onListAllComponents: context?.onListAllComponents ?? options.onListAllComponents,
343
+ onGetComponentDocumentation: context?.onGetComponentDocumentation ?? options.onGetComponentDocumentation
327
344
  });
328
345
  });
329
346
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/mcp",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@tmcp/adapter-valibot": "^0.1.4",
30
- "@tmcp/transport-http": "^0.7.0",
31
- "tmcp": "^1.15.2",
30
+ "@tmcp/transport-http": "^0.8.0",
31
+ "tmcp": "^1.16.0",
32
32
  "valibot": "^1.1.0"
33
33
  },
34
34
  "devDependencies": {
@@ -40,7 +40,7 @@
40
40
  "srvx": "^0.8.16",
41
41
  "tsdown": "^0.15.9",
42
42
  "typescript": "^5.9.3",
43
- "vitest": "^3.2.4"
43
+ "vitest": "3.2.4"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsdown",