// tools/dashboard.ts — MCP tool handlers for start_dashboard and stop_dashboard.
import { startDashboardServer, stopDashboardServer, registerCleanupHandlers, } from '../engine/dashboard/server.js';
// Register process-exit cleanup once at module load time
registerCleanupHandlers();
/** Handle start_dashboard tool invocation */
export async function handleStartDashboard(args) {
    const port = args.port ?? 5050;
    try {
        const url = await startDashboardServer(port);
        return {
            content: [
                {
                    type: 'text',
                    text: [
                        `Dashboard iniciado en **${url}**`,
                        '',
                        'Abre esa URL en tu navegador para ver el estado de tus proyectos y specs.',
                        'Usa `stop_dashboard` para detenerlo cuando ya no lo necesites.',
                    ].join('\n'),
                },
            ],
        };
    }
    catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        return {
            content: [{ type: 'text', text: `Error al iniciar el dashboard: ${message}` }],
            isError: true,
        };
    }
}
/** Handle stop_dashboard tool invocation */
export async function handleStopDashboard(_args) {
    try {
        const message = await stopDashboardServer();
        return {
            content: [{ type: 'text', text: message }],
        };
    }
    catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        return {
            content: [{ type: 'text', text: `Error al detener el dashboard: ${message}` }],
            isError: true,
        };
    }
}
//# sourceMappingURL=dashboard.js.map