#!/usr/bin/env node /** * Apollo.io MCP Server - Entry Point * Provides AI-powered access to Apollo.io sales intelligence platform */ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { ApolloMCPServer } from './server.js'; import { ApolloClient } from './client/apollo-client.js'; // Environment validation const apiKey = process.env.APOLLO_API_KEY; if (!apiKey) { console.error('āŒ APOLLO_API_KEY environment variable is required'); console.error(''); console.error('Get your API key from:'); console.error(' 1. Log in to Apollo.io'); console.error(' 2. Go to Settings > Integrations > API'); console.error(' 3. Generate or copy your API key'); console.error(''); console.error('Then set it:'); console.error(' export APOLLO_API_KEY="your-api-key-here"'); console.error(''); process.exit(1); } // Create Apollo API client const apolloClient = new ApolloClient({ apiKey, baseUrl: process.env.APOLLO_BASE_URL, }); // Create MCP server const server = new Server( { name: 'apollo-mcp-server', version: '1.0.0', }, { capabilities: { tools: {}, }, } ); // Initialize Apollo MCP server with tool handlers const apolloServer = new ApolloMCPServer(server, apolloClient); await apolloServer.setupHandlers(); // Graceful shutdown handler let isShuttingDown = false; const shutdown = async (signal: string) => { if (isShuttingDown) return; isShuttingDown = true; console.error(`\nšŸ“” Received ${signal}, shutting down gracefully...`); try { await server.close(); console.error('āœ… Server closed successfully'); process.exit(0); } catch (error) { console.error('āŒ Error during shutdown:', error); process.exit(1); } }; process.on('SIGINT', () => shutdown('SIGINT')); process.on('SIGTERM', () => shutdown('SIGTERM')); // Health check support process.on('message', (msg: any) => { if (msg === 'health_check') { process.send?.({ status: 'healthy', server: 'apollo-mcp' }); } }); // Start server with stdio transport const transport = new StdioServerTransport(); await server.connect(transport); console.error('šŸš€ Apollo MCP Server running on stdio'); console.error(`šŸ“Š ${apolloServer.getToolCount()} tools available`); console.error('');