Skip to content

feat: include the version in User-Agent from a single source of truth - #41

Merged
dangrondahl merged 4 commits into
mainfrom
feat/version-in-user-agent
Aug 13, 2026
Merged

dangrondahl merged 4 commits into
mainfrom
feat/version-in-user-agent

Conversation

@dangrondahl

Copy link
Copy Markdown
Contributor

Closes #40.

Requests now send kosli-mcp-server/0.5.0 instead of a bare kosli-mcp-server, so the backend can tell releases apart.

Also fixes a rotted version

src/index.ts registered the MCP server as version: "0.1.0". Every MCP client has been told that since shortly after the first release — through 0.2.0, 0.2.1, 0.3.0, 0.4.0 and 0.5.0. It now uses the same constant.

Why a literal, not a read of package.json

Both obvious approaches are broken here, which is the whole reason this needed a decision rather than a one-liner:

  • Importing ../package.json — tsconfig.json sets rootDir: "src", so a JSON import from outside src/ shifts the outDir layout and dist/index.js is no longer where bin points.
  • Reading it at runtime — scripts/pack-mcpb.sh copies package.json into staging for npm install --omit=dev, then deletes it before zipping. So readFileSync(new URL("../package.json", import.meta.url)) works under npx and throws for every Claude Desktop bundle user.

So src/version.ts exports a literal, with the reasoning in a comment so the next person doesn't "improve" it into one of the above.

The guard

A literal can drift — that's exactly how 0.1.0 survived five releases. test/version.test.ts reads package.json and asserts they match. Tests run from the repo root, so the test can do what the shipped code can't.

I verified the guard fails, rather than only checking it passes:

× VERSION > matches the version in package.json
  → expected '0.4.9' to be '0.5.0'

It also asserts VERSION is plain semver, since it's interpolated into a header.

Verification

  • npm run build clean; npm test 67 passed (was 65).
  • Built output confirmed: dist/client/kosli-client.js:66 carries the template literal, and dist/version.js exports 0.5.0.
  • CLAUDE.md's Releasing section now lists package.json and src/version.ts as moving together, and recommends npm version --no-git-tag-version so the lockfile keeps pace.

Requests now send 'kosli-mcp-server/0.5.0' instead of a bare
'kosli-mcp-server', so the backend can tell releases apart.

Also fixes a version that had silently rotted: src/index.ts registered the
MCP server as 0.1.0, so every client has been told that since shortly after
the first release, through to 0.5.0.

VERSION is a literal in src/version.ts rather than a read of package.json,
because neither alternative works: rootDir is 'src', so importing
../package.json shifts the outDir layout and breaks the bin path; and
pack-mcpb.sh strips package.json from the bundle after installing deps, so
reading it at runtime throws for .mcpb users.

test/version.test.ts closes the loop — tests run from the repo root, so the
test can read package.json even though the shipped code cannot. Verified it
fails on drift, not just passes when aligned.

Closes #40
@claude

claude Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Claude finished @dangrondahl's task in 4m 8s —— View job


Review: feat: include the version in User-Agent from a single source of truth

  • Read CLAUDE.md and gather PR context
  • Review the latest commit (590cb03) — three-file staging + widened semver
  • Verify architectural invariants (three tools, error shape, User-Agent, ESM, strict)
  • Check the release path actually enforces the drift guard
  • Build + test locally — blocked in this environment (see note at the end)

No blocking findings. Both items from the last round are correctly addressed, and the release path is genuinely gated rather than gated-in-theory.


Verified in this round

1. package.json:22 — the staging fix is right.

"version": "npm run sync-version && git add src/version.ts package.json package-lock.json"

This closes the half-state I described last round: under --no-git-tag-version npm writes the files but stages nothing, so the previous hook left src/version.ts staged next to an unstaged package.json, and the documented bare git commit -m … would have committed the mismatch. All three files are now staged, so CLAUDE.md step 2 is correct as written. It stays idempotent in the tag flow, where npm stages the same paths itself.

Worth knowing about the widened pathspec (not worth changing): git add errors on a pathspec that matches nothing, so npm version would now abort — after package.json was already written — in a checkout with no package-lock.json. It's tracked here, and git add on an unmodified tracked file is a successful no-op, so this only bites a repo state that doesn't exist. Same trade you already accepted for git add requiring a work tree.

