@@ -49,10 +49,38 @@ async function getNpmVersion() {
4949
5050const getVersion = async ( ) => {
5151 try {
52- const packageJson = await import ( './package.json' , { assert : { type : 'json' } } ) ;
53- return packageJson . default . version ;
54- } catch {
55- return 'unknown'
52+ if ( process . env . npm_package_version ) {
53+ return process . env . npm_package_version ;
54+ } else {
55+ const packageJsonPath = join ( __dirname , 'package.json' ) ;
56+ if ( existsSync ( packageJsonPath ) ) {
57+ const packageJsonContent = readFileSync ( packageJsonPath , 'utf8' ) ;
58+ const packageJson = JSON . parse ( packageJsonContent ) ;
59+ if ( packageJson . version ) {
60+ return packageJson . version ;
61+ }
62+ }
63+ }
64+
65+ throw new Error ( 'Version not found in environment variable or package.json' ) ;
66+ } catch ( error ) {
67+ try {
68+ const packageJson = await import ( './package.json' , { with : { type : 'json' } } ) ;
69+ if ( packageJson . default ?. version ) {
70+ return packageJson . default . version ;
71+ }
72+ } catch ( importError ) {
73+ // Try older syntax as fallback
74+ try {
75+ const packageJson = await import ( './package.json' , { assert : { type : 'json' } } ) ;
76+ if ( packageJson . default ?. version ) {
77+ return packageJson . default . version ;
78+ }
79+ } catch ( legacyImportError ) {
80+ // Log the error for debugging
81+ logToFile ( `Failed to import package.json: ${ legacyImportError . message } ` , true ) ;
82+ }
83+ }
5684 }
5785} ;
5886
@@ -676,8 +704,8 @@ export default async function setup() {
676704 await trackEvent ( 'npx_setup_update_config_error' , { error : updateError . message } ) ;
677705 throw new Error ( `Failed to update config: ${ updateError . message } ` ) ;
678706 }
679-
680- logToFile ( ' Successfully added MCP server to Claude configuration!' ) ;
707+ const appVersion = await getVersion ( )
708+ logToFile ( ` Successfully added Desktop Commander MCP v ${ appVersion } server to Claude configuration!` ) ;
681709 logToFile ( `Configuration location: ${ claudeConfigPath } ` ) ;
682710
683711 if ( debugMode ) {
0 commit comments