Repository navigation
design-system-mcp: Serve pattern guidance through get_patterns and get_pattern_details - #82548
juanmaguitar wants to merge 5 commits into
Conversation
Pattern guidance lives as MDX under storybook/stories/design-system/patterns
and is not reachable through any of the server's tools. Add the index, the
fetching, and the MDX-to-markdown formatting, so the tools can serve it.
The index is maintained by hand because a document's title can be declared
indirectly (<Meta of={ ... } />), leaving no readable title in the source. A
test reads the stories directory and fails when the two fall out of sync.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The server answers which component to use, but not when to use it. Asked to build a delete-account flow with the server as its only source, an agent gets ConfirmDialog back and nothing about when to use it versus a Modal with a destructive button, so it guesses. The two tools mirror get_components and get_component_details, including the array form for fetching several documents in one call. The server instructions now point clients at the patterns before implementing a flow, since a tool that is never called does not close the gap. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
🤖 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 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
|
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Registering each pattern by hand in the server made a new document silently invisible to agents until someone remembered the extra step, and a test that fails on the omission still leaves the step there. The Storybook build now generates build/manifests/patterns.json from every document in the patterns directory, alongside the components manifest it already publishes, and the server only consumes it. Titles and descriptions come from each document's own heading and introduction, so the manifest cannot describe a pattern differently from how the Storybook presents it, and a new pattern needs no registration anywhere. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Ran the testing instructions locally against the MCP Inspector. Recording the results so a reviewer does not have to repeat them. Tools. Five listed:
Automatic discovery. Dropped an see command to create storybook/stories/design-system/patterns/undo.mdxcat > storybook/stories/design-system/patterns/undo.mdx <<'EOF'
import { Meta } from '@storybook/addon-docs/blocks';
<Meta title="Design System/Patterns/Undo" />
# Undo
A throwaway document to check that a new pattern is discovered with no code change. Delete it after testing.
## When to Use
- Never. This is a test fixture.
EOF |
|
Exciting to see this starting to get integrated, thanks for working on it @juanmaguitar ! I'll plan to give it a closer look tomorrow, but one initial thought I want to highlight based on first impression: Can we explore the Storybook-native equivalent of the components manifest for written documentation? I recall that they had a concept of a The manifests feature is still experimental and I know it's been changing pretty dramatically lately (which I encountered in #80697), so I'm not familiar with what the "state of the art" is here at the moment. I think the most important thing to unblock us now would be to make sure that we don't bind ourselves to something that will be difficult to update later. A URL like |
|
Should we close this? The linked issue is marked as resolved. |
|
Yes, this was superseded by #84864, which built on this and credited @juanmaguitar 's work. The description there includes details about how it differs from this pull request. Thanks @juanmaguitar for pushing this along, and @Mamaduka for the nudge to close it! |



What?
Adds
get_patternsandget_pattern_detailsto the design system MCP server, serving the pattern guidance documents understorybook/stories/design-system/patterns/.Closes #82547
Why?
The server answers which component to use, but not when to use it. Asked to build a delete-account flow with the MCP server as its only source, an agent gets
ConfirmDialogback and nothing about when to use it versus aModalwith a destructive button, so it guesses. The decision tree that answers exactly that already exists indestructive-actions.mdx, and no tool serves it. Same shape as the Tooltip case in #80649 (comment).No documentation is duplicated: the same
.mdxfiles serve humans in the Storybook and agents through the MCP.How?
storybook/scripts/generate-patterns-manifest.mjsruns as part ofstorybook:build, alongside the post-processors already applied to the components manifest, and writesbuild/manifests/patterns.jsonfrom every document in the patterns directory. Each entry's title and description come from the document's own heading and introductory paragraph, so the manifest cannot describe a pattern differently from how the Storybook presents it, and the content is the document with its Storybook framing (module imports,<Meta />,<Canvas />) stripped.manifests/components.json, withPATTERNS_MANIFEST_URLto override the location..mdxin the directory is published and served with no registration step anywhere. A document without a heading or an introduction fails the build rather than shipping unnamed.get_componentsandget_component_details, including the array form for fetching several documents in one call.instructionsnow point clients at the patterns before implementing a flow. A tool that is never called does not close the gap.Per-component guidance (
packages/ui/src/*/stories/usage-guidelines.mdx,best-practices.mdx) has the same problem but is scoped to a component rather than cross-cutting, so it fits better as an addition toget_component_details. Left as a follow-up, noted in the issue.Testing Instructions
1. Unit tests
The generator test reads the real patterns directory and asserts the manifest has an entry for every
.mdxin it, so a pattern cannot be added without being served.2. Run the server, no coding agent needed
Node 24 runs the TypeScript sources directly, so this needs no build, and no Storybook deploy: the dev server generates the manifest itself and hands it to the server as a
data:URL. Createpackages/design-system-mcp/dev-server.mjs:Then open it in MCP Inspector, which lists the tools and calls them from a form:
Expected: five tools listed.
get_patternsreturns the three patterns, each described by its own opening paragraph.get_pattern_detailswithdestructive-actionsreturns the decision tree as plain markdown, starting at# Destructive Actions, with noimportline and no<Meta />. An unknown slug returnsisErrorand points atget_patterns.Drop an
.mdxwith a heading and a paragraph intostorybook/stories/design-system/patterns/, restart, and it appears inget_patternswith no code change. Delete it afterwards, along withdev-server.mjs, which is deliberately not part of this PR.To exercise the published artifact instead, run
npm run storybook:buildfor a realbuild/manifests/patterns.jsonandnpm run buildfor the package, then point the Inspector atpackages/design-system-mcp/bin/design-system-mcp.mjswithPATTERNS_MANIFEST_URLset to that file, served over HTTP.3. End to end, the part the unit tests cannot cover
The tests prove the tools return the right documents. They cannot prove an agent decides to call them, which is the actual gap this addresses. Register that dev server with an agent in an empty directory outside Gutenberg, and ask for something the component list alone does not answer:
Expected: the agent calls
get_patterns, thenget_pattern_detailsfordestructive-actions, and justifies the choice from the decision tree. Deleting an account cannot be undone, so it should reach for aModalwith a destructive button rather thanConfirmDialog. Ontrunkthe same prompt returnsConfirmDialogwith no reasoning available to back it.Use of AI Tools
Claude Code was used to implement this change and to write the tests. All of it was reviewed before submitting.
🤖 Generated with Claude Code