diff --git a/Dockerfile b/Dockerfile index 81fa88a..fd007d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,18 @@ -FROM node:22.16-alpine AS builder - -# Must be entire project because `prepare` script is run during `npm install` and requires all files. -COPY src/ /app/src -COPY tsconfig.json /tsconfig.json +FROM node:22.16.0-bookworm-slim@sha256:048ed02c5fd52e86fda6fbd2f6a76cf0d4492fd6c6fee9e2c463ed5108da0e34 AS builder WORKDIR /app -RUN --mount=type=cache,target=/root/.npm npm install +COPY ./package.json ./package.json +COPY ./package-lock.json ./package-lock.json -FROM node:22-alpine AS release +RUN npm ci --ignore-scripts + +COPY ./src ./src +COPY ./tsconfig.json ./tsconfig.json + +RUN npm run build + +FROM node:22.16.0-bookworm-slim@sha256:048ed02c5fd52e86fda6fbd2f6a76cf0d4492fd6c6fee9e2c463ed5108da0e34 AS release WORKDIR /app @@ -20,4 +24,6 @@ ENV NODE_ENV=production RUN npm ci --ignore-scripts --omit-dev -ENTRYPOINT ["node", "dist/index.js"] \ No newline at end of file +USER node + +CMD ["node", "dist/index.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..301fdf7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +services: + mcp-server: + build: . + cap_drop: + - all + deploy: + restart_policy: + condition: any + delay: 5s + environment: + - BRAVE_API_KEY + - BRAVE_MCP_TRANSPORT=http + - BRAVE_MCP_PORT=8080 + - BRAVE_MCP_HOST=0.0.0.0 + init: true + ports: + - 8080:8080 + security_opt: + - no-new-privileges:true diff --git a/src/index.ts b/src/index.ts index 722e489..f542731 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,14 +19,15 @@ if (!BRAVE_API_KEY) { } const program = new Command() - .option("--transport ", "transport type", "http") - .option("--port ", "desired port for HTTP transport", "3000") + .option("--transport ", "transport type", process.env.BRAVE_MCP_TRANSPORT ?? "stdio") + .option("--port ", "desired port for HTTP transport", process.env.BRAVE_MCP_PORT ?? "3000") + .option("--host ", "host address to bind to for HTTP transport", process.env.BRAVE_MCP_HOST ?? "0.0.0.0") .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(); }