2. scripts/sync-version.mjs:20 — build metadata. The pattern now matches test/version.test.ts:21 byte-for-byte, and + is a valid tchar (RFC 9110), so kosli-mcp-server/1.0.0+build.1 is a legal User-Agent product-version. The reasoning holds: libnpmversion writes package.json before the hook runs, so rejecting a version npm accepts left exactly the drift this PR removes. The only untested downstream of a + version is cosmetic — the .mcpb filename at scripts/pack-mcpb.sh:10 and the release asset name — and no one is going to publish build metadata from this repo.

3. The guard is on the release path, not just on PRs. release.yml:48 runs npm test before npm publish at line 55, and prepublishOnly runs build+test again. So a src/version.ts that drifts from package.json fails the release rather than shipping — which is what makes the 0.1.0-for-five-releases class of bug actually unrepeatable, not merely documented against.

4. Invariants intact. Three tools unchanged; readOnlyHint/destructiveHint untouched; KosliClient still returns the error-shape object and doesn't throw; compact JSON.stringify; org fallback in buildUrl untouched; no new dependency; fetchFn still injected in test/client/kosli-client.test.ts (no network). src/version.ts sits inside rootDir: "src" so the dist layout and the bin path are unaffected, imports use .js extensions, and strict: true is unchanged. manifest.json still carries 0.0.0-replaced-at-build-time — not hand-edited. Commit subjects are Conventional Commits.

Worth acknowledging

  • sync-version.mjs resolves both paths from import.meta.url rather than process.cwd(), so it's correct however it's invoked — not just from the package root npm happens to give it.
  • The write-only-when-different check means the byte-exact comparison doubles as self-healing: a hand-edited comment is silently restored on the next bump, which is precisely the gap you (correctly) declined to add a CI step for.
  • CLAUDE.md:32 was the important fix. "Preserve this header" sitting next to the pre-PR value was the one line most likely to get this reverted in good faith, and src/version.ts now appearing in "Things not to do" puts the warning where the edit-time reader will hit it.
  • The PR body documents why both obvious approaches fail. That's the part that stops the next person from "fixing" this into readFileSync("../package.json") and breaking every .mcpb user.

Environment note

I could not run npm ci, npm run build, or npm test in this job — dependency installation and node/npm invocation were not permitted, so this round's review is static (diff, tsconfig.json, release.yml, pack-mcpb.sh, manifest.json). The npm-internals claims I made last round came from reading libnpmversion in that run; that path is outside the workspace here, so I'm restating rather than re-verifying it. Your 67 passed and the npm version 0.5.1 --no-git-tag-version staging output are unverified by me this round — CI on this PR is the thing to trust for that.

LGTM.
· feat/version-in-user-agent

Comment thread CLAUDE.md Resolved
Comment thread src/version.ts Resolved
package.json is the source of truth — release.yml verifies the tag against
it and npm publishes from it. src/version.ts is a mirror that exists only
because the shipped code cannot read package.json at runtime.

Previously that mirror had to be updated by hand, so a contributor could
bump package.json and ship a stale VERSION; the test caught it only after
the fact. Now npm's version lifecycle hook runs sync-version and stages the
result, so 'npm version <x> --no-git-tag-version' moves package.json,
package-lock.json, and src/version.ts in one command.

Verified end to end: 'npm version 0.5.1 --no-git-tag-version' regenerated
src/version.ts at 0.5.1 and staged it, then reverting to 0.5.0 regenerated
it again.

CONTRIBUTING gains a Versioning section; CLAUDE.md's Releasing section now
names package.json as authoritative and covers the PR-then-tag flow the
branch ruleset requires.
Comment thread CLAUDE.md Resolved
CLAUDE.md's Conventions bullet still described the bare
'User-Agent: kosli-mcp-server' and said to preserve it — the instruction
that would motivate reverting this PR's change. It now documents the
versioned form and where the version comes from.

