tryaii-mcp-server
Version:
TryAII MCP Server - 15+ AI models with comparison, cost tracking, and collective intelligence
50 lines • 1.84 kB
JavaScript
import { validateConfig } from './utils/config.js';
import { logger } from './utils/logger.js';
import { MultiTransportServer } from './server/MultiTransportServer.js';
class MiddlewareServer {
multiTransportServer;
constructor() {
this.multiTransportServer = new MultiTransportServer();
}
async start() {
try {
// Validate configuration
logger.info('Starting TryAII Dual Mode Server...');
validateConfig();
// Start multi-transport server
await this.multiTransportServer.start();
// Setup graceful shutdown
this.setupGracefulShutdown();
}
catch (error) {
logger.error('Failed to start server', { error });
process.exit(1);
}
}
setupGracefulShutdown() {
const shutdown = async (signal) => {
logger.info(`Received ${signal}, starting graceful shutdown...`);
await this.multiTransportServer.stop();
logger.info('Graceful shutdown completed');
process.exit(0);
};
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));
// Handle uncaught exceptions
process.on('uncaughtException', (error) => {
logger.error('Uncaught exception', { error });
shutdown('uncaughtException');
});
process.on('unhandledRejection', (reason, promise) => {
logger.error('Unhandled rejection', { reason, promise });
shutdown('unhandledRejection');
});
}
}
// Create and start server
const server = new MiddlewareServer();
server.start().catch((error) => {
logger.error('Failed to start middleware server', { error });
process.exit(1);
});
//# sourceMappingURL=server.js.map