UNPKG

claude-code-subagents-orchestrator

Version:

Claude Code Sub-agents Orchestrator - A powerful MCP server for orchestrating multiple AI sub-agents for complex task execution in Claude Code

105 lines (84 loc) 3.28 kB
#!/usr/bin/env node /** * Post-install script for Claude Code Subagents Orchestrator * Handles MCP server registration and initial setup */ import fs from 'fs-extra'; import path from 'path'; import os from 'os'; import chalk from 'chalk'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Platform-specific paths for Claude Code configuration const CLAUDE_CONFIG_PATHS = { win32: path.join(os.homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'), darwin: path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'), linux: path.join(os.homedir(), '.config', 'claude', 'claude_desktop_config.json') }; async function postInstall() { console.log(chalk.blue('🔧 Setting up Claude Code Subagents Orchestrator...')); try { // Skip setup in CI environments if (process.env.CI || process.env.NODE_ENV === 'test') { console.log(chalk.yellow('⏭️ Skipping setup in CI environment')); return; } const platform = os.platform(); const configPath = CLAUDE_CONFIG_PATHS[platform]; if (!configPath) { console.log(chalk.yellow(`⚠️ Unsupported platform: ${platform}`)); return; } // Check if Claude Code is installed if (!await fs.pathExists(path.dirname(configPath))) { console.log(chalk.yellow('⚠️ Claude Code not found. Please install Claude Code first.')); console.log(chalk.gray(' Visit: https://claude.ai/code')); return; } // Register MCP server await registerMCPServer(configPath); console.log(chalk.green('✅ Setup completed successfully!')); console.log(chalk.blue('📖 Run "claude-orchestrator --help" to get started')); } catch (error) { console.error(chalk.red('❌ Setup failed:'), error.message); console.log(chalk.yellow('💡 You can run the setup manually using: claude-orchestrator init')); } } async function registerMCPServer(configPath) { const packageJsonPath = path.resolve(__dirname, '..', 'package.json'); const packageJson = await fs.readJson(packageJsonPath); // Read existing configuration let config = {}; if (await fs.pathExists(configPath)) { config = await fs.readJson(configPath); } // Initialize mcpServers if it doesn't exist if (!config.mcpServers) { config.mcpServers = {}; } // Add our server configuration const serverName = 'claude-code-subagents-orchestrator'; const serverConfig = { type: 'stdio', command: 'node', args: [path.resolve(__dirname, '..', 'dist', 'server.js')], env: { NODE_ENV: 'production' } }; // Check if already registered if (config.mcpServers[serverName]) { console.log(chalk.yellow(`⚠️ MCP server "${serverName}" already registered`)); return; } config.mcpServers[serverName] = serverConfig; // Write updated configuration await fs.ensureDir(path.dirname(configPath)); await fs.writeJson(configPath, config, { spaces: 2 }); console.log(chalk.green(`✅ Registered MCP server: ${serverName}`)); } // Only run if called directly if (import.meta.url === `file://${process.argv[1]}`) { postInstall(); }