UNPKG

task-engine-ai-core

Version:

Revolutionary AI-driven task management system with complete transformation trilogy: Frontend v0.1.0, Backend v0.2.0, CLI v0.3.0 - Enterprise-grade performance with 95% improvements

315 lines (263 loc) • 9.68 kB
#!/usr/bin/env node /** * Setup script for task-engine-ai-core MCP configuration * * This script helps users configure MCP to use the task-engine-ai-core package * with proper environment variables and IDE-specific configurations. * * @version 0.3.1 * @author Task Engine AI Team */ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs'; import { dirname, resolve } from 'path'; class MCPSetup { constructor() { this.projectRoot = process.cwd(); this.packageVersion = '0.3.1'; this.configs = { cursor: '.cursor/mcp.json', vscode: '.vscode/mcp.json', claude: 'claude_desktop_config.json' }; } /** * Main setup function */ async setup() { console.log('šŸš€ Task Engine AI Core MCP Setup v0.3.1'); console.log('==========================================\n'); try { // Detect IDE const ide = this.detectIDE(); console.log(`šŸ“± Detected IDE: ${ide}`); // Get project root const projectRoot = this.getProjectRoot(); console.log(`šŸ“ Project root: ${projectRoot}`); // Create MCP configuration await this.createMCPConfig(ide, projectRoot); // Install package if needed await this.checkAndInstallPackage(); // Validate configuration await this.validateConfiguration(); console.log('\nāœ… MCP setup completed successfully!'); console.log('\nšŸ“š Next steps:'); console.log('1. Restart your IDE to load the new MCP configuration'); console.log('2. Test the connection by asking Claude to list tasks'); console.log('3. Check the configuration documentation in config/README.md'); } catch (error) { console.error('\nāŒ Setup failed:', error.message); console.error('\nšŸ”§ Troubleshooting:'); console.error('1. Ensure you have Node.js 18+ installed'); console.error('2. Check that you have write permissions in the project directory'); console.error('3. Verify your IDE supports MCP configuration'); process.exit(1); } } /** * Detect the current IDE */ detectIDE() { if (existsSync('.cursor')) return 'cursor'; if (existsSync('.vscode')) return 'vscode'; if (process.env.CURSOR_USER_DATA) return 'cursor'; if (process.env.VSCODE_PID) return 'vscode'; // Default to cursor if no specific IDE detected return 'cursor'; } /** * Get the project root directory */ getProjectRoot() { // Use environment variable if set if (process.env.TASK_MASTER_PROJECT_ROOT) { return process.env.TASK_MASTER_PROJECT_ROOT; } // Use current working directory return resolve(this.projectRoot); } /** * Create MCP configuration for the detected IDE */ async createMCPConfig(ide, projectRoot) { console.log(`\nāš™ļø Creating MCP configuration for ${ide}...`); const configPath = this.configs[ide]; const configDir = dirname(configPath); // Create directory if it doesn't exist if (!existsSync(configDir)) { mkdirSync(configDir, { recursive: true }); console.log(`šŸ“ Created directory: ${configDir}`); } // Generate configuration const config = this.generateMCPConfig(ide, projectRoot); // Write configuration file writeFileSync(configPath, JSON.stringify(config, null, 2)); console.log(`āœ… Created MCP configuration: ${configPath}`); // Create environment file template this.createEnvironmentTemplate(); } /** * Generate MCP configuration based on IDE */ generateMCPConfig(ide, projectRoot) { const baseEnv = { TASK_MASTER_PROJECT_ROOT: projectRoot, TASK_ENGINE_VERSION: this.packageVersion, TASK_ENGINE_ENVIRONMENT: 'development', TASK_ENGINE_DEBUG: 'true', TASK_ENGINE_LOG_LEVEL: 'info' }; // Use relative path with cwd for better cross-platform compatibility const serverPath = 'mcp-server/server.js'; if (ide === 'cursor') { return { mcpServers: { 'task-engine-ai-core': { command: 'node', args: [serverPath], cwd: projectRoot, env: baseEnv } } }; } else if (ide === 'vscode') { return { servers: { 'task-engine-ai-core': { command: 'node', args: [serverPath], cwd: projectRoot, env: { ...baseEnv, MODEL: 'claude-3-5-sonnet-20241022', MAX_TOKENS: '64000', TEMPERATURE: '0.2' } } } }; } else { // Claude Desktop configuration return { mcpServers: { 'task-engine-ai-core': { command: 'node', args: [serverPath], cwd: projectRoot, env: baseEnv } } }; } } /** * Create environment template file */ createEnvironmentTemplate() { const envTemplate = `# Task Engine AI Core Environment Variables # Copy this file to .env and configure your API keys # Core Configuration TASK_MASTER_PROJECT_ROOT=${this.getProjectRoot()} TASK_ENGINE_VERSION=${this.packageVersion} TASK_ENGINE_ENVIRONMENT=development TASK_ENGINE_DEBUG=true TASK_ENGINE_LOG_LEVEL=info # Backend Configuration TASK_ENGINE_PORT=8000 TASK_ENGINE_HOST=localhost TASK_ENGINE_DB_TYPE=sqlite # AI Provider API Keys (optional) # ANTHROPIC_API_KEY=your-anthropic-api-key-here # OPENAI_API_KEY=your-openai-api-key-here # PERPLEXITY_API_KEY=your-perplexity-api-key-here # MCP Configuration MCP_PORT=9000 MCP_HOST=localhost `; const envPath = '.env.example'; writeFileSync(envPath, envTemplate); console.log(`šŸ“ Created environment template: ${envPath}`); } /** * Check if package is installed and install if needed */ async checkAndInstallPackage() { console.log('\nšŸ“¦ Checking package installation...'); try { // Check if package is available globally const { execSync } = await import('child_process'); execSync('npm list -g task-engine-ai-core', { stdio: 'ignore' }); console.log('āœ… Package is already installed globally'); } catch (error) { console.log('šŸ“„ Package not found globally, will use npx for on-demand installation'); console.log('šŸ’” To install globally: npm install -g task-engine-ai-core'); } } /** * Validate the MCP configuration */ async validateConfiguration() { console.log('\nšŸ” Validating configuration...'); // Check if configuration files exist const ide = this.detectIDE(); const configPath = this.configs[ide]; if (!existsSync(configPath)) { throw new Error(`Configuration file not found: ${configPath}`); } // Validate JSON syntax try { const configContent = readFileSync(configPath, 'utf8'); JSON.parse(configContent); console.log('āœ… Configuration file syntax is valid'); } catch (error) { throw new Error(`Invalid JSON in configuration file: ${error.message}`); } // Check project root exists const projectRoot = this.getProjectRoot(); if (!existsSync(projectRoot)) { throw new Error(`Project root directory not found: ${projectRoot}`); } console.log('āœ… Configuration validation passed'); } /** * Display help information */ static showHelp() { console.log(` Task Engine AI Core MCP Setup v0.3.1 Usage: node scripts/setup-mcp-task-engine-core.js [options] Options: --help, -h Show this help message --version, -v Show version information Environment Variables: TASK_MASTER_PROJECT_ROOT Override project root directory TASK_ENGINE_ENVIRONMENT Set environment (development, production, etc.) Examples: # Basic setup node scripts/setup-mcp-task-engine-core.js # Setup with custom project root TASK_MASTER_PROJECT_ROOT=/path/to/project node scripts/setup-mcp-task-engine-core.js # Setup for production TASK_ENGINE_ENVIRONMENT=production node scripts/setup-mcp-task-engine-core.js For more information, see: config/README.md `); } } // Main execution if (import.meta.url === `file://${process.argv[1]}`) { const args = process.argv.slice(2); if (args.includes('--help') || args.includes('-h')) { MCPSetup.showHelp(); process.exit(0); } if (args.includes('--version') || args.includes('-v')) { console.log('Task Engine AI Core MCP Setup v0.3.1'); process.exit(0); } const setup = new MCPSetup(); setup.setup().catch(error => { console.error('Setup failed:', error); process.exit(1); }); } export default MCPSetup;