fix(mcp-proxy): use FS to read storybook version#269
Conversation
✅ Deploy Preview for storybook-mcp-self-host-example canceled.
|
|
commit: |
Bundle ReportChanges will increase total bundle size by 431 bytes (0.27%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: @storybook/mcp-proxy-esmAssets Changed:
Files in
|
Codecov Report❌ Patch coverage is
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. |
There was a problem hiding this comment.
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')torequire.resolve(...)+readFileSync(...)+JSON.parse(...). - Adjust caching behavior to cache only
okresults (and re-check on every call fortoo-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. |
|
|
||
| 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.', |
Bug found during #260
When using
importorrequire, 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.