Repository navigation
Design System MCP: Add patterns tools using Storybook MDX manifest output - #84864
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.56 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Delete (forward) in
|
There was a problem hiding this comment.
🔵 Needs a closer look
The experimental Storybook manifest output and built MCP integration remain unverified and need human validation.
0 open findings
What changed in this PR
Exposes existing Storybook pattern guidance through the design system MCP server, helping agents choose and compose components for common interactions.
Changes:
- Adds pattern discovery and detail tools backed by Storybook’s native docs manifest.
- Updates server guidance and opts existing patterns into manifest generation.
- Adds parsing, caching, handler tests, and manifest validation.
| File | Description |
|---|---|
| storybook/test/patterns-manifest.test.ts | Checks pattern manifest tags and lead paragraphs. |
| storybook/stories/design-system/patterns/save-and-submit.mdx | Makes the document standalone and manifest-enabled. |
| storybook/stories/design-system/patterns/error-messages.mdx | Enables manifest inclusion. |
| storybook/stories/design-system/patterns/destructive-actions.mdx | Enables manifest inclusion. |
| storybook/README.md | Documents manifest publishing requirements. |
| packages/design-system-mcp/src/types.ts | Adds document and pattern types. |
| packages/design-system-mcp/src/tools/test/get-pattern-details.ts | Tests detail responses and missing patterns. |
| packages/design-system-mcp/src/tools/index.ts | Registers both pattern tools. |
| packages/design-system-mcp/src/tools/get-patterns.ts | Adds pattern discovery. |
| packages/design-system-mcp/src/tools/get-pattern-details.ts | Adds single and batched pattern retrieval. |
| packages/design-system-mcp/src/tools/get-component-details.ts | Reuses the shared lookup helper. |
| packages/design-system-mcp/src/test/parse-patterns.ts | Tests pattern extraction and filtering. |
| packages/design-system-mcp/src/test/fixtures/docs-manifest.json | Adds representative manifest data. |
| packages/design-system-mcp/src/test/data.ts | Tests pattern fetching, caching, and lookup. |
| packages/design-system-mcp/src/parse-patterns.ts | Extracts patterns from manifest entries. |
| packages/design-system-mcp/src/index.ts | Exports parsing and updates server instructions. |
| packages/design-system-mcp/src/format.ts | Formats pattern listings. |
| packages/design-system-mcp/src/find-each.ts | Shares ordered lookup handling. |
| packages/design-system-mcp/src/data.ts | Fetches, caches, and retrieves patterns. |
| packages/design-system-mcp/scripts/validate-manifest.mjs | Validates generated pattern availability. |
| packages/design-system-mcp/README.md | Documents pattern guidance capabilities. |
| packages/design-system-mcp/CHANGELOG.md | Records the new tools. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| } | ||
|
|
||
| const slug = componentId.slice( PATTERN_ID_PREFIX.length ); | ||
| const content = source.slice( start ).trim(); |
There was a problem hiding this comment.
get_pattern_details returns the Save & Submit example as <Canvas of={ SaveSubmitStories.SaveFormLayoutCard } />, so MCP clients never receive the form code shown in Storybook.
Should we try to expand those nested canvases into the underlying code block?
There was a problem hiding this comment.
This is a really good point. Ideally an AI agent should receive the same rendered documentation that a human would be able to see in the live Storybook.
Although ironically in this case it's not a great example, because the live Storybook code snippet is not all that helpful at the moment either 😅 (the rendered code is wrapped in a component and preview only shows the name of the wrapper)
The changes in 12b4564 adjust the story to assign the actual component code to render, and implement the behavior of expanding canvases.
I'm not super enthusiastic about the AI's implementation, particularly around using regular expressions for matching imports and components, but it's a relatively straight-forward approach and degrades gracefully.
Other ideas I had was to either change where we implement the story examples (e.g. inline in the .mdx), but I don't think this is very possible with how we want <Canvas /> to work.
There was a problem hiding this comment.
One remaining item I need to address before this is ready is that referencing snippet code from components.json means that various scripts that use it as a canonical reference of components will start seeing "Save & Submit", now that it's marked as manifest. This isn't technically a problem for the MCP server because it ignores entries outside expected packages directories, but some tests and other consumers could be impacted.
There was a problem hiding this comment.
The more I look at this, the more I think it might make sense to punt <Canvas /> expansion as a future improvement and keep the rest of this pull request as-is.
Specifically, the changes explored in my previous comments required that the pattern story code snippets be added to the components.json manifest. Until now, we've been treating the components.json manifest as the canonical list of design system components. Enabling manifest for these pattern stories also produces parser errors where it can't find an associated component. Essentially my concern is that it muddies what components.json actually is, where some components are linked to design system components, and others exist to satisfy this canvas expansion for patterns.
As part of exploring this, I also revisited and refreshed #80697, which is the proof-of-concept of migrating to Storybook's still-unfinished v1 manifest structure. In this structure, components.json and docs.json still exist, but they point to files at storybook/build/services, where parsed result of all stories (manifest or not) are included. You can check out the branch and test this locally if you want.
My thinking is that there might be a clearer path to unfurling canvas snippets under the v1 manifest. And frankly, the way that the v1 manifest is managing "related resources" with a $ref link structure leads me to think that Storybook itself could be linking these related resources.
Which is all to say: Rather than manipulate the component manifest to our purpose under the v0 manifest, I'd suggest we wait and solve this under the v1 manifest.
There was a problem hiding this comment.
I also checked Storybook's own MCP server implementation, and they don't do anything special for <Canvas /> either. Their design is a little different where documents that are attached to components bring all relevant documentation for the component along with the response. This doesn't transfer as well to our case here, because the stories in question are not actually associated with a component.
There was a problem hiding this comment.
And frankly, the way that the v1 manifest is managing "related resources" with a
$reflink structure leads me to think that Storybook itself could be linking these related resources.
Related upstream question: storybookjs/storybook#35333 (comment)
There was a problem hiding this comment.
Deferring Canvas expansion until the manifest v1 work seems reasonable. Let's track it as a follow-up for both Save & Submit and Copy to Clipboard.
There was a problem hiding this comment.
Let's track it as a follow-up for both Save & Submit and Copy to Clipboard.
Follow-up tracking issue at #85969
…tput Co-authored-by: JuanMa <juanma.garrido@gmail.com>
ebb2eed to
de753a7
Compare
… snippets" This reverts commit 12b4564.
|
Relatedly, mentioning here since it's related, I also looked at exposing other guidance documents ("how to use badge?") alongside patterns like in this PR ("how to build settings page?") A few other design system MCPs also had similar tool. Alternatively surfacing those "howto" guides alongside |
Yeah, this is how I was considering this, when I was looking at it before. I feel like "Usage guidelines" for using a particular component makes sense to be included as part of the details of that component, rather than through a separate tool. Particularly since agents are rather conservative with the number of tool calls they're willing to make (part of the reason we added bulk details requests in #78185). |
Yep! I think this makes sense. |
|
Doing some last-minute testing here to see how this behaves in a real AI environment, I happened to get a really nice Before & After because I misconfigured the MCP in my first attempt, thus producing a result that didn't have access to the patterns. And in that case, it provided wrong advice, responding that deletion should happen immediately without any prompt for a reversible action. After the pattern guidance was made available, it provided the correct advice, with details about ConfirmDialog, not using destructive intents for buttons, and showing an Undo action afterward.
Regarding some of the gaps it flagged: On further prompting, I think the failure to reach for |
…tput (WordPress#84864) * Design System MCP: Add patterns tools using Storybook MDX manifest output Co-authored-by: JuanMa <juanma.garrido@gmail.com> * Design System MCP: Expand canvases using component story code snippets * Revert "Design System MCP: Expand canvases using component story code snippets" This reverts commit 12b4564. * design-system-mcp: Move CHANGELOG note under Unreleased * Storybook: Add "Copy to Clipboard" pattern title and manifest tag --------- Co-authored-by: JuanMa <juanma.garrido@gmail.com> Co-authored-by: aduth <aduth@git.wordpress.org> Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: simison <simison@git.wordpress.org>


What?
Closes #82547
Adds new
get_patternsandget_pattern_detailstools to the@wordpress/design-system-mcpMCP server, and updates server instructions on how to consider patterns in relation to components.This achieves the same goal as @juanmaguitar 's #82548, with the key implementation difference being that it relies on Storybook's default manifest behavior emitting
docs.jsoninstead of a custom patterns extraction.Why?
The current set of MCP tools provide agents with an understanding of which components and tokens exist, but little in the form of guidance around how to compose components for common interface patterns. As a design system, we have started to document patterns for common interactions like destructive actions, error messages, and form submission, but these were until now these have not been surfaced to AI agents that use the design system MCP server. By adding patterns to the MCP server, we can continue to grow the library of patterns that describe how components can be composed together to solve common user interaction patterns.
How?
As mentioned above, this follows much of the same implementation direction as #82548 but relies on Storybook's native manifest feature. As such, it also follows the same expectations as how we document components through the MCP server by using the
'manifest'tag with patterns guidance through the<Meta />component.It's wort noting that this manifest shape is going to change in future iterations of Storybook, as the manifest feature we rely on is currently experimental. This applies to both the components manifest and documentation manifests. Early exploration of this is happening in #80697, but I'm waiting for the manifests feature to stabilize before making any changes.
It also goes further by rewriting the server instructions to account for how patterns fit alongside component and token tools in a more holistic sense, and which tools should be used for specific types of requests.
Testing Instructions
The most effective way to test this is using the MCP Inspector tool to see what an agent sees for the new tools:
npm run storybook:buildto build Storybook and its manifestscd storybook/build && php -S 127.0.0.1:8000to host Storybook locally on a static file server (so the MCP server can reference the local manifests)npx @modelcontextprotocol/inspector node packages/design-system-mcp/bin/design-system-mcp.mjs -- -e DOCS_MANIFEST_URL=http://localhost:8000/manifests/docs.json -e COMPONENTS_MANIFEST_URL=http://localhost:8000/manifests/components.jsonto start the inspector process configured to the local server and manifestScreenshots or screencast
Use of AI Tools
Used Claude Code + Opus 5.5