tryaii-mcp-server
Version:
TryAII MCP Server - 15+ AI models with comparison, cost tracking, and collective intelligence
91 lines ⢠4.32 kB
JavaScript
/**
* 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