From e89095f89950af70f750edfc5b83af8c2658bbb4 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Wed, 5 Nov 2025 14:47:27 -0800 Subject: [PATCH] Remove hard-coded azure-mcp references from npm javascript --- eng/npm/wrapper/index.js | 50 ++++++++++--------- .../wrapper/scripts/post-install-script.js | 20 +++----- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/eng/npm/wrapper/index.js b/eng/npm/wrapper/index.js index e43e763cb..3c60439a1 100644 --- a/eng/npm/wrapper/index.js +++ b/eng/npm/wrapper/index.js @@ -1,11 +1,12 @@ #!/usr/bin/env node const os = require('os') +const packageJson = require('./package.json') // Check if DEBUG environment variable is set const isDebugMode = process.env.DEBUG && ( process.env.DEBUG.toLowerCase() === 'true' || - process.env.DEBUG.includes('azure-mcp') || + process.env.DEBUG.includes('mcp') || process.env.DEBUG === '*' ) @@ -25,7 +26,9 @@ process.argv.forEach((val, index) => { const platform = os.platform() const arch = os.arch() -const platformPackageName = `@azure/mcp-${platform}-${arch}` +const packageName = packageJson.name +const packageVersion = packageJson.version +const platformPackageName = `${packageName}-${platform}-${arch}` // Try to load the platform package let platformPackage @@ -34,58 +37,59 @@ try { platformPackage = require(platformPackageName) } catch (err) { debugLog(`Failed to require ${platformPackageName}, attempting auto-install: ${err.message}`) - + // Try to automatically install the missing platform package try { const { execSync } = require('child_process') - + console.error(`Installing missing platform package: ${platformPackageName}`) - + // Try to install the platform package try { - execSync(`npm install ${platformPackageName}@latest`, { + execSync(`npm install ${platformPackageName}@${packageVersion}`, { stdio: ['inherit', 'inherit', 'pipe'], // Only pipe stderr to capture errors timeout: 60000 // 60 second timeout }) } catch (npmErr) { // If npm install fails, try with --no-save and different install strategies debugLog(`npm install failed, trying alternative installation methods: ${npmErr.message}`) - + // Try with --no-save and --prefer-online - execSync(`npm install ${platformPackageName}@latest --no-save --prefer-online`, { + execSync(`npm install ${platformPackageName}@${packageVersion} --no-save --prefer-online`, { stdio: ['inherit', 'inherit', 'pipe'], timeout: 60000 }) } - + // Clear module cache and try to require again after installation Object.keys(require.cache).forEach(key => { if (key.includes(platformPackageName)) { delete require.cache[key] } }) - + platformPackage = require(platformPackageName) - + console.error(`āœ… Successfully installed and loaded ${platformPackageName}`) - + } catch (installErr) { debugLog(`Auto-install failed: ${installErr.message}`) - + console.error(`\nāŒ Failed to load platform specific package '${platformPackageName}'`) console.error(`\nšŸ” Troubleshooting steps:`) - console.error(`\n1. Clear npm cache and reinstall:`) + console.error(`\n1. Clear npm cache:`) console.error(` npm cache clean --force`) - console.error(` npm uninstall -g @azure/mcp`) - console.error(` npm install -g @azure/mcp@latest`) - console.error(`\n2. If using npx, clear the cache:`) - console.error(` npx clear-npx-cache`) - console.error(` npx -y @azure/mcp@latest server start`) - console.error(`\n3. Manually install the platform package:`) + console.error(`\n2. If installing as a global tool, uninstall and reinstall:`) + console.error(` npm uninstall -g ${packageName}`) + console.error(` npm install -g ${packageName}`) + console.error(`\n3. If using npx, clear the npx cache and try again:`) + console.error(` npx -y clear-npx-cache`) + console.error(` npx -y ${packageName}@latest --version`) + console.error(`\n4. Manually install the platform package to check compatibility:`) console.error(` npm install ${platformPackageName}@latest`) - console.error(`\n4. Check your internet connection and try again`) - console.error(`\n5. If the issue persists, please report it at:`) - console.error(` https://github.com/Azure/azure-mcp/issues`) + console.error(`\n5. Check your internet connection and try again`) + console.error(`\n6. If the issue persists, please report it at:`) + console.error(` https://github.com/microsoft/mcp/issues`) console.error(`\nOriginal error: ${err.message}`) console.error(`Install error: ${installErr.message}`) process.exit(1) diff --git a/eng/npm/wrapper/scripts/post-install-script.js b/eng/npm/wrapper/scripts/post-install-script.js index dc4d82208..d8c1ecf69 100644 --- a/eng/npm/wrapper/scripts/post-install-script.js +++ b/eng/npm/wrapper/scripts/post-install-script.js @@ -1,23 +1,19 @@ -const fs = require('fs') -const path = require('path') const os = require('os'); const platform = os.platform(); const arch = os.arch(); -const pkgJsonPath = path.join(__dirname, '..', 'package.json'); -let baseName = '@azure/mcp'; -try { - const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')); - if (pkg.name) { - baseName = pkg.name; - } -} catch (e) { - // fallback to default +let baseName = ''; +try{ + const packageJson = require('../package.json'); + baseName = packageJson.name; +} +catch (err) { + console.error('Unable to verify platform package installation. Error reading package.json.'); + process.exit(1); } const requiredPackage = `${baseName}-${platform}-${arch}`; - try { require.resolve(requiredPackage); } catch (err) {