Skip to content

Conversation

@JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Oct 30, 2025

Replace the source property in the context with request.

Now you don't pass in a source string that might be fetched or handled by your custom manifestProvider, but instead you pass in the whole web request. (This is automatically handled if you use the createStorybookMcpHandler() function).

The default action is now to fetch the manifest from ../manifests/components.json assuming the server is running at ./mcp. Your custom manifestProvider()-function then also does not get a source string as an argument, but gets the whole web request, that you can use to get information about where to fetch the manifest from.

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2025

🦋 Changeset detected

Latest commit: 68dcf87

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@storybook/mcp Minor
@storybook/addon-mcp Patch

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

@codecov
Copy link

codecov bot commented Oct 30, 2025

Bundle Report

Changes will increase total bundle size by 611 bytes (1.62%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@storybook/mcp-esm 20.64kB 637 bytes (3.18%) ⬆️
@storybook/addon-mcp-esm 17.59kB -26 bytes (-0.15%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: @storybook/mcp-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js 490 bytes 13.71kB 3.71%
index.d.ts 147 bytes 6.92kB 2.17%

Files in index.js:

  • ./src/tools/list-all-components.ts → Total Size: 765 bytes

  • ./src/utils/get-manifest.ts → Total Size: 3.15kB

  • ./src/tools/get-component-documentation.ts → Total Size: 1.77kB

  • ./src/index.ts → Total Size: 910 bytes

  • ./src/types.ts → Total Size: 738 bytes

view changes for bundle: @storybook/addon-mcp-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
preset.js -26 bytes 17.59kB -0.15%

Files in preset.js:

  • ./src/mcp-handler.ts → Total Size: 3.72kB

  • ./src/types.ts → Total Size: 614 bytes

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 30, 2025

npm i https://pkg.pr.new/@storybook/addon-mcp@54
npm i https://pkg.pr.new/@storybook/mcp@54

commit: 68dcf87

@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.12%. Comparing base (572243c) to head (68dcf87).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/mcp/src/index.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next      #54      +/-   ##
==========================================
+ Coverage   81.91%   82.12%   +0.21%     
==========================================
  Files          15       15              
  Lines         846      856      +10     
  Branches      159      154       -5     
==========================================
+ Hits          693      703      +10     
  Misses        145      145              
  Partials        8        8              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JReinhold JReinhold marked this pull request as ready for review October 30, 2025 10:48
Copilot AI review requested due to automatic review settings October 30, 2025 10:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the MCP manifest loading mechanism to use the HTTP Request object instead of a string source URL. This change makes the API more flexible by allowing custom manifest providers to extract additional context (headers, origin, etc.) from the request rather than just a URL string.

Key changes:

  • The getManifest() function now accepts a Request object instead of a source URL string
  • A new getManifestUrlFromRequest() helper constructs the manifest URL by replacing /mcp with /manifests/components.json
  • The manifestProvider signature changed from (source: string) => Promise<string> to (request: Request) => Promise<string>

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/mcp/src/utils/get-manifest.ts Refactored to accept Request object, added URL construction helper, updated default provider
packages/mcp/src/utils/get-manifest.test.ts Updated all tests to pass Request objects via helper function
packages/mcp/src/types.ts Changed StorybookContext to use request property instead of source
packages/mcp/src/tools/list-all-components.ts Updated to pass request instead of source to getManifest
packages/mcp/src/tools/list-all-components.test.ts Updated tests to include request in context
packages/mcp/src/tools/get-component-documentation.ts Updated to pass request instead of source to getManifest
packages/mcp/src/tools/get-component-documentation.test.ts Updated tests to include request in context
packages/mcp/src/index.ts Modified handler to pass request object to transport.respond()
packages/mcp/serve.ts Updated development server to use request parameter in manifestProvider
packages/addon-mcp/src/mcp-handler.ts Changed context to pass request instead of source URL
.github/instructions/mcp.instructions.md Added documentation for request-based context and manifest provider API
.github/copilot-instructions.md Updated architecture descriptions to reflect request-based approach
.changeset/hip-sloths-jog.md Added changeset documenting the breaking change

@JReinhold JReinhold self-assigned this Oct 30, 2025
@JReinhold JReinhold requested a review from tmeasday October 30, 2025 10:50
@JReinhold JReinhold changed the base branch from main to next October 30, 2025 13:40
Comment on lines +65 to +67
// Custom logic: read from local filesystem based on request
const url = new URL(request.url);
const manifestPath = `/path/to/manifests${url.pathname.replace('/mcp', '/components.json')}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longer term we'll be splitting the manifests up right? So it doesn't make sense for the user to do this substitution -- we should be telling them what file we expect them to grab.

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JReinhold I think we are misaligned on this. Perhaps we need to quickly sync on a call.

@JReinhold
Copy link
Contributor Author

We discussed that figuring out the path should be handled internally. Eg. a consumer of this API, can use manifestProvider to decide on the "first part" of a fetch URL by looking at the request (mapping requests to S3 buckets, etc.). But we'll assume that the manifest will live in a built Storybook, so the path should come the MCP server itself, currently always be manifests/components.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants