fix(version): drop PKG_VERSION hardcode — second-pass audit M1#45
Merged
Conversation
… hardcode)
Adversarial second-pass audit (M1):
src/index.ts:23 hardcoded `const PKG_VERSION = "0.4.0"` while
src/cli.ts:105-114 correctly resolved version from package.json at
runtime. Inconsistent — and the next minor bump would silently leave
the MCP server reporting the old version in `serverInfo` to clients
(Claude Desktop / Cursor / etc.) while the CLI -v output stays correct.
- Extract readVersion() to src/version.ts (shared helper).
- src/index.ts imports it for new McpServer({ version }).
- src/cli.ts imports the same helper; drops the duplicate impl and the
node:fs/node:path/node:url imports that supported it.
Smoke-verified:
- MCP serverInfo.version = 0.4.0 (dynamic, matches package.json)
- CLI -v = create-starter 0.4.0 (unchanged)
This also covers the path inside the .mcpb bundle: staging structure
keeps package.json alongside dist/, so dirname(import.meta.url) + '../'
resolves the same in dev and packaged contexts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this PR exists
The 2026-05-21 adversarial second-pass audit caught a Major drift point in this session's work that PR-5 (#40) shipped.
src/index.ts:23hardcodedconst PKG_VERSION = "0.4.0";and passed it tonew McpServer({ name: "create-starter", version: PKG_VERSION }).src/cli.ts:105-114already had areadVersion()helper that dynamically resolvespackage.json#versionat runtime.serverInfo.versionstuck at 0.4.0 while CLI-vcorrectly reports 0.5.0.scripts/bundle-mcpb.mjsnor any test gates this — PR-1 caught the same shape of drift inmanifest.jsonbut missed this one insidesrc/.Fix
src/version.tsexportsreadVersion()— the same logic that was inline incli.ts.src/index.tscallsreadVersion()for the McpServer constructor.src/cli.tsimports the shared helper and drops the duplicate impl + thenode:fs/node:path/node:urlimports that supported it.Smoke verification
Both come from the same package.json read now.
Why this works inside the
.mcpbbundlescripts/bundle-mcpb.mjsstagesdist/andpackage.jsoninto the same staging-root. After install,dirname(import.meta.url)fordist/index.jsresolves to<staging>/dist/, and../package.json→<staging>/package.json— the bundled package's metadata. Same path resolution as the dev tree.Test plan
npm run buildcleannpm test— 85/85 pass (was 85; no new tests in this PR — covered by PR-44's contract test which now exists on main once that merges)initializereturnsserverInfo.version= 0.4.0-vreturnscreate-starter 0.4.0Note: this PR will need to update-branch after PR-44 (contract test) merges, since branch protection is
strict: true.