UNPKG

huggingface-mcp-server

Version:

MCP Server for HuggingFace inference endpoints with custom LoRA and story generation

66 lines (65 loc) 2.64 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const dotenv_1 = __importDefault(require("dotenv")); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const server_1 = require("./server"); const stdio_server_1 = require("./stdio-server"); // Load environment variables dotenv_1.default.config(); const program = new commander_1.Command(); program .name('hf-mcp-server') .description('HuggingFace MCP Server for inference endpoints') .version('1.0.5'); program .option('-p, --port <number>', 'Port to run the HTTP server on', '3000') .option('-k, --api-key <string>', 'HuggingFace API key') .option('-e, --env <path>', 'Path to .env file') .option('-t, --transport <type>', 'Transport type (http or stdio)', 'http') .action(async (options) => { // If env file is specified, load it if (options.env) { const envPath = path_1.default.resolve(process.cwd(), options.env); if (fs_1.default.existsSync(envPath)) { dotenv_1.default.config({ path: envPath }); console.error(`Loaded environment from ${envPath}`); } else { console.error(`Warning: Environment file ${envPath} not found`); } } // Override with command line options if provided const port = options.port ? parseInt(options.port, 10) : undefined; const apiKey = options.apiKey || process.env.HUGGINGFACE_API_KEY; const transport = options.transport || 'http'; if (!apiKey) { console.error('Error: HuggingFace API key is required. Provide it via --api-key option or HUGGINGFACE_API_KEY environment variable.'); process.exit(1); } // Start the appropriate server based on transport try { if (transport === 'stdio') { console.error('Starting in stdio mode for MCP integration'); await (0, stdio_server_1.startStdioServer)(apiKey); } else if (transport === 'http') { await (0, server_1.startHttpServer)(port, apiKey); console.error(`HTTP Server started on port ${port}`); } else { console.error(`Error: Invalid transport type '${transport}'. Must be 'http' or 'stdio'.`); process.exit(1); } } catch (error) { console.error('Failed to start server:', error); process.exit(1); } }); program.parse();