Skip to content

fix(mcp): sync User-Agent version with package.json and add CLI validation tests#343

Open
aptsalt wants to merge 3 commits intostripe:mainfrom
aptsalt:fix/version-mismatch-and-test-coverage
Open

fix(mcp): sync User-Agent version with package.json and add CLI validation tests#343
aptsalt wants to merge 3 commits intostripe:mainfrom
aptsalt:fix/version-mismatch-and-test-coverage

Conversation

@aptsalt
Copy link
Copy Markdown

@aptsalt aptsalt commented Mar 30, 2026

Summary

  • Bug fix: userAgent.ts hardcoded VERSION = '0.3.1' but package.json is at 0.3.3, causing the User-Agent header to report an incorrect version to Stripe servers
  • Test coverage: Added missing tests for validateApiKey, validateStripeAccount, and --tools deprecation handling

Changes

  • tools/modelcontextprotocol/src/userAgent.ts: Sync hardcoded version to 0.3.3 (with comment to keep in sync with package.json)
  • tools/modelcontextprotocol/src/test/index.test.ts: Add 6 new test cases covering validateApiKey (4 cases), validateStripeAccount (2 cases), and --tools deprecation (1 case)

Test plan

  • Existing tests pass
  • New validation tests cover edge cases
  • User-Agent string now reports correct version

Related: Noticed during version bump in #330

…LI tests

- VERSION in userAgent.ts was stuck at 0.3.1 while package.json is 0.3.3
- Add test coverage for validateApiKey, validateStripeAccount, and --tools deprecation

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@@ -1,4 +1,5 @@
const VERSION = '0.3.1';
// Keep in sync with version field in package.json
const VERSION = '0.3.3';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call! I looked into importing from tools/typescript/src/shared/constants.ts but since @stripe/mcp is a separate package (no dependency on the typescript toolkit), that import won't resolve.

Two options I see:

  1. Enable resolveJsonModule + import from own package.json — but rootDir: "./src" in tsconfig blocks importing ../package.json. Would need to adjust rootDir or add a build-time injection like tsup does for the shared package.

  2. Replicate the shared pattern — use process.env.PACKAGE_VERSION and inject it at build time via the build script.

Which approach do you prefer? Happy to implement either. Option 2 seems most consistent with how the shared toolkit already handles it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i like option 2! thank you!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done! Just pushed the implementation. userAgent.ts now reads from process.env.PACKAGE_VERSION which gets injected at build time by scripts/inject-version.js same pattern the shared toolkit uses via tsup's define. No more manual version syncing. All tests pass.

Copy link
Copy Markdown
Collaborator

@matv-stripe matv-stripe left a comment

Choose a reason for hiding this comment

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

thank you @aptsalt , left a small comment

Replace hardcoded VERSION constant with process.env.PACKAGE_VERSION,
injected at build time by scripts/inject-version.js. This mirrors the
pattern used by the shared toolkit (tsup define in tools/typescript)
and eliminates manual version sync between userAgent.ts and package.json.

- userAgent.ts: read VERSION from process.env.PACKAGE_VERSION
- scripts/inject-version.js: post-tsc step replaces the env reference
  with the actual version from package.json
- jest.setup.ts: sets PACKAGE_VERSION for test environment
- package.json: updated build script to run inject-version.js

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@aptsalt
Copy link
Copy Markdown
Author

aptsalt commented Mar 30, 2026

Implemented Option 2! Here's what the new commit does:

src/userAgent.ts — Replaced hardcoded version with:

const VERSION = process.env.PACKAGE_VERSION || '0.0.0-development';

scripts/inject-version.js — Post-tsc build step that reads version from package.json and replaces process.env.PACKAGE_VERSION in the compiled dist/userAgent.js with the actual version string. This mirrors how the shared toolkit handles it via tsup's define option.

package.json — Updated build script:

tsc && node scripts/inject-version.js && node -e "require(\"fs\").chmodSync(\"dist/index.js\", \"755\")"

jest.setup.ts + jest.config.ts — Sets PACKAGE_VERSION env var during tests so the version resolves correctly.

All 24 tests pass ✅, build injects version correctly ("0.3.3" baked into dist output).

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