UNPKG

tryaii-mcp-server

Version:

TryAII MCP Server - 15+ AI models with comparison, cost tracking, and collective intelligence

91 lines • 4.32 kB
#!/usr/bin/env node /** * TryAII MCP Server - Main Entry Point * * This is the main entry point for the npm package. * It can be run as a CLI tool or imported as a module. */ import { config, validateConfig } from './middleware/utils/config.js'; import { MultiTransportServer } from './middleware/server/MultiTransportServer.js'; import { logger } from './middleware/utils/logger.js'; async function main() { try { // Show startup banner console.log(` šŸš€ TryAII MCP Server v${process.env.npm_package_version || '1.0.0'} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ šŸ¤– 15+ AI Models | šŸ” Comparison | šŸ“Š Cost Tracking 🌐 https://tryaii-mcp.onrender.com ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ `); console.log('šŸ”§ Loading and validating configuration...'); validateConfig(); console.log(`šŸ“ MCP Mode: ${config.server.modes.mcp}`); console.log(`šŸ“ HTTP Mode: ${config.server.modes.http}`); console.log(`šŸ“ Port: ${config.server.port}`); console.log(`šŸ“ Database: ${config.database.mainUri ? 'Configured' : 'Not configured'}`); // Configuration is now validated // Create and start the multi-transport server console.log('šŸ—ļø Creating MultiTransportServer...'); const server = new MultiTransportServer(); // Handle graceful shutdown const shutdown = async (signal) => { logger.info(`Received ${signal}, shutting down gracefully...`); try { await server.stop(); logger.info('Server stopped successfully'); process.exit(0); } catch (error) { logger.error('Error during shutdown:', error); process.exit(1); } }; // Register shutdown handlers process.on('SIGTERM', () => shutdown('SIGTERM')); process.on('SIGINT', () => shutdown('SIGINT')); process.on('SIGUSR2', () => shutdown('SIGUSR2')); // nodemon restart // Start the server console.log('šŸš€ Starting server...'); await server.start(); console.log('šŸŽ‰ TryAII MCP Server is running successfully!'); console.log('🌐 Server is listening and ready for requests'); console.log(`šŸ” Health Check: http://localhost:${config.server.port}/health`); logger.info('šŸŽ‰ TryAII MCP Server is running successfully!'); logger.info(`šŸ“– Documentation: https://tryaii-mcp.onrender.com/docs`); logger.info(`šŸ” Health Check: http://localhost:${config.server.port}/health`); // Keep the process alive console.log('ā³ Server running, waiting for requests...'); // Handle unhandled promise rejections to prevent crashes process.on('unhandledRejection', (reason, promise) => { logger.error('Unhandled Promise Rejection:', { reason, promise }); console.error('🚨 Unhandled Promise Rejection:', reason); // Don't exit on unhandled rejections in production }); process.on('uncaughtException', (error) => { logger.error('Uncaught Exception:', error); console.error('🚨 Uncaught Exception:', error); // Exit gracefully on uncaught exceptions process.exit(1); }); // Add a heartbeat to prevent process exit setInterval(() => { console.log(`šŸ’“ Heartbeat: ${new Date().toISOString()} - Server healthy`); }, 60000); // Every minute } catch (error) { console.error('āŒ Fatal error starting TryAII MCP Server:', error); logger.error('Failed to start TryAII MCP Server:', error); process.exit(1); } } // Run if this file is executed directly (ES module version) if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { console.error('Fatal error:', error); process.exit(1); }); } export { main, config }; export default main; //# sourceMappingURL=index.js.map