#!/usr/bin/env node
/**
* TexasSolver MCP Server Entry Point
*/
import dotenv from 'dotenv';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { SolverExecutor } from './solver/executor.js';
import { StorageManager } from './storage/manager.js';
import TexasSolverMCPServer from './server.js';
/**
* Main initialization function
*/
async function main() {
try {
// Load environment variables
dotenv.config();
// Get solver path from environment
const solverPath = process.env.TEXAS_SOLVER_PATH;
if (!solverPath) {
console.error('ERROR: TEXAS_SOLVER_PATH environment variable not set');
process.exit(1);
}
// Validate solver binary exists and is executable
const solverValid = await SolverExecutor.validateSolver(solverPath);
if (!solverValid) {
console.error(`ERROR: Solver binary not found or not executable: ${solverPath}`);
process.exit(1);
}
// Initialize storage manager
const dataDir = process.env.MCP_DATA_DIR || './data';
const storageManager = new StorageManager(dataDir);
await storageManager.initialize();
// Create and configure MCP server
const mcpServer = new TexasSolverMCPServer(solverPath, storageManager);
// Connect to stdio transport
const transport = new StdioServerTransport();
await mcpServer.connect(transport);
// Log startup (to stderr only - stdout is for MCP protocol)
if (process.env.DEBUG) {
console.error(`[TexasSolver MCP] Server started`);
console.error(`[TexasSolver MCP] Solver: ${solverPath}`);
console.error(`[TexasSolver MCP] Data directory: ${dataDir}`);
}
} catch (error) {
console.error('FATAL ERROR:', error.message);
process.exit(1);
}
}
// Run the server
main();