Skip to content

fix(version): drop PKG_VERSION hardcode — second-pass audit M1#45

Merged
heznpc merged 3 commits into
mainfrom
fix/pkg-version-dynamic
May 21, 2026
Merged

fix(version): drop PKG_VERSION hardcode — second-pass audit M1#45
heznpc merged 3 commits into
mainfrom
fix/pkg-version-dynamic

Conversation

@heznpc
Copy link
Copy Markdown
Member

@heznpc heznpc commented May 21, 2026

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:23 hardcoded const PKG_VERSION = "0.4.0"; and passed it to new McpServer({ name: "create-starter", version: PKG_VERSION }).
  • src/cli.ts:105-114 already had a readVersion() helper that dynamically resolves package.json#version at runtime.
  • Inconsistent. Next minor bump (0.5.0 release flow) would leave the MCP server's serverInfo.version stuck at 0.4.0 while CLI -v correctly reports 0.5.0.
  • Neither scripts/bundle-mcpb.mjs nor any test gates this — PR-1 caught the same shape of drift in manifest.json but missed this one inside src/.

Fix

  • New src/version.ts exports readVersion() — the same logic that was inline in cli.ts.
  • src/index.ts calls readVersion() for the McpServer constructor.
  • src/cli.ts imports the shared helper and drops the duplicate impl + the node:fs / node:path / node:url imports that supported it.

Smoke verification

MCP serverInfo: {"name":"create-starter","version":"0.4.0"}
CLI -v:         create-starter 0.4.0

Both come from the same package.json read now.

Why this works inside the .mcpb bundle

scripts/bundle-mcpb.mjs stages dist/ and package.json into the same staging-root. After install, dirname(import.meta.url) for dist/index.js resolves 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 build clean
  • npm 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)
  • MCP initialize returns serverInfo.version = 0.4.0
  • CLI -v returns create-starter 0.4.0
  • CI green

Note: this PR will need to update-branch after PR-44 (contract test) merges, since branch protection is strict: true.

… 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.
@heznpc heznpc enabled auto-merge (squash) May 21, 2026 13:22
@heznpc heznpc merged commit ca89592 into main May 21, 2026
6 checks passed
@heznpc heznpc deleted the fix/pkg-version-dynamic branch May 21, 2026 15:28
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.

1 participant