safevibe
Version:
Safevibe CLI - Simple personal secret vault for AI developers and amateur vibe coders
68 lines (67 loc) ⢠2.98 kB
JavaScript
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);
}
}