You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,8 +29,12 @@ The `@storybook/mcp` package (in `packages/mcp`) is framework-agnostic:
29
29
30
30
- Uses `tmcp` with HTTP transport and Valibot schema validation
31
31
- Factory pattern: `createStorybookMcpHandler()` returns a request handler
32
-
- Context-based: handlers accept `StorybookContext` to override source URLs
32
+
- Context-based: handlers accept `StorybookContext` to override source URLs and provide optional callbacks
33
33
-**Exports tools and types** for reuse by `addon-mcp` and other consumers
34
+
-**Optional handlers**: `StorybookContext` supports optional handlers that are called at various points, allowing consumers to track usage or collect telemetry:
35
+
-`onSessionInitialize`: Called when an MCP session is initialized
36
+
-`onListAllComponents`: Called when the list-all-components tool is invoked
37
+
-`onGetComponentDocumentation`: Called when the get-component-documentation tool is invoked
Copy file name to clipboardExpand all lines: .github/instructions/addon-mcp.instructions.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -350,6 +350,36 @@ The addon collects anonymous usage data:
350
350
- Tool usage events (which tools are called and how often)
351
351
- Client information (MCP client name)
352
352
353
+
**For addon-specific tools**: Telemetry is collected directly in the tool implementation using `collectTelemetry()`.
354
+
355
+
**For reused tools from `@storybook/mcp`**: The addon uses optional handlers (`onListAllComponents`, `onGetComponentDocumentation`) provided by the `StorybookContext` to track usage. These handlers are passed in the context when calling `transport.respond()` in `mcp-handler.ts`:
Copy file name to clipboardExpand all lines: .github/instructions/mcp.instructions.md
+26-7Lines changed: 26 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,10 +13,11 @@ This is a Model Context Protocol (MCP) server for Storybook that serves knowledg
13
13
### Key Components
14
14
15
15
-**MCP Server**: Built using the `tmcp` library with HTTP transport
16
-
-**Tools System**: Extensible tool registration system (includes `list_all_components` and `get_component_documentation`)
16
+
-**Tools System**: Extensible tool registration system with optional handlers for tracking tool usage
17
17
-**Component Manifest**: Parses and formats component documentation including React prop information from react-docgen
18
18
-**Schema Validation**: Uses Valibot for JSON schema validation via `@tmcp/adapter-valibot`
19
19
-**HTTP Transport**: Provides HTTP-based MCP communication via `@tmcp/transport-http`
20
+
-**Context System**: `StorybookContext` allows passing optional handlers (`onSessionInitialize`, `onListAllComponents`, `onGetComponentDocumentation`) that are called at various points when provided
20
21
21
22
### File Structure
22
23
@@ -68,7 +69,8 @@ Component manifests can include a `reactDocgen` property containing prop informa
68
69
```
69
70
70
71
**Type serialization examples:**
71
-
- Unions: `"primary" | "secondary"`
72
+
73
+
- Unions: `"primary" | "secondary"`
72
74
- Functions: `(event: MouseEvent) => void`
73
75
- Objects: `{ name: string; age?: number }`
74
76
- Arrays: `string[]`
@@ -192,20 +194,37 @@ To add a new MCP tool:
192
194
1. Create a new file in `src/tools/` (e.g., `src/tools/my-tool.ts`)
193
195
2. Export a constant for the tool name
194
196
3. Export an async function that adds the tool to the server:
0 commit comments