-
Notifications
You must be signed in to change notification settings - Fork 656
Adding the storybook mcp agent so that copilot can effectively work with our storybook docs #7704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jonrohan
wants to merge
6
commits into
main
Choose a base branch
from
storybook_mcp_server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,447
−811
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7fa502
Update storybook and add a mcp server
jonrohan aafd378
fix(rollup.config.js): specify extensions for nodeResolve plugin
jonrohan 7d75aa3
Fix more rollup config
jonrohan f6a0339
Fix for styled-react
jonrohan 3e0a927
Fix lint issue with zod and eslint-plugin-react-hooks@7.0.1
jonrohan 283b1f4
chore: update dependencies and improve build script for styled-react
jonrohan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| name: storybook | ||
| description: 'Use when: starting, checking, or using the Storybook dev server; looking up Primer React component stories, props, or documentation; previewing component variants; writing or verifying Storybook stories; using the primer-storybook MCP to explore components. Covers starting Storybook, checking if it is running, and using MCP tools (list-all-documentation, get-documentation, get-storybook-story-instructions, preview-stories) to look up components.' | ||
| --- | ||
|
|
||
| # Storybook — Start Server & Use MCP | ||
|
|
||
| ## When to Use | ||
|
|
||
| - You need to look up a component's stories, props, or usage examples | ||
| - You are writing or editing a Storybook story | ||
| - You want to preview a component variant at a URL | ||
| - Any task that benefits from live Storybook documentation | ||
|
|
||
| --- | ||
|
|
||
| ## Step 1 — Ensure Storybook Is Running | ||
|
|
||
| Storybook must be running **before** any MCP tool calls. The MCP server is served by Storybook at `http://localhost:6006/mcp`. | ||
|
|
||
| ### Check if it is already running | ||
|
|
||
| ```bash | ||
| curl -s -o /dev/null -w "%{http_code}" http://localhost:6006 | ||
| ``` | ||
|
|
||
| - **200 / 3xx** → Storybook is already up. Skip to Step 2. | ||
| - **000 / connection refused** → Start it now. | ||
|
|
||
| ### Start Storybook | ||
|
|
||
| Run from the workspace root (not `packages/react`): | ||
|
|
||
| ```bash | ||
| npm start | ||
| ``` | ||
|
|
||
| This starts the Storybook dev server on `http://localhost:6006`. It takes ~3–10 seconds. | ||
| Run as a **background process** so the agent continues working. | ||
|
|
||
| ### Verify it is ready | ||
|
|
||
| Poll until the server responds: | ||
|
|
||
| ```bash | ||
| until curl -s -o /dev/null -w "%{http_code}" http://localhost:6006 | grep -q "200\|301\|302"; do sleep 1; done | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 2 — Use the `primer-storybook` MCP | ||
|
|
||
| The `primer-storybook` MCP is configured in `.vscode/mcp.json` as an HTTP server at `http://localhost:6006/mcp`. | ||
|
|
||
| Load deferred tools before calling them: | ||
|
|
||
| ``` | ||
| tool_search_tool_regex pattern: "mcp_primer-storyb" | ||
| ``` | ||
|
|
||
| ### Available Tools | ||
|
|
||
| | Tool | When to Use | | ||
| | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | ||
| | `mcp_primer-storyb_list-all-documentation` | Discover all available component and documentation IDs — call once per task | | ||
| | `mcp_primer-storyb_get-documentation` | Retrieve full docs, props, and examples for a component by `id` | | ||
| | `mcp_primer-storyb_get-documentation-for-story` | Get docs for a specific story variant not covered by `get-documentation` | | ||
| | `mcp_primer-storyb_get-storybook-story-instructions` | Get framework-specific imports and story patterns — always call before writing/editing stories | | ||
| | `mcp_primer-storyb_preview-stories` | Get live preview URLs for stories — always include returned URLs in your response | | ||
|
|
||
| ### Workflow | ||
|
|
||
| 1. **Always list first**: Call `list-all-documentation` to get the full list of valid IDs. **Never call `get-documentation` without first obtaining an ID from this list.** Do not guess or infer IDs from component names (e.g. `"button"` is wrong — the correct ID is `"components-button"`). | ||
| 2. **Match the ID**: Find the entry in the list that corresponds to the component you need. IDs follow the pattern `components-<componentname>` (e.g. `components-button`, `components-actionmenu`). | ||
| 3. **Get by ID**: Call `get-documentation` with the exact `id` from the list (use `storybookId` to scope to one source when multiple are configured). | ||
| 4. **Verify props**: Never invent props or variants not present in the documentation. | ||
| 5. **Before writing stories**: Always call `get-storybook-story-instructions` first — treat its output as the source of truth. | ||
| 6. **After changing stories**: Call `preview-stories` and include every returned URL in your response. | ||
|
|
||
| --- | ||
|
|
||
| ## Rules | ||
|
|
||
| - Do **not** call MCP tools before Storybook is running — they will fail silently. | ||
| - **Always** call `list-all-documentation` before `get-documentation` — never guess or derive an ID from a component name. Only use `id` values returned by this list. | ||
| - **Never invent props or variants** not present in the documentation. Only use properties explicitly documented or shown in example stories — do not assume properties based on naming conventions or patterns from other libraries. If a property isn't documented, report it as not found and check back with the user. | ||
| - Before writing or editing stories, always call `get-storybook-story-instructions` — treat its output as the source of truth. | ||
| - Check your work by running `run-story-tests`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run-story-testsdoesn’t appear to be a runnable command or documented script in this repo (a full-text search only finds it here). This will send users down a dead end; please replace it with an actual verification command used in this repo (e.g. the Playwright Storybook-based checks documented in contributor-docs/testing.md) or remove this bullet if there isn’t a supported local command.