/** Convert InteractiveQuestion[] to MCP elicitation JSON Schema. */
export function questionsToElicitSchema(questions) {
    const properties = {};
    const required = [];
    for (const q of questions) {
        const key = q.header.toLowerCase().replace(/\s+/g, '_');
        properties[key] = {
            type: 'string',
            title: q.header,
            description: q.question,
            enum: q.options.map((o) => o.label),
            enumNames: q.options.map((o) => o.description),
        };
        required.push(key);
    }
    return { type: 'object', properties, required };
}
/** Call server.server.elicitInput with graceful fallback if unsupported by the MCP host. */
export async function requestElicitation(server, message, questions) {
    try {
        const schema = questionsToElicitSchema(questions);
        const innerServer = server.server;
        const elicitFn = innerServer.elicitInput;
        if (typeof elicitFn !== 'function') {
            return { supported: false, error: 'Host does not support elicitation' };
        }
        const raw = await elicitFn.call(innerServer, {
            mode: 'form',
            message,
            requestedSchema: schema,
        });
        return { supported: true, result: raw };
    }
    catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        if (msg.includes('does not support')) {
            return { supported: false, error: msg };
        }
        throw err;
    }
}
//# sourceMappingURL=elicit-helper.js.map