setup-guide.js•10.7 kB
#!/usr/bin/env node
// Interactive Setup Guide for Enhanced Coolify MCP Server
// Helps beginners get started with clear instructions and examples
import readline from 'readline';
import fs from 'fs';
import path from 'path';
import { spawn } from 'child_process';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('🚀 Enhanced Coolify MCP Server - Interactive Setup Guide');
console.log('=====================================================');
console.log('');
console.log('This guide will help you set up the Enhanced Coolify MCP Server');
console.log('for use with AI assistants like Claude, Cursor, and others.');
console.log('');
// Helper function to ask questions
function askQuestion(question) {
return new Promise((resolve) => {
rl.question(question, resolve);
});
}
// Helper function to validate URL
function isValidUrl(string) {
try {
new URL(string);
return true;
} catch (_) {
return false;
}
}
// Helper function to validate API token format
function isValidApiToken(token) {
// Coolify tokens typically start with a number followed by |
return /^\d+\|[a-zA-Z0-9]+/.test(token);
}
async function main() {
console.log('📋 Step 1: Coolify Server Information');
console.log('=====================================');
console.log('');
console.log('First, we need to know where your Coolify server is hosted.');
console.log('');
console.log('Common examples:');
console.log(' • Coolify Cloud: https://app.coolify.io');
console.log(' • v0cl.one hosting: https://s1.v0cl.one (or s2, s3, etc.)');
console.log(' • Self-hosted: https://coolify.yourdomain.com');
console.log(' • Local development: http://localhost:3000');
console.log('');
let coolifyUrl = '';
while (!coolifyUrl) {
const input = await askQuestion('🌐 Enter your Coolify server URL: ');
if (!input.trim()) {
console.log('❌ Please enter a URL');
continue;
}
if (!isValidUrl(input)) {
console.log('❌ Please enter a valid URL (including http:// or https://)');
continue;
}
coolifyUrl = input.trim();
console.log(`✅ Coolify server: ${coolifyUrl}`);
}
console.log('');
console.log('🔑 Step 2: API Token Setup');
console.log('==========================');
console.log('');
console.log('Now you need to get your Coolify API token:');
console.log('');
console.log('1. 🌐 Open your Coolify dashboard in a browser:');
console.log(` ${coolifyUrl}`);
console.log('');
console.log('2. 👤 Log in to your account');
console.log('');
console.log('3. ⚙️ Go to Settings → API Tokens (or Profile → API Tokens)');
console.log('');
console.log('4. ➕ Click "Create New Token" or "Generate Token"');
console.log('');
console.log('5. 📝 Give it a name like "MCP Server" or "AI Assistant"');
console.log('');
console.log('6. ✅ Make sure it has these permissions:');
console.log(' • Read servers');
console.log(' • Manage projects');
console.log(' • Manage applications');
console.log(' • Manage services');
console.log(' • Manage databases');
console.log('');
console.log('7. 📋 Copy the generated token (it looks like: 0|1234567890abcdef...)');
console.log('');
await askQuestion('Press Enter when you have your API token ready...');
let apiToken = '';
while (!apiToken) {
const input = await askQuestion('🔑 Paste your Coolify API token: ');
if (!input.trim()) {
console.log('❌ Please enter your API token');
continue;
}
if (!isValidApiToken(input.trim())) {
console.log('❌ This doesn\'t look like a valid Coolify API token.');
console.log(' It should start with a number followed by | (e.g., 0|abc123...)');
console.log(' Please check and try again.');
continue;
}
apiToken = input.trim();
console.log('✅ API token format looks correct');
}
console.log('');
console.log('🔧 Step 3: Choose Your AI Assistant');
console.log('===================================');
console.log('');
console.log('Which AI assistant do you want to use?');
console.log('');
console.log('1. Claude Desktop');
console.log('2. Cursor IDE');
console.log('3. VS Code with MCP extension');
console.log('4. Other MCP-compatible tool');
console.log('5. Just test the server (no AI assistant setup)');
console.log('');
const choice = await askQuestion('Enter your choice (1-5): ');
console.log('');
console.log('📁 Step 4: Configuration Files');
console.log('==============================');
console.log('');
// Create environment file
const envContent = `# Enhanced Coolify MCP Server Configuration
# Generated by setup guide on ${new Date().toISOString()}
COOLIFY_ACCESS_TOKEN="${apiToken}"
COOLIFY_BASE_URL="${coolifyUrl}"
# Optional: Enable debug logging
# DEBUG=coolify:*
`;
fs.writeFileSync('.env', envContent);
console.log('✅ Created .env file with your configuration');
// Generate configuration based on choice
const currentDir = process.cwd();
const serverPath = path.join(currentDir, 'dist', 'index.js');
switch (choice) {
case '1':
console.log('');
console.log('🤖 Claude Desktop Configuration');
console.log('===============================');
console.log('');
console.log('Add this to your Claude Desktop config file:');
console.log('');
console.log('📍 Config file location:');
console.log(' • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json');
console.log(' • Windows: %APPDATA%\\Claude\\claude_desktop_config.json');
console.log(' • Linux: ~/.config/Claude/claude_desktop_config.json');
console.log('');
console.log('📝 Configuration to add:');
console.log('');
console.log(JSON.stringify({
mcpServers: {
coolify: {
command: "node",
args: [serverPath],
env: {
COOLIFY_ACCESS_TOKEN: apiToken,
COOLIFY_BASE_URL: coolifyUrl
}
}
}
}, null, 2));
break;
case '2':
console.log('');
console.log('🎯 Cursor IDE Configuration');
console.log('===========================');
console.log('');
console.log('In Cursor, add this MCP server configuration:');
console.log('');
console.log(`env COOLIFY_ACCESS_TOKEN="${apiToken}" COOLIFY_BASE_URL="${coolifyUrl}" node ${serverPath}`);
break;
case '3':
console.log('');
console.log('💻 VS Code Configuration');
console.log('========================');
console.log('');
console.log('1. Install the MCP extension in VS Code');
console.log('2. Add this server configuration:');
console.log('');
console.log(JSON.stringify({
command: "node",
args: [serverPath],
env: {
COOLIFY_ACCESS_TOKEN: apiToken,
COOLIFY_BASE_URL: coolifyUrl
}
}, null, 2));
break;
case '4':
console.log('');
console.log('🔧 Generic MCP Configuration');
console.log('============================');
console.log('');
console.log('For other MCP-compatible tools, use:');
console.log('');
console.log(`Command: node ${serverPath}`);
console.log('Environment variables:');
console.log(` COOLIFY_ACCESS_TOKEN=${apiToken}`);
console.log(` COOLIFY_BASE_URL=${coolifyUrl}`);
break;
case '5':
console.log('');
console.log('🧪 Testing Configuration');
console.log('========================');
console.log('');
console.log('You can test the server anytime with:');
console.log('');
console.log(' node test-mcpaas.js');
console.log('');
break;
}
console.log('');
console.log('🧪 Step 5: Test Your Setup');
console.log('==========================');
console.log('');
console.log('Let\'s test if everything is working:');
console.log('');
const testNow = await askQuestion('Would you like to test the connection now? (y/n): ');
if (testNow.toLowerCase().startsWith('y')) {
console.log('');
console.log('🔄 Testing connection to Coolify server...');
try {
const testProcess = spawn('node', ['test-mcpaas.js'], {
stdio: 'inherit',
env: {
...process.env,
COOLIFY_ACCESS_TOKEN: apiToken,
COOLIFY_BASE_URL: coolifyUrl
}
});
testProcess.on('close', (code) => {
if (code === 0) {
console.log('');
console.log('🎉 Setup Complete!');
console.log('==================');
console.log('');
console.log('Your Enhanced Coolify MCP Server is ready to use!');
console.log('');
console.log('💬 Try these example prompts with your AI assistant:');
console.log('');
console.log(' "Show me all my Coolify servers"');
console.log(' "List all my applications and their status"');
console.log(' "Create a new project called \'my-app\'"');
console.log(' "Deploy a full-stack project with PostgreSQL and Redis"');
console.log('');
console.log('📚 For more examples, check the README.md file');
console.log('🐛 If you encounter issues, check the troubleshooting section');
console.log('');
console.log('Happy deploying! 🚀');
} else {
console.log('');
console.log('⚠️ Test failed. Please check:');
console.log(' • Your Coolify server is accessible');
console.log(' • Your API token is valid and has correct permissions');
console.log(' • Your network connection is working');
console.log('');
console.log('💡 You can run the test again with: node test-mcpaas.js');
}
rl.close();
});
} catch (error) {
console.log('❌ Error running test:', error.message);
rl.close();
}
} else {
console.log('');
console.log('✅ Setup Complete!');
console.log('==================');
console.log('');
console.log('Your configuration has been saved. You can:');
console.log('');
console.log('🧪 Test anytime with: node test-mcpaas.js');
console.log('📚 Read the full documentation in README.md');
console.log('🚀 Start using with your AI assistant!');
console.log('');
rl.close();
}
}
main().catch((error) => {
console.error('❌ Setup failed:', error.message);
rl.close();
process.exit(1);
});