@storybook/mcp 0.0.4 → 0.0.5

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,7 +19,64 @@ 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";
@@ -29,7 +87,41 @@ declare const GET_TOOL_NAME = "get-component-documentation";
29
87
  declare function addGetComponentDocumentationTool(server: McpServer<any, StorybookContext>): 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.5";
9
9
  var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
10
10
 
11
11
  //#endregion
@@ -248,9 +248,15 @@ async function addListAllComponentsTool(server) {
248
248
  description: "List all available UI components from the component library"
249
249
  }, async () => {
250
250
  try {
251
+ const manifest = await getManifest(server.ctx.custom?.source, server.ctx.custom?.manifestProvider);
252
+ const componentList = formatComponentManifestMapToList(manifest);
253
+ await server.ctx.custom?.onListAllComponents?.({
254
+ context: server.ctx.custom,
255
+ manifest
256
+ });
251
257
  return { content: [{
252
258
  type: "text",
253
- text: formatComponentManifestMapToList(await getManifest(server.ctx.custom?.source, server.ctx.custom?.manifestProvider))
259
+ text: componentList
254
260
  }] };
255
261
  } catch (error) {
256
262
  return errorToMCPContent(error);
@@ -273,12 +279,14 @@ async function addGetComponentDocumentationTool(server) {
273
279
  const manifest = await getManifest(server.ctx.custom?.source, server.ctx.custom?.manifestProvider);
274
280
  const content = [];
275
281
  const notFoundIds = [];
282
+ const foundComponents = [];
276
283
  for (const componentId of input.componentIds) {
277
284
  const component = manifest.components[componentId];
278
285
  if (!component) {
279
286
  notFoundIds.push(componentId);
280
287
  continue;
281
288
  }
289
+ foundComponents.push(component);
282
290
  content.push({
283
291
  type: "text",
284
292
  text: formatComponentManifest(component)
@@ -293,6 +301,12 @@ async function addGetComponentDocumentationTool(server) {
293
301
  text: `${severity}: ${componentWord} not found: ${notFoundIds.join(", ")}`
294
302
  });
295
303
  }
304
+ await server.ctx.custom?.onGetComponentDocumentation?.({
305
+ context: server.ctx.custom,
306
+ input: { componentIds: input.componentIds },
307
+ foundComponents,
308
+ notFoundIds
309
+ });
296
310
  return {
297
311
  content,
298
312
  ...allNotFound && { isError: true }
@@ -315,15 +329,16 @@ const createStorybookMcpHandler = async (options = {}) => {
315
329
  adapter,
316
330
  capabilities: { tools: { listChanged: true } }
317
331
  }).withContext();
332
+ if (options.onSessionInitialize) server.on("initialize", options.onSessionInitialize);
318
333
  await addListAllComponentsTool(server);
319
334
  await addGetComponentDocumentationTool(server);
320
335
  const transport = new HttpTransport(server, { path: null });
321
336
  return (async (req, context) => {
322
- const source = context?.source ?? options.source;
323
- const manifestProvider = context?.manifestProvider ?? options.manifestProvider;
324
337
  return await transport.respond(req, {
325
- source,
326
- manifestProvider
338
+ source: context?.source ?? options.source,
339
+ manifestProvider: context?.manifestProvider ?? options.manifestProvider,
340
+ onListAllComponents: context?.onListAllComponents ?? options.onListAllComponents,
341
+ onGetComponentDocumentation: context?.onGetComponentDocumentation ?? options.onGetComponentDocumentation
327
342
  });
328
343
  });
329
344
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/mcp",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -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",