"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildClaudeMcpInstallCommand = buildClaudeMcpInstallCommand;
exports.buildClaudeMcpRemoveCommand = buildClaudeMcpRemoveCommand;
function buildClaudeMcpInstallCommand(serverName, spec) {
    return [
        "claude",
        "mcp",
        "add-json",
        serverName,
        JSON.stringify(toClaudeServerJson(spec)),
        "--scope",
        "user",
    ];
}
function buildClaudeMcpRemoveCommand(serverName) {
    return ["claude", "mcp", "remove", serverName, "--scope", "user"];
}
function toClaudeServerJson(spec) {
    if (spec.transport === "stdio") {
        return {
            command: spec.command,
            ...(spec.args === undefined ? {} : { args: spec.args }),
            ...(spec.env === undefined ? {} : { env: spec.env }),
            ...(spec.cwd === undefined ? {} : { cwd: spec.cwd }),
        };
    }
    const headers = buildRemoteHeaders(spec);
    return {
        type: spec.transport,
        url: spec.url,
        ...(spec.env === undefined ? {} : { env: spec.env }),
        ...(Object.keys(headers).length === 0 ? {} : { headers }),
    };
}
function buildRemoteHeaders(spec) {
    const headers = { ...(spec.headers ?? {}) };
    if (spec.bearerTokenEnvVar !== undefined) {
        const authorizationHeaderName = "Authorization";
        if (headers[authorizationHeaderName] !== undefined) {
            throw new Error("Claude MCP install cannot combine bearerTokenEnvVar with an explicit Authorization header.");
        }
        headers[authorizationHeaderName] = `Bearer \${${spec.bearerTokenEnvVar}}`;
    }
    return headers;
}
