UNPKG

smartlead-mcp-by-leadmagic

Version:

šŸ’œ The Premier Model Context Protocol Server for SmartLead's Cold Email Automation Platform - Complete API coverage with 116+ tools for campaign management, lead tracking, smart delivery, and analytics. Beautiful purple-gradient installer, zero-config set

137 lines • 5.36 kB
#!/usr/bin/env node /** * SmartLead MCP Server - Main Entry Point * * Handles both MCP server mode and interactive installer mode * * Usage: * npx smartlead-mcp-by-leadmagic # Start MCP server * npx smartlead-mcp-by-leadmagic install # Start installer * * @author LeadMagic Team * @version 1.6.1 */ import { config } from 'dotenv'; // Load environment variables try { config(); } catch (error) { console.warn('āš ļø Warning: Could not load .env file:', error); } /** * Main entry point - routes to installer or server based on arguments */ async function main() { const args = process.argv.slice(2); if (args.includes('install') || args.includes('--install') || args.includes('-i')) { // Check if running in install mode // Dynamic import to avoid loading React Ink unless needed const { render } = await import('ink'); const React = await import('react'); const { SmartLeadInstaller } = await import('./installer.js'); render(React.createElement(SmartLeadInstaller)); return; } // Otherwise start the MCP server const { SmartLeadMCPServer } = await import('./server.js'); try { console.log('šŸš€ SmartLead MCP Server v1.6.1 - Starting...'); console.log('šŸ“” Built by LeadMagic in partnership with SmartLead'); // Get and validate API key const apiKey = process.env.SMARTLEAD_API_KEY; if (!validateApiKey(apiKey)) { console.error('āŒ Error: Invalid or missing SMARTLEAD_API_KEY environment variable'); console.log(''); console.log('šŸ’” Setup Instructions:'); console.log(' 1. Get your API key from SmartLead account settings'); console.log(' 2. Set the environment variable:'); console.log(' export SMARTLEAD_API_KEY=your_actual_api_key'); console.log(' 3. Or create a .env file with:'); console.log(' SMARTLEAD_API_KEY=your_actual_api_key'); console.log(''); console.log('šŸ”§ Or run the interactive installer:'); console.log(' npx smartlead-mcp-by-leadmagic install'); console.log(''); process.exit(1); } // Parse optional configuration const serverConfig = { baseUrl: process.env.SMARTLEAD_BASE_URL, timeout: process.env.SMARTLEAD_TIMEOUT ? parseInt(process.env.SMARTLEAD_TIMEOUT, 10) : undefined, maxRetries: process.env.SMARTLEAD_MAX_RETRIES ? parseInt(process.env.SMARTLEAD_MAX_RETRIES, 10) : undefined, retryDelay: process.env.SMARTLEAD_RETRY_DELAY ? parseInt(process.env.SMARTLEAD_RETRY_DELAY, 10) : undefined, rateLimit: process.env.SMARTLEAD_RATE_LIMIT ? parseInt(process.env.SMARTLEAD_RATE_LIMIT, 10) : undefined, }; // Initialize and start the server const server = new SmartLeadMCPServer(apiKey, serverConfig); // Set up graceful shutdown const gracefulShutdown = async (signal) => { console.log(`\nšŸ›‘ Received ${signal}, shutting down gracefully...`); try { await server.close(); console.log('āœ… SmartLead MCP Server shutdown complete'); process.exit(0); } catch (error) { console.error('āŒ Error during shutdown:', error); process.exit(1); } }; process.on('SIGINT', () => gracefulShutdown('SIGINT')); process.on('SIGTERM', () => gracefulShutdown('SIGTERM')); // Handle errors process.on('uncaughtException', (error) => { console.error('āŒ Uncaught Exception:', error); process.exit(1); }); process.on('unhandledRejection', (reason, promise) => { console.error('āŒ Unhandled Rejection at:', promise, 'reason:', reason); process.exit(1); }); // Start the server await server.connect(); } catch (error) { console.error('āŒ Failed to start SmartLead MCP Server:', error); if (error instanceof Error) { if (error.message.includes('ECONNREFUSED')) { console.log('šŸ”§ Network connection failed. Please check your internet connection.'); } else if (error.message.includes('401') || error.message.includes('Unauthorized')) { console.log('šŸ”§ Authentication failed. Please verify your SMARTLEAD_API_KEY is correct.'); } } console.log(''); console.log('šŸ’” Try the interactive installer:'); console.log(' npx smartlead-mcp-by-leadmagic install'); console.log(''); process.exit(1); } } /** * Validates the API key */ function validateApiKey(apiKey) { if (!apiKey) return false; if (apiKey.trim().length === 0) return false; if (apiKey === 'your_api_key_here' || apiKey === 'your_smartlead_api_key_here') return false; return true; } // Start the application main().catch((error) => { console.error('āŒ Fatal error:', error); process.exit(1); }); //# sourceMappingURL=index.js.map