@realeng/maestro
Version:
Easy setup and management for local MCP servers
169 lines ⢠7.9 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.syncCommand = syncCommand;
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const os = __importStar(require("os"));
const config_1 = require("../utils/config");
const servers_1 = require("../servers");
const inquirer_1 = __importDefault(require("inquirer"));
// Determine Claude Desktop config path based on platform
function getClaudeConfigPath() {
const platform = process.platform;
if (platform === 'darwin') {
// macOS
return path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
}
else if (platform === 'win32') {
// Windows
return path.join(process.env.APPDATA || '', 'Claude', 'claude_desktop_config.json');
}
else {
// Linux and others
return path.join(os.homedir(), '.config', 'Claude', 'claude_desktop_config.json');
}
}
async function syncCommand() {
console.log(chalk_1.default.blue('\nš Syncing MCP configuration with Claude Desktop...\n'));
const config = (0, config_1.loadConfig)();
const enabledServers = Object.entries(config.servers)
.filter(([_, serverConfig]) => serverConfig.enabled);
if (enabledServers.length === 0) {
console.log(chalk_1.default.yellow('ā ļø No MCP servers configured or enabled.'));
console.log(chalk_1.default.gray('Run "maestro init" to configure servers.'));
return;
}
// Generate MCP configuration
const claudeConfig = {
mcpServers: {}
};
let skippedServers = 0;
for (const [name, serverConfig] of enabledServers) {
const serverDef = (0, servers_1.getServer)(serverConfig.type);
if (!serverDef) {
skippedServers++;
continue;
}
const command = serverDef.command(serverConfig);
// Include env object if server has includeEnvInConfig flag set to true
const includeEnv = serverDef.includeEnvInConfig && serverDef.env;
const env = includeEnv && serverDef.env ? serverDef.env(serverConfig) : undefined;
claudeConfig.mcpServers[name] = {
command: command[0],
args: command.slice(1).length > 0 ? command.slice(1) : undefined,
...(env && { env })
};
}
// Get Claude config path
const claudeConfigPath = getClaudeConfigPath();
const claudeConfigDir = path.dirname(claudeConfigPath);
// Check if Claude Desktop is installed
if (!fs.existsSync(claudeConfigDir)) {
console.log(chalk_1.default.red('ā Claude Desktop configuration directory not found!'));
console.log(chalk_1.default.yellow('\nPlease make sure Claude Desktop is installed:'));
console.log(chalk_1.default.cyan.underline('https://claude.ai/download'));
console.log(chalk_1.default.gray(`\nExpected config directory: ${claudeConfigDir}`));
return;
}
// Check if config file exists and load it
let existingConfig = {};
let hasExistingConfig = false;
if (fs.existsSync(claudeConfigPath)) {
hasExistingConfig = true;
try {
const existingData = fs.readFileSync(claudeConfigPath, 'utf-8');
existingConfig = JSON.parse(existingData);
// Check if there are existing MCP servers
if (existingConfig.mcpServers && Object.keys(existingConfig.mcpServers).length > 0) {
console.log(chalk_1.default.yellow('ā ļø Found existing MCP servers in Claude Desktop configuration:'));
console.log(chalk_1.default.gray(JSON.stringify(existingConfig.mcpServers, null, 2)));
const { confirmOverwrite } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'confirmOverwrite',
message: 'Do you want to replace the existing MCP server configuration?',
default: false
}
]);
if (!confirmOverwrite) {
console.log(chalk_1.default.gray('\nā
Sync cancelled. Existing configuration unchanged.'));
return;
}
}
}
catch (error) {
console.log(chalk_1.default.yellow('ā ļø Could not parse existing Claude Desktop config. It will be overwritten.'));
}
}
// Merge configurations (preserve non-MCP settings)
const finalConfig = {
...existingConfig,
mcpServers: claudeConfig.mcpServers
};
// Create backup if existing config exists
if (hasExistingConfig) {
const backupPath = claudeConfigPath + '.backup';
fs.copyFileSync(claudeConfigPath, backupPath);
console.log(chalk_1.default.gray(`š Backup created: ${backupPath}`));
}
// Write the configuration
try {
fs.writeFileSync(claudeConfigPath, JSON.stringify(finalConfig, null, 2));
console.log(chalk_1.default.green('\nā
Successfully synced MCP configuration to Claude Desktop!'));
console.log(chalk_1.default.gray(`š Configuration written to: ${claudeConfigPath}`));
if (skippedServers > 0) {
console.log(chalk_1.default.yellow(`\nā ļø Skipped ${skippedServers} inactive server(s)`));
}
console.log(chalk_1.default.cyan('\nš Configuration synced!'));
console.log(chalk_1.default.white('š Synced servers:'));
Object.keys(claudeConfig.mcpServers).forEach(server => {
console.log(chalk_1.default.white(` ⢠${server}`));
});
console.log(chalk_1.default.yellow('\nā ļø Important: Restart Claude Desktop for changes to take effect!'));
console.log(chalk_1.default.blue('\nš” Using Claude Code?'));
console.log(chalk_1.default.white(' Run: ') + chalk_1.default.green('claude mcp add-from-claude-desktop'));
console.log(chalk_1.default.gray(' This will sync your MCP servers from Claude Desktop to Claude Code'));
}
catch (error) {
console.error(chalk_1.default.red('\nā Error writing configuration:'), error);
console.log(chalk_1.default.gray('\nYou may need to run this command with appropriate permissions.'));
}
}
//# sourceMappingURL=sync.js.map