UNPKG

spex-mcp

Version:

MCP server for Figma SpeX plugin and Cursor AI integration

80 lines (65 loc) 2.66 kB
#!/usr/bin/env node /** * SpeX MCP Server Router * Routes to either local or remote implementation based on arguments */ import { pathToFileURL } from 'url'; import { join } from 'path'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); function parseMode() { const args = process.argv.slice(2); // Check for explicit mode selection if (args.includes('--mode')) { const modeIndex = args.indexOf('--mode'); if (modeIndex + 1 < args.length) { const mode = args[modeIndex + 1]; if (['local', 'remote'].includes(mode)) { return mode; } } } // Auto-detect mode based on arguments const hasClientType = args.includes('--client-type'); const hasServerUrl = args.includes('--server-url'); const hasSessionId = args.includes('--session-id'); // If any remote-specific arguments are present, use remote mode if (hasClientType || hasServerUrl || hasSessionId) { console.error('🌐 Auto-detected remote mode based on arguments'); return 'remote'; } // Default to remote mode (for cloud deployment) console.error('🌐 Using default remote mode'); return 'remote'; } async function main() { try { const mode = parseMode(); console.error(`🚀 Starting SpeX MCP Server in ${mode} mode`); // Route to appropriate implementation const modulePath = join(__dirname, mode, 'index.js'); const moduleUrl = pathToFileURL(modulePath); // Import and run the selected mode await import(moduleUrl); } catch (error) { console.error(`❌ Error starting SpeX MCP Server: ${error.message}`); if (error.code === 'ERR_MODULE_NOT_FOUND') { console.error(''); console.error('Available modes:'); console.error(' --mode local # Local development mode'); console.error(' --mode remote # Remote/cloud mode (default)'); console.error(''); console.error('Examples:'); console.error(' node src/index.js --mode local --port 8080 --force'); console.error(' node src/index.js --mode remote --client-type mcp-client --session-id abc123'); console.error(' node src/index.js --session-id abc123 # Auto-detects remote mode'); } process.exit(1); } } main().catch((error) => { console.error(`❌ Unexpected error: ${error.message}`); process.exit(1); });