Handle private composed sources as own-MCP notices#242
Conversation
🦋 Changeset detectedLatest commit: 7c28163 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 |
✅ Deploy Preview for storybook-mcp-self-host-example canceled.
|
commit: |
Bundle ReportChanges will increase total bundle size by 2.39kB (3.1%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: @storybook/mcp-esmAssets Changed:
Files in
view changes for bundle: @storybook/mcp-proxy-esmAssets Changed:
Files in
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #242 +/- ##
==========================================
+ Coverage 76.21% 77.26% +1.05%
==========================================
Files 52 53 +1
Lines 1417 1465 +48
Branches 393 407 +14
==========================================
+ Hits 1080 1132 +52
+ Misses 205 202 -3
+ Partials 132 131 -1 ☔ View full report in Codecov by Sentry. |
3a24d24 to
ff7948a
Compare
ff7948a to
d142450
Compare
There was a problem hiding this comment.
Pull request overview
Adds a “requires own MCP” notice flow for private composed Storybook sources that can’t be read through the local MCP proxy, keeping those sources visible and returning routing guidance (instead of failing the whole tool call or forcing an OAuth challenge in the proxy path).
Changes:
- Introduces a helper to compute a composed source’s
/mcpendpoint and format non-error routing guidance. - Extends multi-source manifest fetching + markdown formatting to carry and render per-source “notice” entries (without an
error:prefix). - Updates addon + proxy integration to mark proxied requests with
X-Storybook-MCP-Proxy: trueand switch proxy-originated unauthenticated private-source behavior from OAuth challenge to “use own MCP” guidance, with targeted tests and a changeset.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/mcp/src/utils/requires-own-mcp.ts | Adds endpoint derivation and user-facing notice text for “use the source’s own MCP”. |
| packages/mcp/src/utils/requires-own-mcp.test.ts | Validates endpoint derivation for root + subpath-hosted Storybooks (incl. query/hash). |
| packages/mcp/src/utils/get-manifest.ts | Adds RequiresOwnMcpError, maps it to non-error MCP content, and surfaces notices in multi-source results. |
| packages/mcp/src/utils/get-manifest.test.ts | Covers multi-source notice capture behavior and success-vs-notice accounting. |
| packages/mcp/src/types.ts | Adds RequiresOwnMcpNotice and a notice field to SourceManifests. |
| packages/mcp/src/utils/manifest-formatter/markdown.ts | Renders per-source notices as guidance (not error:) in multi-source lists. |
| packages/mcp/src/utils/manifest-formatter/markdown.test.ts | Ensures notices render without an error: prefix. |
| packages/mcp/src/tools/list-all-documentation.ts | Avoids treating notice-only sources as successful manifests for callback purposes. |
| packages/mcp/src/tools/list-all-documentation.test.ts | Asserts list output includes routing notices for private composed sources. |
| packages/mcp/src/tools/get-documentation.test.ts | Verifies selected-source own-MCP routing notice behavior. |
| packages/mcp/src/tools/get-documentation-for-story.test.ts | Verifies selected-source own-MCP routing notice behavior for story docs. |
| packages/mcp/src/index.ts | Exports RequiresOwnMcpError and RequiresOwnMcpNotice for consumers. |
| packages/mcp/README.md | Documents the new notice field and RequiresOwnMcpNotice type. |
| packages/addon-mcp/src/auth/composition-auth.ts | Adds proxy-mode “requires own MCP” behavior for unauthenticated private remotes via RequiresOwnMcpError. |
| packages/addon-mcp/src/auth/composition-auth.test.ts | Tests the trusted-proxy unauthenticated path yields RequiresOwnMcpError (and doesn’t record auth error state). |
| packages/addon-mcp/src/auth/index.ts | Re-exports proxy header constants + proxy-request detection helper. |
| packages/addon-mcp/src/preset.ts | Makes manifest provider per-request and bypasses OAuth challenge only for proxy-marked requests. |
| packages/addon-mcp/src/preset.test.ts | Tests direct unauthenticated requests still get OAuth 401, while proxy-marked requests reach MCP and get the new provider behavior. |
| packages/mcp-proxy/src/utils/proxy-client.ts | Adds X-Storybook-MCP-Proxy: true marker header on proxied tool calls. |
| packages/mcp-proxy/src/utils/proxy-client.test.ts | Verifies the proxy header is sent. |
| .changeset/loud-maps-promise.md | Declares patch releases for @storybook/mcp and @storybook/addon-mcp. |
| @@ -42,7 +58,18 @@ type MCPErrorResult = { | |||
| * @param error - The error to convert (can be any type) | |||
| * @returns A tool result with error content and isError flag | |||
| */ | |||
TL;DR
Smaller replacement for #235. This keeps the current architecture and adds one narrow path for private composed Storybooks reached through the local Storybook MCP proxy:
list-all-documentation401challengeBehavior contract
list-all-documentationshows private composed sources instead of dropping the whole multi-source response into an OAuth/tool error.get-documentationandget-documentation-for-storyreturn the same own-MCP guidance when the selected source cannot be read through the local proxy.X-Storybook-MCP-Proxy: trueis treated as our internal proxy routing signal. It is not a security boundary.https://example.com/storybook/->https://example.com/storybook/mcp.Review order
packages/mcp/src/utils/requires-own-mcp.tspackages/mcp/src/utils/get-manifest.tsandpackages/mcp/src/types.tsRequiresOwnMcpErrorand thenoticevariant onSourceManifests.RequiresOwnMcpErroris an exception for control flow, but it becomes non-error MCP content.packages/mcp/src/utils/manifest-formatter/markdown.tserror:prefix, so agents see routing guidance rather than a failed tool call.packages/mcp/src/tools/list-all-documentation.tspackages/addon-mcp/src/auth/composition-auth.tsandpackages/addon-mcp/src/preset.tspackages/mcp-proxy/src/utils/proxy-client.tsX-Storybook-MCP-Proxymarker on proxied tool calls. The proxy does not know about private sources.Tests
Validation
pnpm exec oxfmt --check ...pnpm vitest --project=@storybook/mcp --run packages/mcp/src/utils/requires-own-mcp.test.ts packages/mcp/src/utils/get-manifest.test.ts packages/mcp/src/utils/manifest-formatter/markdown.test.ts packages/mcp/src/tools/list-all-documentation.test.ts packages/mcp/src/tools/get-documentation.test.ts packages/mcp/src/tools/get-documentation-for-story.test.tspnpm vitest --project=@storybook/mcp-proxy --run packages/mcp-proxy/src/utils/proxy-client.test.tspnpm vitest --project=@storybook/addon-mcp --run packages/addon-mcp/src/auth/composition-auth.test.ts packages/addon-mcp/src/preset.test.tspnpm --filter @storybook/addon-mcp run buildpnpm --filter @storybook/mcp run buildpnpm turbo run typecheck --filter=@storybook/mcp --filter=@storybook/addon-mcp --filter=@storybook/mcp-proxypnpm changeset status --since=origin/maingit diff --check