From d766e5c23e084e71d8dac4879fb8d53fc01c3c1b Mon Sep 17 00:00:00 2001 From: Michael Irwin Date: Mon, 23 Dec 2024 14:56:47 -0500 Subject: [PATCH 1/2] Add a Dockerfile to build the MCP server as a container image --- Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8148693 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:22-bookworm-slim AS base +WORKDIR /usr/local/app +COPY package.json . + +# Build the typescript code +FROM base AS dependencies +RUN npm install +COPY tsconfig.json . +COPY src ./src +RUN npm run build + +# Create the final production-ready image +FROM base AS release +RUN useradd -m appuser && chown -R appuser /usr/local/app +ENV NODE_ENV=production +RUN npm install --only=production +COPY --from=dependencies /usr/local/app/dist ./dist +USER appuser +CMD ["node", "dist/index.js"] \ No newline at end of file From 89fbaa13e546616f973320a15078dd33fee2b6ac Mon Sep 17 00:00:00 2001 From: Michael Irwin Date: Mon, 23 Dec 2024 14:57:12 -0500 Subject: [PATCH 2/2] Add process signal handling for a graceful container exit --- src/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/index.ts b/src/index.ts index 6383362..eda8e8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -699,3 +699,11 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => { const transport = new StdioServerTransport(); await server.connect(transport); + +["SIGINT", "SIGTERM"].forEach((signal) => { + process.on(signal, async () => { + console.log(`Received ${signal}, shutting down...`); + await server.close(); + process.exit(0); + }); +}); \ No newline at end of file