Skip to content

Fix createStorybookMcpHandler not forwarding the sources option#194

Merged
JReinhold merged 1 commit intomainfrom
fix-sources-create-api
Mar 11, 2026
Merged

Fix createStorybookMcpHandler not forwarding the sources option#194
JReinhold merged 1 commit intomainfrom
fix-sources-create-api

Conversation

@JReinhold
Copy link
Copy Markdown
Contributor

@JReinhold JReinhold commented Mar 11, 2026

This docs-PR comment surfaced a problem: #172 (comment)

The createStorybookMcpHandler API didn't forward the sources option to the request context, so it didn't apply in that scenario (only in the scenario where the individual tool-adders are used).

Now the logic is changed so that all options are always forwarded and merged correctly.

Copilot AI review requested due to automatic review settings March 11, 2026 14:38
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: eb0ea73

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 Patch
@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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 11, 2026

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

commit: eb0ea73

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.91%. Comparing base (762c0e8) to head (eb0ea73).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #194      +/-   ##
==========================================
+ Coverage   73.28%   73.91%   +0.63%     
==========================================
  Files          42       42              
  Lines        1179     1177       -2     
  Branches      333      330       -3     
==========================================
+ Hits          864      870       +6     
+ Misses        198      192       -6     
+ Partials      117      115       -2     

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

Copy link
Copy Markdown
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 fixes createStorybookMcpHandler() so handler-level sources are forwarded into the per-request transport context, enabling multi-source manifest behavior to work when configured at handler creation time.

Changes:

  • Forward all handler-level StorybookContext options (including sources) into transport.respond() by default.
  • Keep onSessionInitialize as a handler-level-only option (not part of per-request context).
  • Add tests covering handler-level sources forwarding and per-request override behavior, plus a changeset.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/mcp/src/index.ts Changes context construction/merging so handler-level options (incl. sources) flow into the transport context.
packages/mcp/src/index.test.ts Adds regression tests for forwarding sources and for per-request override semantics.
.changeset/fair-pianos-smile.md Documents the patch-level fix for consumers.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread packages/mcp/src/index.ts
Comment on lines 107 to 111
return await transport.respond(req, {
...defaultContext,
...context,
request: req,
manifestProvider: context?.manifestProvider ?? options.manifestProvider,
onListAllDocumentation: context?.onListAllDocumentation ?? options.onListAllDocumentation,
onGetDocumentation: context?.onGetDocumentation ?? options.onGetDocumentation,
});
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Spreading ...context over ...defaultContext changes the precedence semantics compared to the previous nullish-coalescing merge: if a caller passes a per-request context where fields like manifestProvider, sources, onListAllDocumentation, or onGetDocumentation are present but undefined (e.g. via object-spread), this will now overwrite the handler-level defaults and can fall back to the default provider unexpectedly. Consider merging per-field with nullish coalescing (or a merge helper that ignores undefined) so handler-level options remain the default unless the request explicitly supplies a defined override.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is okay actually.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 11, 2026

Bundle Report

Changes will decrease total bundle size by 170 bytes (-0.34%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@storybook/mcp-esm 44.24kB -170 bytes (-0.38%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: @storybook/mcp-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js -170 bytes 29.97kB -0.56%

Files in index.js:

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

Copy link
Copy Markdown
Member

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

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

LGTM

@JReinhold JReinhold merged commit e53012e into main Mar 11, 2026
16 checks passed
@JReinhold JReinhold deleted the fix-sources-create-api branch March 11, 2026 15:41
@storybook-app-bot storybook-app-bot Bot mentioned this pull request Mar 11, 2026
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