import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const emptyCleanup = async () => { };
export async function prepareClaudeMcpConfig(mcpServers) {
    if (!mcpServers || Object.keys(mcpServers).length === 0) {
        return { cleanup: emptyCleanup };
    }
    const tempDir = await mkdtemp(join(tmpdir(), 'takt-claude-mcp-'));
    const configPath = join(tempDir, 'mcp-config.json');
    try {
        await chmod(tempDir, 0o700);
        await writeFile(configPath, JSON.stringify({ mcpServers }), {
            encoding: 'utf-8',
            mode: 0o600,
        });
        await chmod(configPath, 0o600);
    }
    catch (error) {
        await rm(tempDir, { recursive: true, force: true });
        throw error;
    }
    return {
        path: configPath,
        cleanup: async () => {
            await rm(tempDir, { recursive: true, force: true });
        },
    };
}
//# sourceMappingURL=mcp-config.js.map