UNPKG

safevibe

Version:

Safevibe CLI - Simple personal secret vault for AI developers and amateur vibe coders

68 lines (67 loc) • 2.98 kB
import chalk from "chalk"; import { startMcpServer, getCursorInstructions } from "../utils/mcp.js"; import { isInitialized } from "../utils/config.js"; /** * Start the Safevibe MCP server for Cursor integration */ export async function startCommand(options) { console.log(chalk.cyan("šŸš€ Starting Safevibe MCP Server...\n")); try { // Check if Safevibe is initialized if (!(await isInitialized())) { console.error(chalk.red("āŒ Safevibe is not initialized.")); console.log(chalk.yellow("šŸ’” Run 'safevibe init' first to get started.")); process.exit(1); } // Start the MCP server const server = await startMcpServer(); console.log(chalk.green("āœ… MCP server is running!")); console.log(chalk.cyan("šŸ”— Ready for Cursor integration.")); // Show integration instructions console.log(getCursorInstructions()); console.log(chalk.cyan("\nšŸŽÆ Server Status:")); console.log(chalk.gray(` Process ID: ${server.process.pid}`)); console.log(chalk.gray(" Status: Running")); console.log(chalk.gray(" Protocol: Model Context Protocol (MCP)")); // Handle daemon mode if (options.daemon) { console.log(chalk.yellow("\nšŸ”„ Running in daemon mode...")); console.log(chalk.gray(" Press Ctrl+C to stop the server")); // Keep process alive const keepAlive = () => { setTimeout(keepAlive, 1000); }; keepAlive(); } else { console.log(chalk.yellow("\nšŸ”„ Running in foreground mode...")); console.log(chalk.gray(" Press Ctrl+C to stop the server")); // Keep process alive and handle graceful shutdown process.on('SIGINT', async () => { console.log(chalk.yellow("\n\nšŸ›‘ Stopping MCP server...")); await server.stop(); console.log(chalk.green("āœ… Server stopped gracefully.")); process.exit(0); }); process.on('SIGTERM', async () => { console.log(chalk.yellow("\n\nšŸ›‘ Stopping MCP server...")); await server.stop(); process.exit(0); }); // Keep process alive const keepAlive = () => { setTimeout(keepAlive, 1000); }; keepAlive(); } } catch (error) { console.error(chalk.red(`\nāŒ Failed to start MCP server: ${error.message}`)); // Provide helpful troubleshooting tips console.log(chalk.yellow("\nšŸ’” Troubleshooting:")); console.log(chalk.gray(" - Make sure the backend is running (npm run dev)")); console.log(chalk.gray(" - Check if MCP server is built (npm run build)")); console.log(chalk.gray(" - Verify your configuration (safevibe init)")); process.exit(1); } }