#!/usr/bin/env node
import { config as loadEnv } from 'dotenv';
loadEnv();
import { loadConfig } from './config.js';
import { parseArgs } from './cli.js';
import { NotionServer } from './server.js';
import { runStdioTransport, startHttpTransport } from './transport/index.js';
async function main() {
try {
const config = loadConfig();
const cliOptions = parseArgs();
const shouldUseHttp = cliOptions.port || (process.env.PORT && !cliOptions.stdio);
const port = cliOptions.port || config.port;
if (shouldUseHttp) {
startHttpTransport({ ...config, port });
}
else {
const server = new NotionServer(config.apiKey, config.version);
await runStdioTransport(server.getServer());
}
}
catch (error) {
console.error("Fatal error running Notion server:", error);
process.exit(1);
}
}
main();