Add support for using story ID as input for preview and test tools#175
Add support for using story ID as input for preview and test tools#175
Conversation
…as an alternative to story paths
🦋 Changeset detectedLatest commit: b8bf0a1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
Pull request overview
This PR extends the Storybook MCP addon + MCP library to support story ID–based workflows (storyId) alongside the existing path/export-based story addressing, and surfaces story IDs in documentation output to enable that flow end-to-end.
Changes:
- Add
{ storyId }as an alternativeStoryInputshape and wire it intopreview-storiesandrun-story-testsvia shared ID resolution logic. - Enhance docs output/formatters to include story IDs (plus
withStoryIdsoption forlist-all-documentation). - Add/adjust unit + E2E coverage and introduce eval tasks (914/915) to validate strategy selection (path-based vs docs-first ID flow).
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/mcp/src/utils/manifest-formatter/markdown.ts | Surfaces story IDs in component markdown and adds optional story ID sub-bullets for list formatting. |
| packages/mcp/src/utils/manifest-formatter/markdown.test.ts | Updates/extends formatter tests to assert story ID rendering and list sub-bullets. |
| packages/mcp/src/utils/manifest-formatter/snapshots/markdown.test.ts.snap | Snapshot updates reflecting story ID lines and story ID-labeled “Other Stories”. |
| packages/mcp/src/tools/list-all-documentation.ts | Adds withStoryIds input and passes list-format options through. |
| packages/mcp/src/tools/list-all-documentation.test.ts | Adds test coverage for withStoryIds: true behavior. |
| packages/mcp/src/tools/get-documentation.ts | Updates tool description to clarify story IDs are included. |
| packages/mcp/src/tools/get-documentation.test.ts | Updates expectations to include “Story ID:” lines. |
| packages/mcp/fixtures/small-manifest.fixture.json | Adds id fields to fixture stories to support story ID output/tests. |
| packages/addon-mcp/src/utils/find-story-ids.ts | Adds { storyId } resolution path and normalizes importPath matching for path-based inputs. |
| packages/addon-mcp/src/utils/find-story-ids.test.ts | Adds tests for storyId lookup + adjusts typing assertions. |
| packages/addon-mcp/src/types.ts | Refactors StoryInput to a union of path-based and storyId shapes (shared props/globals). |
| packages/addon-mcp/src/tools/run-story-tests.ts | Updates schema descriptions to document when to prefer storyId vs path-based input. |
| packages/addon-mcp/src/tools/run-story-tests.test.ts | Adds focused test run coverage using { storyId } inputs. |
| packages/addon-mcp/src/tools/preview-stories.ts | Switches to shared findStoryIds to support { storyId } inputs in preview URLs. |
| packages/addon-mcp/src/tools/preview-stories.test.ts | Adds preview coverage for { storyId } input shape. |
| packages/addon-mcp/README.md | Documents both path-based and ID-based inputs and withStoryIds usage guidance. |
| eval/variant-configs/preview-by-id-internal.ts | Adds internal eval variant matrix covering tasks 914–915. |
| eval/templates/grading/.storybook/main.ts | Enables experimentalComponentsManifest for grading template runs. |
| eval/tasks/915-preview-story-by-id/prompt.md | New eval prompt for previewing existing stories (docs-first ID flow). |
| eval/tasks/915-preview-story-by-id/prompt.docs-first.md | Prompt variant that explicitly forces docs-first behavior. |
| eval/tasks/915-preview-story-by-id/post-prepare-trial/stories/Button.stories.tsx | Trial fixture story file for task 915. |
| eval/tasks/915-preview-story-by-id/post-prepare-trial/src/components/Button.tsx | Trial fixture component for task 915. |
| eval/tasks/915-preview-story-by-id/post-prepare-trial/.storybook/preview.tsx | Trial fixture Storybook preview config for task 915. |
| eval/tasks/915-preview-story-by-id/hooks.ts | Adds quality hooks asserting storyId input strategy usage. |
| eval/tasks/915-preview-story-by-id/config.json | Defines expected MCP tool calls, including withStoryIds: true. |
| eval/tasks/915-preview-story-by-id/README.md | Documents purpose + scoring for task 915. |
| eval/tasks/914-preview-story-by-path/prompt.md | New eval prompt to write a story then preview via path-based inputs. |
| eval/tasks/914-preview-story-by-path/post-prepare-trial/stories/Button.stories.tsx | Trial fixture story file for task 914. |
| eval/tasks/914-preview-story-by-path/post-prepare-trial/src/components/Button.tsx | Trial fixture component for task 914. |
| eval/tasks/914-preview-story-by-path/post-prepare-trial/.storybook/preview.tsx | Trial fixture Storybook preview config for task 914. |
| eval/tasks/914-preview-story-by-path/hooks.ts | Adds quality hooks asserting path-based preview inputs and avoiding unnecessary docs calls. |
| eval/tasks/914-preview-story-by-path/config.json | Defines expected MCP tool calls for task 914. |
| eval/tasks/914-preview-story-by-path/README.md | Documents purpose + scoring for task 914. |
| apps/internal-storybook/tests/mcp-endpoint.e2e.test.ts | Updates tool JSON-schema snapshots for new input shapes/options and updated descriptions. |
| apps/internal-storybook/tests/mcp-composition.e2e.test.ts | Updates composition expectations to include story IDs in docs output. |
| apps/internal-storybook/tests/mcp-composition-auth.e2e.test.ts | Updates auth composition expectations to include story IDs in docs output. |
| .changeset/smart-clouds-glow.md | Changeset entry for patch releases of @storybook/mcp and @storybook/addon-mcp. |
Bundle ReportChanges will decrease total bundle size by 58.52kB (-54.99%) ⬇️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: @storybook/addon-mcp-esmAssets Changed:
view changes for bundle: @storybook/mcp-esmAssets Changed:
Files in
|
There was a problem hiding this comment.
I've changed the findStoryIds function to return an array instead of an object, so that tools can maintain the same input->output order of the results, even when there are mixed found/not-found cases.
❌ 1 Tests Failed:
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
…nto id-story-input
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 38 out of 41 changed files in this pull request and generated 2 comments.
Files not reviewed (3)
- apps/internal-storybook/pnpm-lock.yaml: Language not supported
- eval/pnpm-lock.yaml: Language not supported
- packages/addon-mcp/pnpm-lock.yaml: Language not supported
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 38 out of 41 changed files in this pull request and generated no new comments.
Files not reviewed (3)
- apps/internal-storybook/pnpm-lock.yaml: Language not supported
- eval/pnpm-lock.yaml: Language not supported
- packages/addon-mcp/pnpm-lock.yaml: Language not supported
This pull request introduces story ID-based inputs to the preview and testing tools, making it easier for agents and tools to reference stories directly.
preview-storiesandrun-story-tests, while retaining path-based story inputs.list-all-documentationandget-documentation), allowing agents to discover and reuse IDs without extra filesystem lookup steps.Previously, we saw numerous times that the agent would use the docs tools to get information about a component, then traverse the file system to find the story files so it could get story IDs for previewing/testing stories. That was inefficient. Now story IDs can be used directly, so if the agent doesn't have the file already in context, it will use the docs tool to get the IDs, and then preview/test stories.
In situations where it already has the file in context, it will still used the path-based inputs.
Evals shows that this is both faster and cheaper (in the minimal scenario).