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
JavaScript
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