UNPKG

stellar-cyber-mcp-agents

Version:

Model Context Protocol (MCP) server for Stellar Cyber security operations with specialized multi-agent analysis capabilities

141 lines โ€ข 6.29 kB
#!/usr/bin/env node import { MultiAgentOrchestrator, createDefaultConfig } from './orchestrator.js'; import dotenv from 'dotenv'; // Load environment variables dotenv.config(); async function startMultiAgentSystem() { try { console.log('๐Ÿš€ Starting Stellar Cyber Multi-Agent System...'); // Create configuration const config = createDefaultConfig(); // Override with environment variables if available if (process.env['STELLAR_API_URL']) { config.stellar.apiUrl = process.env['STELLAR_API_URL']; } if (process.env['STELLAR_API_TOKEN']) { config.stellar.apiToken = process.env['STELLAR_API_TOKEN']; } // Create and start orchestrator const orchestrator = new MultiAgentOrchestrator(config); // Set up event handlers orchestrator.on('started', () => { console.log('โœ… Multi-Agent System started successfully'); console.log('๐Ÿ“Š Use orchestrator.getStatus() to check system status'); console.log('๐Ÿ” Use orchestrator.investigateCase(caseId) to investigate cases'); console.log('๐Ÿ”— Use orchestrator.correlateCase(caseId) to find related cases'); console.log('๐ŸŒ Use orchestrator.analyzeNetwork(caseId, timeRange) to analyze network activity'); }); orchestrator.on('stopped', () => { console.log('๐Ÿ›‘ Multi-Agent System stopped'); }); orchestrator.on('agent_event', (event) => { console.log('๐ŸŽฏ Agent Event:', event.type, 'from', event.sourceAgentId.type); }); orchestrator.on('agent_critical', (status) => { console.error('โš ๏ธ Agent in critical state:', status.id.type); }); orchestrator.on('metrics_collected', (metrics) => { console.log('๐Ÿ“ˆ Metrics:', { totalAgents: metrics.registry.totalAgents, activeAgents: metrics.registry.activeAgents, totalRequests: metrics.registry.totalRequests }); }); // Start the system await orchestrator.start(); // Example usage after startup setTimeout(async () => { try { console.log('\n๐Ÿงช Testing system functionality...'); // Get system status const status = await orchestrator.getStatus(); console.log('๐Ÿ“Š System Status:', { status: status.status, totalAgents: status.agents.total, healthyAgents: status.agents.healthy, uptime: Math.round(status.uptime / 1000) + 's' }); // Test case investigation (with example case ID) if (process.env['TEST_CASE_ID']) { console.log(`๐Ÿ” Testing case investigation with ID: ${process.env['TEST_CASE_ID']}`); try { const investigation = await orchestrator.investigateCase(process.env['TEST_CASE_ID']); console.log('โœ… Case investigation completed:', { caseId: investigation.caseId, findingsCount: investigation.findings?.length || 0, recommendationsCount: investigation.recommendations?.length || 0 }); } catch (error) { console.log('โ„น๏ธ Case investigation test skipped (expected in demo mode):', error.message); } } // Test workflow execution console.log('๐Ÿ”„ Testing workflow execution...'); try { const workflowResult = await orchestrator.executeWorkflow('case-investigation', { caseId: 'test-case-123' }); console.log('โœ… Workflow execution started:', workflowResult); } catch (error) { console.log('โ„น๏ธ Workflow test skipped (expected in demo mode):', error.message); } // Get agent metrics const metrics = await orchestrator.getAgentMetrics(); console.log('๐Ÿ“ˆ Agent Metrics:', { registryStats: metrics.registry, channelStats: metrics.channel }); console.log('\n๐ŸŽ‰ System test completed successfully!'); } catch (error) { console.error('โŒ System test failed:', error); } }, 5000); // Wait 5 seconds after startup // Handle graceful shutdown process.on('SIGINT', async () => { console.log('\n๐Ÿ›‘ Shutting down Multi-Agent System...'); try { await orchestrator.stop(); console.log('โœ… System shutdown completed'); process.exit(0); } catch (error) { console.error('โŒ Error during shutdown:', error); process.exit(1); } }); process.on('SIGTERM', async () => { console.log('\n๐Ÿ›‘ Received SIGTERM, shutting down...'); try { await orchestrator.stop(); console.log('โœ… System shutdown completed'); process.exit(0); } catch (error) { console.error('โŒ Error during shutdown:', error); process.exit(1); } }); // Keep the process alive console.log('๐Ÿ”„ Multi-Agent System is running. Press Ctrl+C to stop.'); } catch (error) { console.error('โŒ Failed to start Multi-Agent System:', error); process.exit(1); } } // Handle uncaught exceptions process.on('uncaughtException', (error) => { console.error('๐Ÿ’ฅ Uncaught Exception:', error); process.exit(1); }); // Handle unhandled promise rejections process.on('unhandledRejection', (reason, promise) => { console.error('๐Ÿ’ฅ Unhandled Rejection at:', promise, 'reason:', reason); process.exit(1); }); // Start the system startMultiAgentSystem(); //# sourceMappingURL=index.js.map