Add manifestProvider option to allow custom manifest retrieval#32
Merged
Add manifestProvider option to allow custom manifest retrieval#32
Conversation
🦋 Changeset detectedLatest commit: 531a2d4 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 |
Co-authored-by: JReinhold <5678122+JReinhold@users.noreply.github.com>
- Add optional manifestProvider to StorybookMcpHandlerOptions - Update StorybookContext to include manifestProvider - Update fetchManifest to use manifestProvider if provided, fallback to fetch - Update handler creation to pass manifestProvider through context - Update serve.ts to use manifestProvider for reading local fixtures - Add comprehensive tests for manifestProvider functionality - All 53 tests passing with 90%+ coverage Co-authored-by: JReinhold <5678122+JReinhold@users.noreply.github.com>
Co-authored-by: JReinhold <5678122+JReinhold@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add optional manifestProvider to handle creator
Add manifestProvider option to allow custom manifest retrieval
Oct 23, 2025
JReinhold
reviewed
Oct 23, 2025
- Rename files: fetch-manifest.ts → get-manifest.ts and fetch-manifest.test.ts → get-manifest.test.ts - Rename function: fetchManifest → getManifest - Rename error class: ManifestFetchError → ManifestGetError - Update all imports and references across the codebase - Update comments mentioning "fetch" to "get" - Remove vi.clearAllMocks() from beforeEach (Vitest does this automatically) - Remove StorybookMcpHandlerOptions type and use StorybookContext instead - Move coverage to root .gitignore and remove packages/mcp/.gitignore - Add instruction to copilot instructions about Vitest auto-clearing mocks - All 53 tests passing Co-authored-by: JReinhold <5678122+JReinhold@users.noreply.github.com>
Contributor
Author
Changed all "fetch" terminology to "get" throughout the codebase. This includes:
Commit: 8e538fe |
commit: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds an optional
manifestProviderfunction to the@storybook/mcppackage, allowing consumers to define custom logic for retrieving component manifests instead of relying solely on HTTP fetch.Motivation
Previously, the MCP server could only get manifests via HTTP using the built-in
fetchAPI. This created unnecessary complexity when working with local files during development, as demonstrated inserve.tswhich had to spin up an HTTP endpoint just to serve local fixture files to itself.Changes
API Enhancement
The handler now accepts a
StorybookContextobject with optionalmanifestProvider:When provided, the
manifestProviderfunction is called instead offetchto retrieve manifests. The function receives the source URL/path and should return the manifest content as a string. If not provided, the implementation falls back to usingfetchas before.Implementation Details
src/index.ts: Updated to useStorybookContextdirectly for options (removed duplicateStorybookMcpHandlerOptionstype)src/types.ts: ExtendedStorybookContextinterface withmanifestProvidersrc/utils/get-manifest.ts: Renamed fromfetch-manifest.ts, updated to use custom provider when available, with fallback to fetchsrc/tools/*.ts: Updated both tools to passmanifestProviderthrough togetManifest()Terminology Changes
All "fetch" terminology has been changed to "get" throughout the codebase to better reflect that manifests can be retrieved in any way (not just via HTTP fetch):
fetchManifest()→getManifest()ManifestFetchError→ManifestGetErrorfetch-manifest.ts→get-manifest.tsSimplified Development Server
The
serve.tsfile now demonstrates the cleaner approach:This eliminates the need for the HTTP endpoint that previously served local fixtures.
Testing
manifestProviderfunctionalityBackward Compatibility
This is a fully backward-compatible change. Existing code continues to work without modification, as
manifestProvideris optional and defaults to usingfetch.Original prompt
the handle creator in @storybook/mcp needs to take in an optional
manifestProvider?: (source: string) => stringoption. it should be used to consumers can define their own way of getting the manifest, instead of only using fetch. it should fallback to just fetch.add this functionality, and also make the serve.ts file use it as a simpler way to get the local manifests.
[Chronological Review: The conversation began with the user requesting an enhancement to the handle creator in the @storybook/mcp package. The user specified that the enhancement should include an optional `manifestProvider` function to allow consumers to define their own method for obtaining manifests, with a fallback to the default fetch method. The user also requested that the serve.ts file utilize this new functionality for easier access to local manifests.][Intent Mapping:
manifestProvider?: (source: string) => stringoption."[Technical Inventory:
manifestProviderfunction for custom manifest retrieval.manifestProviderfunctionality.][Code Archaeology:
manifestProvideroption into the existing codebase for easier local manifest retrieval.][Progress Assessment:
manifestProvideroption and modifications to serve.ts.][Context Validation: All necessary details for implementing the requested changes are captured, including the need for fallback functionality and integration into serve.ts.]
[Recent Commands Analysis:
manifestProvideroption and its integration into serve.ts.manifestProviderfunctionality and its integration into the serve.ts file when the token budget was exceeded.1. Conversation Overview: - Primary Objectives: - "the handle creator in @storybook/mcp needs to take in an optional `manifestProvider?: (source: string) => string` option." - "it should be used to consumers can define their own way of getting the manifest, instead of only using fetch." - "it should fallback to just fetch." - "add this functionality, and also make the serve.ts file use it as a simpler way to get the local manifests." - Session Context: The user is enhancing the handle creator in the @storybook/mcp package to allow for custom manifest retrieval methods. - User Intent Evolution: The user has consistently focused on improving the flexibility of manifest retrieval while ensuring a fallback mechanism is in place.- Technical Foundation:
- Package: @storybook/mcp
- Functionality: Optional
- Codebase Status:
- File Name: serve.ts
- Purpose: To be modified to utilize the new
- Current State: Pending modifications to integrate the new functionality.
- Problem Resolution:
- Issues Encountered: None explicitly stated; focus is on implementing new functionality.
- Solutions Implemented: Not applicable yet as the implementation is pending.
- Debugging Context: No ongoing troubleshooting efforts mentioned.
- Lessons Learned: The need for flexibility in manifest retrieval methods.
- Progress Tracking:
- Completed Tasks: User has defined the requirements for the new functionality.
- Partially Complete Work: Implementation of the
- Validated Outcomes: None yet, as the implementation has not been completed.
- Active Work State:
- Current Focus: Implementing the
- Recent Context: The user has been discussing the specifics of the
- Working Code: No specific code snippets were provided yet.
- Immediate Context: The user was detailing the requirements for...
manifestProviderfunction for custom manifest retrieval with a fallback to fetch.manifestProviderfunctionality for easier access to local manifests.manifestProvideroption and modifications to serve.ts are pending.manifestProviderfunctionality in the @storybook/mcp package.manifestProvideroption and its integration into serve.ts.Created from VS Code via the GitHub Pull Request extension.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.