Skip to content

fix(mcp-proxy): use FS to read storybook version#269

Open
huang-julien wants to merge 5 commits into
mainfrom
fix/cached_storybookversion
Open

fix(mcp-proxy): use FS to read storybook version#269
huang-julien wants to merge 5 commits into
mainfrom
fix/cached_storybookversion

Conversation

@huang-julien

Copy link
Copy Markdown
Contributor

Bug found during #260

When using import or require, nodeJS caches the result/module and since MCP-proxy is usually a long-living process, updates to storybook during this time won't be catched because of nodeJS returning the cached module.

We need to switch to path resolve, FS read and JSON parse.

Copilot AI review requested due to automatic review settings June 3, 2026 12:15
@netlify

netlify Bot commented Jun 3, 2026

Copy link
Copy Markdown

Deploy Preview for storybook-mcp-self-host-example canceled.

Name Link
🔨 Latest commit 2800ad4
🔍 Latest deploy log https://app.netlify.com/projects/storybook-mcp-self-host-example/deploys/6a282a7a90a4f200082582b9

@changeset-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2800ad4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 3, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/storybookjs/mcp/@storybook/addon-mcp@269
npx https://pkg.pr.new/storybookjs/mcp/@storybook/mcp@269
npx https://pkg.pr.new/storybookjs/mcp/@storybook/mcp-proxy@269

commit: 5337691

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
@storybook/mcp-proxy-esm 29.54kB 431 bytes (1.48%) ⬆️

Affected Assets, Files, and Routes:

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

Assets Changed:

Asset Name Size Change Total Size Change (%)
src-DL1HleYI.js (New) 26.44kB 26.44kB 100.0% 🚀
src-bOva-aPl.js (Deleted) -26.01kB 0 bytes -100.0% 🗑️

Files in src-DL1HleYI.js:

  • ./src/tools/clear-version-cache.ts → Total Size: 1.15kB

  • ./src/tools/proxy-tool.ts → Total Size: 2.98kB

  • ./src/utils/version-check.ts → Total Size: 1.47kB

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.97%. Comparing base (4e7061c) to head (5337691).
⚠️ Report is 23 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/mcp-proxy/src/utils/version-check.ts 83.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #269      +/-   ##
==========================================
+ Coverage   78.40%   78.97%   +0.57%     
==========================================
  Files          57       63       +6     
  Lines        1565     1812     +247     
  Branches      434      515      +81     
==========================================
+ Hits         1227     1431     +204     
- Misses        202      213      +11     
- Partials      136      168      +32     

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates @storybook/mcp-proxy’s Storybook version detection to avoid Node’s module cache by resolving storybook/package.json from the project cwd and reading/parsing it from disk, so long-lived proxy processes can observe in-session installs/upgrades.

Changes:

  • Switch Storybook version detection from require('storybook/package.json') to require.resolve(...) + readFileSync(...) + JSON.parse(...).
  • Adjust caching behavior to cache only ok results (and re-check on every call for too-old / not-installed).
  • Update unit tests and the “clear version cache” tool description to reflect the new behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/mcp-proxy/src/utils/version-check.ts Reads storybook/package.json from disk to avoid require/import caching; changes caching policy.
packages/mcp-proxy/src/utils/version-check.test.ts Updates mocks/tests to reflect disk-read version detection and revised caching semantics.
packages/mcp-proxy/src/tools/clear-version-cache.ts Updates tool description to clarify cache-clearing is now rarely needed.

Comment thread packages/mcp-proxy/src/utils/version-check.ts Outdated
Comment thread packages/mcp-proxy/src/utils/version-check.test.ts Outdated
@huang-julien huang-julien requested a review from kasperpeulen June 3, 2026 12:20
Comment thread packages/mcp-proxy/src/utils/version-check.ts Outdated
Copilot AI review requested due to automatic review settings June 3, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread packages/mcp-proxy/src/utils/version-check.ts
Comment thread packages/mcp-proxy/src/tools/clear-version-cache.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


if (resolution.kind === 'intercept') {
if (
resolution.reason === 'no-instance' &&
title: 'Clear Storybook Version Cache',
description:
'Clear the in-memory cached Storybook version detection for a project. Call this after upgrading Storybook (e.g. via the `storybook-upgrade` skill) so the proxy re-reads `storybook/package.json` on the next tool call instead of returning the stale `too-old` result.',
'Manually clear the in-memory cached Storybook version detection for a project. Rarely needed: the proxy already re-reads `storybook/package.json` from disk on every call for `too-old`/`not-installed` projects (only an `ok` result is cached), so an upgrade or fresh install is picked up automatically. Use this as an escape hatch if a tool call still reports a stale version after an in-session change.',
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.

2 participants