import { runStdio, runLoopbackHTTP } from '@duckcodeailabs/dql-mcp';
import { findProjectRoot } from '../local-runtime.js';
export async function runMcp(arg, flags) {
    const projectRoot = findProjectRoot(arg ?? process.cwd());
    if (flags.http) {
        const handle = await runLoopbackHTTP({ projectRoot, port: flags.port ?? 0 });
        process.stderr.write(`dql-mcp listening on ${handle.url}\n`);
        process.stderr.write(`  Authorization: Bearer ${handle.token}\n`);
        for (const sig of ['SIGINT', 'SIGTERM']) {
            process.on(sig, () => void handle.close().then(() => process.exit(0)));
        }
        return;
    }
    await runStdio({ projectRoot });
}
//# sourceMappingURL=mcp.js.map