UNPKG

second-opinion

Version:

Get a second opinion on your code from AI - MCP tool for Cursor IDE

98 lines (84 loc) 3.37 kB
#!/usr/bin/env node const { execSync } = require('child_process'); const fs = require('fs'); const os = require('os'); const path = require('path'); console.log('🤔 Second Opinion - AI Code Review Installer'); console.log('Setting up MCP integration for Cursor...'); console.log(''); async function install() { try { // Generate trial token console.log('📝 Generating trial token (5 free credits)...'); const response = await fetch('http://localhost:3000/api/auth/trial-token', { method: 'POST', headers: { 'Content-Type': 'application/json' } }); if (!response.ok) { if (response.status === 429) { console.log('❌ Trial already claimed from this IP address!'); console.log('💡 Ready to subscribe? Visit: http://localhost:3000/pricing'); return; } throw new Error(`Failed to generate trial token: ${response.status}`); } const { trial_token } = await response.json(); console.log(`✅ Trial token generated: ${trial_token.substring(0, 15)}...`); // Set up MCP config const mcpConfigPath = path.join(os.homedir(), '.cursor', 'mcp.json'); let config = { mcpServers: {} }; // Read existing config if it exists if (fs.existsSync(mcpConfigPath)) { try { config = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8')); } catch (error) { console.log('⚠️ Found existing MCP config but couldn\'t parse it, creating new one'); } } else { // Create .cursor directory if it doesn't exist fs.mkdirSync(path.dirname(mcpConfigPath), { recursive: true }); } // Add Second Opinion configuration config.mcpServers['second-opinion'] = { command: 'npx', args: ['second-opinion', 'server'], env: { SECOND_OPINION_API_URL: 'http://localhost:3000/api/second-opinion', TRIAL_TOKEN: trial_token } }; // Write config back fs.writeFileSync(mcpConfigPath, JSON.stringify(config, null, 2)); console.log(`✅ MCP configuration updated: ${mcpConfigPath}`); console.log(''); console.log('🎉 Second Opinion installed successfully!'); console.log(''); console.log('🆓 Trial Mode Active:'); console.log(' • You have 5 free credits to try Second Opinion'); console.log(' • No signup required - start using immediately!'); console.log(' • When credits run out, you\'ll be prompted to upgrade'); console.log(''); console.log('📋 Next steps:'); console.log(' 1. Restart Cursor'); console.log(' 2. Look for \'second-opinion\' in your available tools'); console.log(' 3. Try asking for a second opinion on any code'); console.log(''); console.log('🌍 Global Installation:'); console.log(' • Works in ALL Cursor projects automatically!'); } catch (error) { console.error('❌ Installation failed:', error.message); console.log(''); console.log('💡 Troubleshooting:'); console.log(' • Make sure you have internet connection'); console.log(' • Visit https://secondopinion.codes for help'); } } // Check command line arguments const args = process.argv.slice(2); if (args.includes('server')) { // This is the MCP server mode require('./server.js'); } else { // This is the installer mode install(); }