UNPKG

xai-live-search-mcp

Version:

šŸ”„ xAI Live Search integration for Claude Code via MCP - BEAST MODE!

164 lines (137 loc) • 5.2 kB
#!/usr/bin/env node // šŸ”„ xAI Live Search MCP - First-Time Setup Wizard const readline = require('readline'); const fs = require('fs'); const path = require('path'); const os = require('os'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); console.log('šŸ”„ xAI Live Search MCP - Setup Wizard'); console.log('====================================='); console.log(''); async function askQuestion(question) { return new Promise((resolve) => { rl.question(question, (answer) => { resolve(answer.trim()); }); }); } async function setupWizard() { try { console.log('šŸš€ Welcome to the xAI Live Search MCP setup!'); console.log(''); console.log('This wizard will help you configure your API key and preferences.'); console.log(''); // Check if already configured const homeEnvPath = path.join(os.homedir(), '.local/share/claude-mcp-servers/.env'); const localEnvPath = path.join(process.cwd(), '.env'); if (fs.existsSync(homeEnvPath) || fs.existsSync(localEnvPath) || process.env.XAI_API_KEY) { const reconfigure = await askQuestion('āš ļø Configuration detected. Reconfigure? (y/N): '); if (!reconfigure.toLowerCase().startsWith('y')) { console.log('āœ… Using existing configuration. Setup complete!'); process.exit(0); } } // Get API key console.log('šŸ“‹ Step 1: API Key Configuration'); console.log(''); console.log('You need an xAI API key from: https://x.ai/api'); console.log(''); const apiKey = await askQuestion('šŸ”‘ Enter your xAI API key: '); if (!apiKey || apiKey === 'your_xai_api_key_here') { console.log('āŒ Valid API key required! Get one from: https://x.ai/api'); process.exit(1); } // Get preferences console.log(''); console.log('šŸ“‹ Step 2: Configuration Preferences'); console.log(''); const model = await askQuestion('šŸ¤– Model (default: grok-3-latest): ') || 'grok-3-latest'; const maxTokens = await askQuestion('šŸ“Š Max tokens (default: 4096): ') || '4096'; const temperature = await askQuestion('šŸŒ”ļø Temperature 0.0-2.0 (default: 0.7): ') || '0.7'; // Choose install location console.log(''); console.log('šŸ“‹ Step 3: Installation Location'); console.log(''); console.log('1) Global (~/.local/share/claude-mcp-servers/) - Recommended'); console.log('2) Current directory'); console.log('3) Environment variable only'); const location = await askQuestion('Choose location (1-3): ') || '1'; // Create configuration const config = `# xAI Live Search MCP Server Configuration # Generated on ${new Date().toISOString()} # Your xAI API Key XAI_API_KEY=${apiKey} # Configuration XAI_MODEL=${model} XAI_MAX_TOKENS=${maxTokens} XAI_TEMPERATURE=${temperature} XAI_BASE_URL=https://api.x.ai # MCP Server Configuration MCP_SERVER_NAME=xai-live-search MCP_SERVER_VERSION=1.0.0 `; let envPath; switch (location) { case '1': // Global installation envPath = path.join(os.homedir(), '.local/share/claude-mcp-servers'); fs.mkdirSync(envPath, { recursive: true }); envPath = path.join(envPath, '.env'); break; case '2': // Current directory envPath = path.join(process.cwd(), '.env'); break; case '3': // Environment variable only console.log(''); console.log('šŸ”§ Add this to your shell profile (~/.bashrc, ~/.zshrc):'); console.log(`export XAI_API_KEY="${apiKey}"`); console.log(`export XAI_MODEL="${model}"`); console.log(`export XAI_MAX_TOKENS="${maxTokens}"`); console.log(`export XAI_TEMPERATURE="${temperature}"`); console.log(''); console.log('Then restart your terminal or run: source ~/.bashrc'); console.log(''); console.log('āœ… Setup complete!'); process.exit(0); break; default: console.log('āŒ Invalid choice'); process.exit(1); } // Write configuration fs.writeFileSync(envPath, config, { mode: 0o600 }); console.log(''); console.log('šŸŽ‰ Setup Complete!'); console.log(''); console.log(`šŸ“ Configuration saved to: ${envPath}`); console.log('šŸ”’ File permissions set to 600 (secure)'); console.log(''); console.log('šŸš€ Add to Claude Code with:'); console.log(' claude mcp add xai-live-search -- npx xai-live-search-mcp'); console.log(''); console.log('šŸ’Ŗ Available tools:'); console.log(' • xai_test_connection'); console.log(' • xai_live_search'); console.log(' • xai_chat_with_search'); console.log(' • xai_configure'); console.log(''); console.log('šŸ”„ BEAST MODE ACTIVATED! Ready to CRUSH information gaps! šŸ’Ŗ'); } catch (error) { console.error('āŒ Setup failed:', error.message); process.exit(1); } process.exit(0); } // Handle Ctrl+C gracefully process.on('SIGINT', () => { console.log('\nāŒ Setup cancelled by user'); process.exit(1); }); setupWizard().finally(() => { rl.close(); });