xai-live-search-mcp
Version:
š„ xAI Live Search integration for Claude Code via MCP - BEAST MODE!
145 lines (142 loc) ⢠5.78 kB
JavaScript
// š„ xAI Live Search MCP - TypeScript Setup Wizard
import * as readline from 'readline';
import * as fs from 'fs';
import * as path from 'path';
import * as os from '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());
});
});
}
export async function runSetupWizard() {
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 -- 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);
});
// Run if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
runSetupWizard().finally(() => {
rl.close();
});
}
//# sourceMappingURL=setup-wizard.js.map