#!/usr/bin/env node
/**
* Entry point that tries to run the native binary first, then falls back to Node.js.
* This allows the MCP server to work regardless of how Node.js is installed.
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const BINARY_NAME = 'fastmode-mcp';
function getNativeBinaryPath() {
const ext = process.platform === 'win32' ? '.exe' : '';
const binaryPath = path.join(__dirname, `${BINARY_NAME}${ext}`);
if (fs.existsSync(binaryPath)) {
return binaryPath;
}
return null;
}
function runNativeBinary(binaryPath) {
const child = spawn(binaryPath, process.argv.slice(2), {
stdio: 'inherit',
env: process.env,
});
child.on('error', (error) => {
console.error(`Failed to run native binary: ${error.message}`);
runNodeFallback();
});
child.on('exit', (code) => {
process.exit(code || 0);
});
}
function runNodeFallback() {
// Fall back to the Node.js version
require('../dist/index.js');
}
const nativeBinary = getNativeBinaryPath();
if (nativeBinary) {
runNativeBinary(nativeBinary);
} else {
runNodeFallback();
}