From 13b0fcb0f5a72fd542adc4e713188c0a54a3ef6c Mon Sep 17 00:00:00 2001 From: Kamil Grabowski Date: Tue, 24 Jun 2025 16:54:15 +0200 Subject: [PATCH] add --host parameter --- src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 722e489..3210f92 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,12 +21,13 @@ if (!BRAVE_API_KEY) { const program = new Command() .option("--transport ", "transport type", "http") .option("--port ", "desired port for HTTP transport", "3000") + .option("--host ", "host address to bind to for HTTP transport", "127.0.0.1") .allowUnknownOption() .parse(process.argv); const TRANSPORT_TYPES = ["stdio", "http"] as const; -const CLI_OPTIONS = program.opts<{ transport: "stdio" | "http"; port: string }>(); +const CLI_OPTIONS = program.opts<{ transport: "stdio" | "http"; port: string; host: string }>(); if (!TRANSPORT_TYPES.includes(CLI_OPTIONS.transport)) { console.error(`Invalid --transport value: '${CLI_OPTIONS.transport}'. Must be one of: ${TRANSPORT_TYPES.join(", ")}.`); @@ -83,7 +84,7 @@ async function getHttpTransportForRequest(req: Request, transports: Map) { +function startHttpServer(port: string, host: string, transports: Map) { const app = express(); app.use(express.json()); @@ -102,7 +103,7 @@ function startHttpServer(port: string, transports: Map console.error(`Server is running on http://localhost:${port}/mcp`)); + app.listen(parseInt(port), host, () => console.error(`Server is running on http://${host}:${port}/mcp`)); } async function startStdioServer() { @@ -127,7 +128,7 @@ function main() { const transports = new Map(); if (CLI_OPTIONS.transport === "http") { - startHttpServer(CLI_OPTIONS.port, transports); + startHttpServer(CLI_OPTIONS.port, CLI_OPTIONS.host, transports); } else { startStdioServer(); }