Skip to content

Commit 31f7978

Browse files
committed
fix(cli-mcp): resolve package.json path correctly in both compiled and Vitest contexts
1 parent 34300c6 commit 31f7978

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

tools/cli/src/mcp.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { McpServer, Tool, Toolkit } from '@effect/ai';
22
import { NodeContext, NodeRuntime, NodeSink, NodeStream } from '@effect/platform-node';
33
import { Cause, Effect, Layer, Logger, Option, Schema } from 'effect';
4-
import { readFileSync } from 'node:fs';
4+
import { existsSync, readFileSync } from 'node:fs';
55
import { dirname, resolve } from 'node:path';
66
import { fileURLToPath } from 'node:url';
77

@@ -15,10 +15,12 @@ import { GithubReleaseLayer, Release } from './services/release.js';
1515

1616
import type { FileSystem, Path } from '@effect/platform';
1717

18-
// dist/src/mcp.js → ../../package.json resolves to the package root
19-
const { version } = JSON.parse(
20-
readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json'), 'utf8'),
21-
) as { version: string };
18+
// Resolve package.json from either dist/src/ (compiled) or src/ (Vitest).
19+
const __dir = dirname(fileURLToPath(import.meta.url));
20+
const pkgPath = existsSync(resolve(__dir, '../../package.json'))
21+
? resolve(__dir, '../../package.json')
22+
: resolve(__dir, '../package.json');
23+
const { version } = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version: string };
2224

2325
// ── Shared error formatter ────────────────────────────────────────────────────
2426

0 commit comments

Comments
 (0)