Addon MCP: Make endpoint configurable#233
Conversation
✅ Deploy Preview for storybook-mcp-self-host-example canceled.
|
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 76.06% 76.46% +0.39%
==========================================
Files 52 52
Lines 1412 1419 +7
Branches 391 394 +3
==========================================
+ Hits 1074 1085 +11
+ Misses 205 203 -2
+ Partials 133 131 -2 ☔ View full report in Codecov by Sentry. |
🦋 Changeset detectedLatest commit: e68bf67 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Bundle ReportChanges will decrease total bundle size by 41 bytes (-0.05%) ⬇️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: @storybook/mcp-esmAssets Changed:
Files in
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new endpoint addon option to @storybook/addon-mcp, allowing the MCP HTTP route to be served somewhere other than /mcp while keeping /mcp as the default. It also updates OAuth protected-resource metadata generation and adds test coverage + a Changesets entry for the new option.
Changes:
- Add
endpoint?: stringto addon options schema and wire it into the preset’s dev server route registration (GET/POST). - Update
.well-known/oauth-protected-resourcegeneration to use the configured endpoint. - Add unit tests for the configurable route and OAuth metadata, plus a minor Changesets entry.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/addon-mcp/src/types.ts | Adds endpoint to the addon options Valibot schema/types. |
| packages/addon-mcp/src/preset.ts | Uses the configured endpoint for MCP GET/POST and passes it into OAuth well-known generation. |
| packages/addon-mcp/src/preset.test.ts | Tests registering a custom MCP endpoint route. |
| packages/addon-mcp/src/auth/composition-auth.ts | Uses the configured endpoint when building protected-resource metadata. |
| packages/addon-mcp/src/auth/composition-auth.test.ts | Updates tests to cover the new buildWellKnown signature. |
| .changeset/quiet-rivers-connect.md | Declares a minor release for the new addon option. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
packages/addon-mcp/src/preset.ts:41
- With a custom
endpoint, requests will haverequest.urlending in that endpoint (e.g./custom-mcp). The docs tools reused from@storybook/mcpderive manifest URLs by replacing a trailing/mcpinrequest.url(seepackages/mcp/src/utils/get-manifest.ts), so in single-source mode (no refs) manifest fetching will break and attempt to fetch manifests from the MCP endpoint path. To keep docs tools working whenendpointis customized, create amanifestProviderunconditionally (e.g. viacompositionAuth.createManifestProvider(origin)) instead of only when refs are configured.
// Get composed Storybook refs from config
const refs = await getRefsFromConfig(options);
const compositionAuth = new CompositionAuth();
// Build sources and manifest provider only if refs are configured
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 10 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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 10 changed files in this pull request and generated 1 comment.
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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 13 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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 12 changed files in this pull request and generated 3 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
Comments suppressed due to low confidence (1)
packages/addon-mcp/src/auth/composition-auth.ts:143
- Changing
buildWellKnown(origin: string)tobuildWellKnown({ origin, endpoint })is a breaking public API change for any external consumers constructingCompositionAuthdirectly (it’s exported). If you want to avoid a breaking change, consider keeping the original signature (and optionally adding an overload/new method) so existing callers continue to work while enabling the new endpoint-aware behavior.
/** Build .well-known/oauth-protected-resource response. */
buildWellKnown({
origin,
endpoint = DEFAULT_MCP_ENDPOINT,
}: {
origin: string;
endpoint?: string;
}): object | null {
if (!this.#authRequirement) return null;
return {
resource: this.#buildMcpEndpointUrl(origin, endpoint),
authorization_servers: this.#authRequirement.resourceMetadata.authorization_servers,
scopes_supported: this.#authRequirement.resourceMetadata.scopes_supported,
};
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 19 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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 15 changed files in this pull request and generated 1 comment.
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
Comments suppressed due to low confidence (1)
packages/addon-mcp/src/auth/composition-auth.ts:296
new URL(DEFAULT_MCP_ENDPOINT, origin)also drops any base pathname (e.g.https://host/storybook->https://host/mcp). Hereoriginis effectively a base URL for the Storybook instance (can include a path), so this can mis-detect auth requirements when Storybook is hosted under a sub-path. AppendDEFAULT_MCP_ENDPOINTto the provided base URL instead.
/** Quick check: does the remote MCP endpoint return 401? */
async #isMcpUnauthorized(origin: string): Promise<boolean> {
try {
const response = await fetch(new URL(DEFAULT_MCP_ENDPOINT, origin).toString(), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list' }),
});
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 76.06% 76.21% +0.15%
==========================================
Files 52 52
Lines 1412 1417 +5
Branches 391 393 +2
==========================================
+ Hits 1074 1080 +6
Misses 205 205
+ Partials 133 132 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 15 changed files in this pull request and generated 1 comment.
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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 15 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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 15 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
3119636 to
e68bf67
Compare
TL;DR
Adds an optional
endpointoption to@storybook/addon-mcpso the addon dev server can serve MCP somewhere other than/mcp.Default behavior is unchanged: without
endpoint, the addon still registers/mcp. The option only configures the local addon route; composed remote refs and OAuth metadata keep the existing/mcpbehavior.Companion PR: storybookjs/storybook#34863.
Usage
Review Map
Start with the behavior surface:
packages/addon-mcp/src/types.tsparsesendpoint?: stringas a URL pathname.packages/addon-mcp/src/preset.tsapplies the parsed endpoint to the addon GET/POST MCP routes.packages/mcp/src/utils/get-manifest.tskeeps Storybook manifests top-level by deriving/manifests/...from the request origin, independent of the MCP endpoint path.Tests to review next:
packages/addon-mcp/src/types.test.tscovers endpoint parsing and rejection directly at the schema boundary.packages/addon-mcp/src/preset.test.tscovers default/mcp, custom endpoints, no-refs behavior, and refs/local-manifest behavior.packages/mcp/src/utils/get-manifest.test.tscovers manifest URL resolution for default, trailing slash, nested custom endpoint, prefixed path, and localhost custom endpoint requests.packages/addon-mcp/src/auth/composition-auth.test.tsonly addsstubGlobalcleanup;composition-auth.tsitself is not changed in the final diff.Docs/release notes:
packages/addon-mcp/README.mddocuments addon configuration.README.mdmentions the configured endpoint in local debug instructions..changeset/quiet-rivers-connect.mdmarks the new addon option as a minor change.Mechanical/CI-required:
pnpm-workspace.yamland generated lockfiles refresh Storybook packages from10.5.0-alpha.1to10.5.0-alpha.2; the repo dependency freshness test requires this.Non-goals
/manifests/...resources.Review Notes
This branch is now a single focused commit. Review the final Files changed diff in the order above: option schema, route wiring, shared manifest URL derivation, tests, docs, then generated lockfile/catalog refreshes.
Validation
Local checks run on this branch:
pnpm linthas 0 errors and the same 2 unrelated warnings in untouched test files.