#!/usr/bin/env node /* Copyright (C) 2026 Moko Consulting * SPDX-License-Identifier: GPL-3.0-or-later * BRIEF: Interactive setup — prompts for Gitea connection details */ import { createInterface } from 'node:readline/promises'; import { readFile, writeFile } from 'node:fs/promises'; import { resolve } from 'node:path'; import { homedir } from 'node:os'; const CONFIG_PATH = resolve(homedir(), '.gitea-api-mcp.json'); const rl = createInterface({ input: process.stdin, output: process.stdout }); async function prompt(q, d) { const a = await rl.question(`${q}${d ? ` [${d}]` : ''}: `); return a.trim() || d || ''; } async function promptRequired(q) { let a = ''; while (!a) { a = (await rl.question(`${q}: `)).trim(); if (!a) console.log(' Required.'); } return a; } async function main() { console.log('\n=== gitea-api-mcp Setup ===\n'); let existing = null; try { existing = JSON.parse(await readFile(CONFIG_PATH, 'utf-8')); console.log(`Existing: ${Object.keys(existing.connections).join(', ')}\n`); } catch {} const name = await prompt('Connection name', 'moko'); const baseUrl = await promptRequired('Gitea URL (e.g. https://git.mokoconsulting.tech)'); const token = await promptRequired('Access token (Settings > Applications > Generate Token)'); const insecure = (await prompt('Skip TLS verification? (y/N)', 'N')).toLowerCase() === 'y'; const conn = { baseUrl: baseUrl.replace(/\/+$/, ''), token }; if (insecure) conn.insecure = true; const config = existing ?? { defaultConnection: name, connections: {} }; config.connections[name] = conn; if (!existing) config.defaultConnection = name; else if ((await prompt(`Set "${name}" as default? (y/N)`, 'N')).toLowerCase() === 'y') config.defaultConnection = name; await writeFile(CONFIG_PATH, JSON.stringify(config, null, '\t') + '\n', 'utf-8'); console.log(`\nConfig written to ${CONFIG_PATH}\n`); rl.close(); } main().catch(e => { console.error(e.message); rl.close(); process.exit(1); });