All files / src index.ts

0% Statements 0/16
0% Branches 0/8
0% Functions 0/1
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                     
#!/usr/bin/env node
 
import { Crawl4AIServer } from './server.js';
 
// Try to load dotenv only in development
// In production (via npx), env vars come from the MCP client
try {
  // Only try to load dotenv if CRAWL4AI_BASE_URL is not set
  Iif (!process.env.CRAWL4AI_BASE_URL) {
    const dotenv = await import('dotenv');
    dotenv.config();
  }
} catch {
  // dotenv is not available in production, which is expected
}
 
const CRAWL4AI_BASE_URL = process.env.CRAWL4AI_BASE_URL;
const CRAWL4AI_API_KEY = process.env.CRAWL4AI_API_KEY || '';
const SERVER_NAME = process.env.SERVER_NAME || 'crawl4ai-mcp';
const SERVER_VERSION = process.env.SERVER_VERSION || '1.0.0';
 
Iif (!CRAWL4AI_BASE_URL) {
  console.error('Error: CRAWL4AI_BASE_URL environment variable is required');
  console.error('Please set it to your Crawl4AI server URL (e.g., http://localhost:8080)');
  process.exit(1);
}
 
// Always start the server when this script is executed
// This script is meant to be run as an MCP server
const server = new Crawl4AIServer(CRAWL4AI_BASE_URL, CRAWL4AI_API_KEY, SERVER_NAME, SERVER_VERSION);
server.start().catch((err) => {
  console.error('Server failed to start:', err);
  process.exit(1);
});