- 拓展/: MCP配置向导、PowerShell工具、mcp-auto-loader 纳入版本管理 - guide.html: badges 从模糊 "90+" 改为精确 "92 Skills | 18 Agents | 34 Hooks"
120 lines
4.3 KiB
JavaScript
120 lines
4.3 KiB
JavaScript
#!/usr/bin/env node
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const readline = require('readline');
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
function question(prompt) {
|
|
return new Promise(resolve => rl.question(prompt, resolve));
|
|
}
|
|
|
|
async function main() {
|
|
console.log('╔════════════════════════════════════════════════════════╗');
|
|
console.log('║ MCP Configuration Installer ║');
|
|
console.log('╚════════════════════════════════════════════════════════╝\n');
|
|
|
|
// 检查生成的配置文件
|
|
const generatedConfig = path.join(__dirname, 'generated-claude.json');
|
|
if (!fs.existsSync(generatedConfig)) {
|
|
console.log('✗ No configuration found. Run "node wizard.js" first.');
|
|
rl.close();
|
|
return;
|
|
}
|
|
|
|
const config = JSON.parse(fs.readFileSync(generatedConfig, 'utf-8'));
|
|
console.log(`Found configuration with ${Object.keys(config.mcpServers).length} MCP services\n`);
|
|
|
|
// 目标配置文件路径
|
|
const targetConfig = path.join(os.homedir(), '.claude.json');
|
|
let existingConfig = {};
|
|
|
|
// 检查现有配置
|
|
if (fs.existsSync(targetConfig)) {
|
|
console.log('⚠ Existing .claude.json found\n');
|
|
console.log('Installation options:');
|
|
console.log(' 1. Merge - Keep existing settings, add/update MCP servers');
|
|
console.log(' 2. Replace - Overwrite with new configuration');
|
|
console.log(' 3. Backup & Replace - Backup existing, then replace');
|
|
console.log(' 4. Cancel\n');
|
|
|
|
const choice = await question('Select option (1-4): ');
|
|
|
|
switch (choice) {
|
|
case '1':
|
|
existingConfig = JSON.parse(fs.readFileSync(targetConfig, 'utf-8'));
|
|
existingConfig.mcpServers = {
|
|
...(existingConfig.mcpServers || {}),
|
|
...config.mcpServers
|
|
};
|
|
break;
|
|
case '2':
|
|
existingConfig = config;
|
|
break;
|
|
case '3':
|
|
const backupPath = targetConfig + `.backup-${Date.now()}`;
|
|
fs.copyFileSync(targetConfig, backupPath);
|
|
console.log(`\n✓ Backup created: ${backupPath}`);
|
|
existingConfig = config;
|
|
break;
|
|
case '4':
|
|
console.log('\nInstallation cancelled');
|
|
rl.close();
|
|
return;
|
|
default:
|
|
console.log('\nInvalid option');
|
|
rl.close();
|
|
return;
|
|
}
|
|
} else {
|
|
existingConfig = config;
|
|
}
|
|
|
|
// 写入配置
|
|
try {
|
|
fs.writeFileSync(targetConfig, JSON.stringify(existingConfig, null, 2));
|
|
console.log(`\n✓ Configuration installed to: ${targetConfig}`);
|
|
} catch (e) {
|
|
console.log(`\n✗ Failed to write configuration: ${e.message}`);
|
|
console.log('\nManual installation:');
|
|
console.log(` 1. Copy ${generatedConfig}`);
|
|
console.log(` 2. To ${targetConfig}`);
|
|
rl.close();
|
|
return;
|
|
}
|
|
|
|
// 应用环境变量
|
|
const envFile = path.join(__dirname, 'generated-env.json');
|
|
if (fs.existsSync(envFile)) {
|
|
console.log('\n=== Environment Variables ===\n');
|
|
console.log('Environment variables need to be set manually:');
|
|
|
|
if (os.platform() === 'win32') {
|
|
console.log('\nWindows: Run the PowerShell script:');
|
|
console.log(' .\\apply-env.ps1');
|
|
} else {
|
|
console.log('\nUnix/Mac: Source the shell script:');
|
|
console.log(' source ./apply-env.sh');
|
|
}
|
|
|
|
console.log('\nOr set them manually from: generated-env.json');
|
|
}
|
|
|
|
console.log('\n╔════════════════════════════════════════════════════════╗');
|
|
console.log('║ Installation Complete ║');
|
|
console.log('╚════════════════════════════════════════════════════════╝');
|
|
console.log('\n✓ MCP configuration installed successfully');
|
|
console.log('\n📋 Next steps:');
|
|
console.log(' 1. Set environment variables (if needed)');
|
|
console.log(' 2. Restart Claude Code');
|
|
console.log(' 3. Verify MCP services are loaded\n');
|
|
|
|
rl.close();
|
|
}
|
|
|
|
main().catch(console.error);
|