UNPKG

@agentdb/mcpproxy

Version:

MCP proxy server for remote HTTP endpoints supporting JSON and Server-Sent Events

56 lines (46 loc) 1.48 kB
#!/usr/bin/env node import { spawn } from 'child_process'; import { existsSync } from 'fs'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import { getLocalBinaryPath, downloadBinary } from '../lib/download-binary.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); async function main() { const binaryPath = getLocalBinaryPath(); // Check if binary exists, if not try to download it if (!existsSync(binaryPath)) { console.error('mcpproxy binary not found. Attempting to download...'); try { await downloadBinary(); } catch (error) { console.error('Failed to download binary:', error.message); process.exit(1); } } // Execute the binary with all arguments passed through const args = process.argv.slice(2); const child = spawn(binaryPath, args, { stdio: 'inherit', shell: false }); // Forward signals process.on('SIGINT', () => child.kill('SIGINT')); process.on('SIGTERM', () => child.kill('SIGTERM')); // Exit with the same code as the child process child.on('exit', (code, signal) => { if (signal) { process.kill(process.pid, signal); } else { process.exit(code || 0); } }); child.on('error', (error) => { console.error('Failed to start mcpproxy:', error.message); process.exit(1); }); } main().catch(error => { console.error('Error:', error.message); process.exit(1); });