Skip to content

Commit 93d07da

Browse files
committed
fix: dynamically set CLI version from package.json
- Update CLI to read version from package.json instead of hardcoding it. - Replace fs.promises.access with fs.access for checking file existence.
1 parent 9ff6103 commit 93d07da

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

packages/cli/src/index.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
import { Command } from 'commander';
33
import { buildWidgets } from './build';
44
import { spawn } from 'node:child_process';
5-
import { promises as fs } from 'node:fs';
5+
import { readFileSync } from 'node:fs';
6+
import { access } from 'node:fs/promises';
67
import path from 'node:path';
78
import open from 'open';
8-
99
const program = new Command();
1010

11+
12+
const packageContent = readFileSync(path.join(__dirname, '../../package.json'), 'utf-8')
13+
const packageJson = JSON.parse(packageContent)
14+
const packageVersion = packageJson.version || 'unknown'
15+
16+
1117
program
1218
.name('mcp-use')
1319
.description('MCP CLI tool')
14-
.version('2.0.1');
20+
.version(packageVersion);
1521

1622
// Helper to check if port is available
1723
async function isPortAvailable(port: number): Promise<boolean> {
1824
try {
19-
const response = await fetch(`http://localhost:${port}`);
25+
await fetch(`http://localhost:${port}`);
2026
return false; // Port is in use
2127
} catch {
2228
return true; // Port is available
@@ -77,7 +83,7 @@ program
7783
try {
7884
const projectPath = path.resolve(options.path);
7985

80-
console.log('\x1b[36m\x1b[1mmcp-use\x1b[0m \x1b[90mVersion: 2.0.1\x1b[0m\n');
86+
console.log(`\x1b[36m\x1b[1mmcp-use\x1b[0m \x1b[90mVersion: ${packageJson.version}\x1b[0m\n`);
8187

8288
// Run tsc first
8389
console.log('Building TypeScript...');
@@ -103,7 +109,7 @@ program
103109
const projectPath = path.resolve(options.path);
104110
let port = parseInt(options.port, 10);
105111

106-
console.log('\x1b[36m\x1b[1mmcp-use\x1b[0m \x1b[90mVersion: 2.0.1\x1b[0m\n');
112+
console.log(`\x1b[36m\x1b[1mmcp-use\x1b[0m \x1b[90mVersion: ${packageJson.version}\x1b[0m\n`);
107113

108114
// Check if port is available, find alternative if needed
109115
if (!(await isPortAvailable(port))) {
@@ -116,7 +122,7 @@ program
116122
// Find the main source file
117123
let serverFile = 'src/server.ts';
118124
try {
119-
await fs.access(path.join(projectPath, serverFile));
125+
await access(path.join(projectPath, serverFile));
120126
} catch {
121127
serverFile = 'src/index.ts';
122128
}
@@ -215,12 +221,12 @@ program
215221
const projectPath = path.resolve(options.path);
216222
const port = parseInt(options.port, 10);
217223

218-
console.log('\x1b[36m\x1b[1mmcp-use\x1b[0m \x1b[90mVersion: 2.0.1\x1b[0m\n');
224+
console.log(`\x1b[36m\x1b[1mmcp-use\x1b[0m \x1b[90mVersion: ${packageJson.version}\x1b[0m\n`);
219225

220226
// Find the built server file
221227
let serverFile = 'dist/server.js';
222228
try {
223-
await fs.access(path.join(projectPath, serverFile));
229+
await access(path.join(projectPath, serverFile));
224230
} catch {
225231
serverFile = 'dist/index.js';
226232
}

packages/inspector/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'node:path'
21
import { readFileSync } from 'node:fs'
2+
import path from 'node:path'
33
import tailwindcss from '@tailwindcss/vite'
44
import react from '@vitejs/plugin-react'
55
import { defineConfig } from 'vite'
@@ -39,7 +39,7 @@ export default defineConfig({
3939
// Define process.env for browser compatibility
4040
'process.env': {},
4141
// Inject version from package.json at build time
42-
__INSPECTOR_VERSION__: JSON.stringify(packageJson.version),
42+
'__INSPECTOR_VERSION__': JSON.stringify(packageJson.version),
4343
},
4444
optimizeDeps: {
4545
include: ['mcp-use/react'],

0 commit comments

Comments
 (0)