"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHumanQueueServer = createHumanQueueServer;
exports.getServer = getServer;
exports.stopServer = stopServer;
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const logger_1 = require("../../lib/logger");
const server_tools_1 = require("./server-tools");
let server = null;
/**
 * Create the Long Tail Human Queue MCP server.
 *
 * Registers six tools that expose the escalation API:
 * - escalate_to_human -- create a new escalation (fire-and-forget)
 * - check_resolution -- check escalation status
 * - get_available_work -- list available escalations by role
 * - claim_and_resolve -- claim + resolve in one step
 * - resolve_escalation -- resolve an already-claimed escalation
 * - escalate_and_wait -- create escalation and return signal for durable wait
 *
 * The server is created with tools registered but no transport
 * auto-connected. Callers connect a transport programmatically
 * or via the Streamable HTTP endpoint.
 */
async function createHumanQueueServer(options) {
    if (server)
        return server;
    const name = options?.name || 'long-tail-human-queue';
    server = new mcp_js_1.McpServer({ name, version: '1.0.0' });
    (0, server_tools_1.registerHumanQueueTools)(server);
    logger_1.loggerRegistry.info(`[lt-mcp:server] ${name} ready (5 tools registered)`);
    return server;
}
/**
 * Get the current MCP server instance.
 */
function getServer() {
    return server;
}
/**
 * Stop the MCP server and release resources.
 */
async function stopServer() {
    if (server) {
        await server.close();
        server = null;
        logger_1.loggerRegistry.info('[lt-mcp:server] stopped');
    }
}