Also adds src/version.ts to 'Things not to do' alongside the other
generated files. 'Never edit by hand' previously lived only in the
Releasing section, which is read at release time rather than at edit
time.
Comment thread package.json Resolved
Comment thread scripts/sync-version.mjs Resolved
Comment thread test/version.test.ts Resolved
Comment thread package.json Resolved
Comment thread scripts/sync-version.mjs Resolved
The version hook staged only src/version.ts. npm stages nothing itself
under --no-git-tag-version, so the documented 'git commit -m' would have
committed the new src/version.ts alongside an unbumped package.json —
caught by CI, but a confusing half-state in the flow that exists to remove
a two-file footgun. Verified: staged output is now all three files, where
before it was src/version.ts alone.

The semver check also rejected build metadata, which npm accepts
(npm version 1.0.0+build.1). Since package.json is written before this
hook runs, rejecting a version npm considers valid left the repo bumped
with a stale src/version.ts — the exact state this is meant to prevent.
'+' is a valid HTTP token character, so nothing downstream needed the
restriction. Widened here and in the matching test assertion.
@dangrondahl
dangrondahl enabled auto-merge (squash) August 13, 2026 11:20
@dangrondahl
dangrondahl merged commit ffaded1 into main Aug 13, 2026
4 checks passed
@dangrondahl
dangrondahl deleted the feat/version-in-user-agent branch August 13, 2026 12:12
@dangrondahl dangrondahl mentioned this pull request Oct 23, 2026
5 tasks
dangrondahl added a commit that referenced this pull request Oct 23, 2026
Release prep for **0.6.0**. A draft for now: it gets rebased once #97
(CodeQL) merges, then marked ready.

`npm version minor --no-git-tag-version` moves `package.json`,
`package-lock.json` and the generated `src/version.ts` together.
`manifest.json` gets the version at pack time. Nothing else changes.

## What's in 0.6.0 (since 0.5.0)

### ⚠️ Changes that affect existing setups
- **No configured org (#65).** `KOSLI_ORG` and the Desktop extension's
*Organization* setting are removed. Every org-scoped call names its org
through the execute tools' `org` input, so no request lands in an org
the caller didn't name. An existing config that still sets `KOSLI_ORG`
starts fine and logs that the value is ignored, but calls that relied on
the default are now refused until an org is given.
- **Node ≥ 22 (#38).** It was ≥ 20.

### Fixes
- **Evidence downloads work again (#88, fixes #86).** Since 16 Oct,
every `get_attestation_evidence` call failed: our token was forwarded to
the pre-signed S3 URL. Text files come back as text, and binary files
return a clear error.
- **The `.mcpb` bundle starts on Node 22.0 – 22.6 (#87).** It didn't
before.
- **No known vulnerabilities in the bundled dependencies (#96).** `npm
audit --omit=dev` is clean.

### Features
- **`org` input on the execute tools (#65).**
- **`User-Agent` carries the version (#41):**
`kosli-mcp-server/<version>`.

### Dependencies
- **Runtime:** `@modelcontextprotocol/sdk` 1.29.0 → 1.32.1 (#29, #71,
#79).
- **Dev:** TypeScript 7 (#45), with emitted output byte-identical to
5.9. vitest 5 (#93).
- **Catalog:** regenerated from the OpenAPI spec (#50, #53, #60, #69,
#78).

### Release confidence (CI only)
Typecheck of tests and scripts, a stdio smoke test against `dist/` and
the unzipped bundle (including Node 22.0.0), `mcpb validate`, and
`release.yml` publishing only after every check (#87). There's also a
phased Claude review (#90), Dependabot grouping with a 7-day cooldown,
and CodeQL (#97).

## Checked locally on this branch

- Build, typecheck, 122 tests.
- The smoke test reports `server advertises version 0.6.0`, both from
`dist/` and from the unzipped bundle.
- `kosli-mcp-server-0.6.0.mcpb`: the manifest says 0.6.0 and `mcpb
validate` passes.

## Before tagging (after merge)
- [ ] Rebase onto `main` once #97 merges, then mark ready.
- [ ] Install the 0.6.0 `.mcpb` in Claude Desktop, including an upgrade
over 0.5.0 with an org configured.
- [ ] Run `KOSLI_API_TOKEN=… KOSLI_SMOKE_ORG=<org> npm run smoke` on
`main`.
- [ ] Download one piece of evidence via `get_attestation_evidence`.
- [ ] `git tag -a v0.6.0 -m "v0.6.0" <merge commit> && git push origin
v0.6.0`. `release.yml` does the rest.
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.

Include the version in User-Agent, from a single source of truth

2 participants