Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/argent-mcp/src/installed-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as fs from "node:fs";
import * as path from "node:path";

/**
* Version reported in the MCP `initialize` handshake (`serverInfo.version`).
*
* Resolved from the package.json one directory above the executing file —
* the same pattern as `getInstalledVersion()` in packages/argent/src/cli.ts:
* in the published package the bundled `dist/mcp-server.mjs` sits next to
* `dist/cli.js`, so two-up is @swmansion/argent's shipped package.json; in
* the dev workspace the compiled file resolves @argent/mcp's own package.json.
* Both are version-bumped in lockstep, so either source is correct — unlike
* the hardcoded literal this replaces, which had drifted several releases
* behind the actual install.
*/
export function getInstalledVersion(): string {
try {
const pkgPath = path.resolve(import.meta.dirname, "..", "package.json");
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")) as { version?: string };
return pkg.version ?? "unknown";
} catch {
return "unknown";
}
}
3 changes: 2 additions & 1 deletion packages/argent-mcp/src/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getAutoScreenshotDelayMs,
} from "./auto-screenshot.js";
import { toMcpTool } from "./tool-mapping.js";
import { getInstalledVersion } from "./installed-version.js";

const MAX_RETRIES = 4;
const EXP_BACKOFF_BASE = 250;
Expand Down Expand Up @@ -182,7 +183,7 @@ export async function startMcpServer(options: StartMcpServerOptions): Promise<vo
}

const server = new Server(
{ name: "argent", version: "0.5.3" },
{ name: "argent", version: getInstalledVersion() },
{
capabilities: { tools: {} },
instructions:
Expand Down
17 changes: 17 additions & 0 deletions packages/argent-mcp/test/installed-version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, it, expect } from "vitest";
import * as fs from "node:fs";
import * as path from "node:path";
import { getInstalledVersion } from "../src/installed-version.js";

describe("getInstalledVersion", () => {
it("matches the workspace package.json version (no more hardcoded drift)", () => {
const pkg = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "..", "package.json"), "utf8")
) as { version: string };
expect(getInstalledVersion()).toBe(pkg.version);
});

it("never returns the stale literal this replaced", () => {
expect(getInstalledVersion()).not.toBe("0.5.3");
});
});