22import { Command } from 'commander' ;
33import { buildWidgets } from './build' ;
44import { 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' ;
67import path from 'node:path' ;
78import open from 'open' ;
8-
99const 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+
1117program
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
1723async 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 }
0 commit comments