Skip to content

Commit 64fd8cd

Browse files
committed
fix(sequentialthinking): read server version from package.json
Replace the hardcoded 0.2.0 so initialize serverInfo tracks the package version (0.6.2 in-tree; CalVer after release), matching the approach used for memory server version sync. Skip the dist-layout assertion when dist/ is absent so CI's test-before-build job (and local runs without prepare) still pass.
1 parent d31124c commit 64fd8cd

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { createRequire } from 'node:module';
3+
import { existsSync } from 'node:fs';
4+
import path from 'node:path';
5+
import { fileURLToPath, pathToFileURL } from 'node:url';
6+
import { resolvePackageVersion, SERVER_VERSION } from '../version.js';
7+
8+
const packageJson = createRequire(import.meta.url)('../package.json') as { version: string };
9+
const distVersionPath = path.join(
10+
path.dirname(fileURLToPath(import.meta.url)),
11+
'..',
12+
'dist',
13+
'version.js',
14+
);
15+
16+
describe('server version', () => {
17+
it('uses package.json version instead of a hardcoded string', () => {
18+
expect(SERVER_VERSION).toBe(packageJson.version);
19+
expect(resolvePackageVersion()).toBe(packageJson.version);
20+
expect(SERVER_VERSION).not.toBe('0.2.0');
21+
});
22+
23+
// CI runs `npm test` before the dedicated build job. `npm ci` usually
24+
// materializes dist/ via prepare, but that is not guaranteed (e.g. local
25+
// `rm -rf dist && npm test`, or install with --ignore-scripts).
26+
it.skipIf(!existsSync(distVersionPath))(
27+
'resolves package.json from the dist layout after build',
28+
async () => {
29+
const distModule = (await import(pathToFileURL(distVersionPath).href)) as {
30+
SERVER_VERSION: string;
31+
};
32+
expect(distModule.SERVER_VERSION).toBe(packageJson.version);
33+
},
34+
);
35+
});

‎src/sequentialthinking/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
44
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
55
import { z } from "zod";
66
import { SequentialThinkingServer } from './lib.js';
7+
import { SERVER_VERSION } from './version.js';
78

89
/** Safe boolean coercion that correctly handles string "false" */
910
const coercedBoolean = z.preprocess((val) => {
@@ -17,7 +18,7 @@ const coercedBoolean = z.preprocess((val) => {
1718

1819
const server = new McpServer({
1920
name: "sequential-thinking-server",
20-
version: "0.2.0",
21+
version: SERVER_VERSION,
2122
});
2223

2324
const thinkingServer = new SequentialThinkingServer();

‎src/sequentialthinking/version.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { createRequire } from 'node:module';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
/**
6+
* Resolve this package's version from package.json.
7+
*
8+
* Works both from source (`src/sequentialthinking/`) and from the published
9+
* layout (`dist/`), where package.json lives one directory up.
10+
*/
11+
export function resolvePackageVersion(): string {
12+
const require = createRequire(import.meta.url);
13+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
14+
const candidates = [
15+
path.join(moduleDir, 'package.json'),
16+
path.join(moduleDir, '..', 'package.json'),
17+
];
18+
19+
for (const candidate of candidates) {
20+
try {
21+
const pkg = require(candidate) as { version?: string };
22+
if (pkg.version) {
23+
return pkg.version;
24+
}
25+
} catch {
26+
// Try the next candidate when running from dist/ or source.
27+
}
28+
}
29+
30+
throw new Error('Could not locate package.json for server version');
31+
}
32+
33+
export const SERVER_VERSION = resolvePackageVersion();

0 commit comments

Comments
 (0)