From 5e832573f4b0fa12b74574f04399ecd4d439097f Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:15:07 +0100 Subject: [PATCH 01/21] feat: docker support --- .github/workflows/docker.yaml | 50 +++++++++++++++++++++++++++++++++++ Dockerfile | 15 +++++++++++ 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/docker.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 00000000..3ed9113a --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,50 @@ +# See RELEASING.md#DockerImage for more details about the steps in this workflow. +name: Daily Release AtlasCLI Docker Image +on: + schedule: + - cron: "0 1 * * *" # Every day at 1:00 AM + workflow_dispatch: # Run the action manually + pull_request: # TODO: delete this before merging +jobs: + build_images: + name: Build and publish docker image to staging registry + runs-on: ubuntu-latest + env: + IMAGE_REPOSITORY: docker.io/mongodb/apix_test + TAG_PREFIX: mongodb-mcp-server + steps: + - uses: GitHubSecurityLab/actions-permissions/monitor@v1 + with: + config: ${{ vars.PERMISSIONS_CONFIG }} + - name: Check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Set properties + id: set-properties + run: | + DATE=$(date +'%Y-%m-%d') + VERSION=$(npm pkg get version | tr -d '"') + echo "DATE=${DATE}" >> "$GITHUB_OUTPUT" + echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 + - name: Login to Docker Hub + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d + with: + username: "${{ secrets.DOCKERHUB_USER }}" + password: "${{ secrets.DOCKERHUB_SECRET }}" + - name: Build and push image to dockerhub staging registry + uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 + with: + context: . + platforms: linux/amd64,linux/arm64 + tags: + ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + file: Dockerfile + push: true + # - name: Create Issue + # if: ${{ failure() }} + # uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd + # with: + # labels: failed-release + # title: Release Failure for Atlas CLI Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + # body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..79983c91 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:22 AS build +WORKDIR /app +COPY package.json package-lock.json tsconfig.build.json ./ +RUN npm install --ignore-scripts +COPY src src +RUN npm run build + +FROM node:22 +WORKDIR /app +COPY --from=build /app/package.json /app/package.json +COPY --from=build /app/package-lock.json /app/package-lock.json +COPY --from=build /app/dist dist +RUN npm ci --omit=dev --ignore-scripts +ENV NODE_ENV=production +CMD ["node", "dist/index.js"] From e2430ab2697fa3fb74d5787a94fc87614cdb864c Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:16:41 +0100 Subject: [PATCH 02/21] fix: docs --- .github/workflows/docker.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 3ed9113a..ff1b58bc 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,5 +1,4 @@ -# See RELEASING.md#DockerImage for more details about the steps in this workflow. -name: Daily Release AtlasCLI Docker Image +name: Daily Release Docker Image on: schedule: - cron: "0 1 * * *" # Every day at 1:00 AM @@ -46,5 +45,5 @@ jobs: # uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd # with: # labels: failed-release - # title: Release Failure for Atlas CLI Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} # body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} From c07a174a7131a16c024fddb35f833b3a8baa531d Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:17:33 +0100 Subject: [PATCH 03/21] fix: auth --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index ff1b58bc..2f2a822f 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -29,7 +29,7 @@ jobs: - name: Login to Docker Hub uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d with: - username: "${{ secrets.DOCKERHUB_USER }}" + username: "${{ secrets.DOCKERHUB_USERNAME }}" password: "${{ secrets.DOCKERHUB_SECRET }}" - name: Build and push image to dockerhub staging registry uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 From fd0ebb7dc61ec7b52159ab569d3547323a2465ce Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:25:49 +0100 Subject: [PATCH 04/21] fix: tag --- .github/workflows/docker.yaml | 8 ++++++-- Dockerfile | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 2f2a822f..06877943 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -4,13 +4,16 @@ on: - cron: "0 1 * * *" # Every day at 1:00 AM workflow_dispatch: # Run the action manually pull_request: # TODO: delete this before merging +permissions: + contents: read + issues: write jobs: build_images: - name: Build and publish docker image to staging registry + name: Build and publish docker image runs-on: ubuntu-latest env: IMAGE_REPOSITORY: docker.io/mongodb/apix_test - TAG_PREFIX: mongodb-mcp-server + TAG_PREFIX: mongodb-mcp-server- steps: - uses: GitHubSecurityLab/actions-permissions/monitor@v1 with: @@ -47,3 +50,4 @@ jobs: # labels: failed-release # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} # body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + # TODO: enable before merging diff --git a/Dockerfile b/Dockerfile index 79983c91..85a05aee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM node:22 AS build +FROM node:22-alpine AS build WORKDIR /app COPY package.json package-lock.json tsconfig.build.json ./ RUN npm install --ignore-scripts COPY src src RUN npm run build -FROM node:22 +FROM node:22-alpine WORKDIR /app COPY --from=build /app/package.json /app/package.json COPY --from=build /app/package-lock.json /app/package-lock.json From 900626af55f8ca9fbd80ea8589e7a8f00d83bf91 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:40:18 +0100 Subject: [PATCH 05/21] fix: docs --- .github/workflows/docker.yaml | 2 +- README.md | 69 ++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 06877943..a39f80a1 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -34,7 +34,7 @@ jobs: with: username: "${{ secrets.DOCKERHUB_USERNAME }}" password: "${{ secrets.DOCKERHUB_SECRET }}" - - name: Build and push image to dockerhub staging registry + - name: Build and push image to dockerhub registry uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 with: context: . diff --git a/README.md b/README.md index 28c0c755..5bd5cb02 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Use your Atlas API Service Accounts credentials. Must follow all the steps in [A } ``` -### Option 3: Standalone Service using command arguments +#### Option 3: Standalone Service using command arguments Start Server using npx command: @@ -109,6 +109,73 @@ You can use environment variables in the config file or set them and run the ser - Connection String via environment variables in the MCP file [example](#connection-string-with-environment-variables) - Atlas API credentials via environment variables in the MCP file [example](#atlas-api-credentials-with-environment-variables) +#### Option 5: Using Docker + +You can run the MongoDB MCP Server in a Docker container, which provides isolation and doesn't require a local Node.js installation. + +#### Run with Environment Variables + +You need to provide either a MongoDB connection string OR Atlas API credentials: + +##### Option A: With MongoDB connection string +```shell +docker run -i \ + -e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" \ + mongodb/mongodb-mcp-server:latest +``` + +##### Option B: With Atlas API credentials +```shell +docker run -i \ + -e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \ + -e MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret" \ + mongodb/mongodb-mcp-server:latest +``` + +##### Docker in MCP Configuration File + +With connection string: + +```json +{ + "mcpServers": { + "MongoDB": { + "command": "docker", + "args": [ + "run", + "--rm", + "-i", + "-e", + "MDB_MCP_CONNECTION_STRING=mongodb+srv://username:password@cluster.mongodb.net/myDatabase", + "mongodb/mongodb-mcp-server:latest" + ] + } + } +} +``` + +With Atlas API credentials: + +```json +{ + "mcpServers": { + "MongoDB": { + "command": "docker", + "args": [ + "run", + "--rm", + "-i", + "-e", + "MDB_MCP_API_CLIENT_ID=your-atlas-service-accounts-client-id", + "-e", + "MDB_MCP_API_CLIENT_SECRET=your-atlas-service-accounts-client-secret", + "mongodb/mongodb-mcp-server:latest" + ] + } + } +} +``` + ## 🛠️ Supported Tools ### Tool List From 2e5b4be5f9d20e5fab4e15cc486690c0d79cc3c4 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:42:02 +0100 Subject: [PATCH 06/21] fix: styles --- .github/workflows/docker.yaml | 3 +-- README.md | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index a39f80a1..243ad94c 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -39,8 +39,7 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - tags: - ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} file: Dockerfile push: true # - name: Create Issue diff --git a/README.md b/README.md index 5bd5cb02..05696f67 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ You can run the MongoDB MCP Server in a Docker container, which provides isolati You need to provide either a MongoDB connection string OR Atlas API credentials: ##### Option A: With MongoDB connection string + ```shell docker run -i \ -e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" \ @@ -125,6 +126,7 @@ docker run -i \ ``` ##### Option B: With Atlas API credentials + ```shell docker run -i \ -e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \ From 968cd2742c4e0b9c3f023e81256f594ed5c4b12f Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:56:17 +0100 Subject: [PATCH 07/21] fix: dist path --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 85a05aee..b4a9cf94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ FROM node:22-alpine WORKDIR /app COPY --from=build /app/package.json /app/package.json COPY --from=build /app/package-lock.json /app/package-lock.json -COPY --from=build /app/dist dist +COPY --from=build /app/dist /app/dist RUN npm ci --omit=dev --ignore-scripts ENV NODE_ENV=production CMD ["node", "dist/index.js"] From 8a04017720bb764ce263b0a2f772fa64c96a2e28 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 15:57:19 +0100 Subject: [PATCH 08/21] fix: dockerfile command order --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b4a9cf94..984d4be5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ RUN npm run build FROM node:22-alpine WORKDIR /app +ENV NODE_ENV=production COPY --from=build /app/package.json /app/package.json COPY --from=build /app/package-lock.json /app/package-lock.json -COPY --from=build /app/dist /app/dist RUN npm ci --omit=dev --ignore-scripts -ENV NODE_ENV=production +COPY --from=build /app/dist /app/dist CMD ["node", "dist/index.js"] From 528b4f17e0ae886bdd72dcfbb86f1b04fb9511c9 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Tue, 13 May 2025 16:00:17 +0100 Subject: [PATCH 09/21] fix: add todo for latest tag --- .github/workflows/docker.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 243ad94c..d64ab2f1 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -39,6 +39,7 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 + # TODO: add latest tag tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} file: Dockerfile push: true From d92b95f895517dc30cf012ef50d6742b78a3b076 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 16:04:37 +0100 Subject: [PATCH 10/21] fix: checkout code for specific version --- .github/workflows/docker.yaml | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index d64ab2f1..da2d920e 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -8,12 +8,12 @@ permissions: contents: read issues: write jobs: - build_images: - name: Build and publish docker image + properties: + name: Set properties runs-on: ubuntu-latest - env: - IMAGE_REPOSITORY: docker.io/mongodb/apix_test - TAG_PREFIX: mongodb-mcp-server- + outputs: + date: ${{ steps.set-properties.outputs.DATE }} + version: ${{ steps.set-properties.outputs.VERSION }} steps: - uses: GitHubSecurityLab/actions-permissions/monitor@v1 with: @@ -27,6 +27,21 @@ jobs: VERSION=$(npm pkg get version | tr -d '"') echo "DATE=${DATE}" >> "$GITHUB_OUTPUT" echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" + push: + name: Build and publish docker image + runs-on: ubuntu-latest + needs: properties + env: + IMAGE_REPOSITORY: docker.io/mongodb/apix_test + TAG_PREFIX: mongodb-mcp-server- + steps: + - uses: GitHubSecurityLab/actions-permissions/monitor@v1 + with: + config: ${{ vars.PERMISSIONS_CONFIG }} + - name: Check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + ref: v${{ needs.properties.outputs.version }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 - name: Login to Docker Hub @@ -40,7 +55,7 @@ jobs: context: . platforms: linux/amd64,linux/arm64 # TODO: add latest tag - tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ needs.properties.outputs.version }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ needs.properties.outputs.version }}-${{ needs.properties.outputs.date }} file: Dockerfile push: true # - name: Create Issue @@ -48,6 +63,6 @@ jobs: # uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd # with: # labels: failed-release - # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ needs.properties.outputs.version }}-${{ needs.properties.outputs.date }} # body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} # TODO: enable before merging From 7030f933e9cb445df5162fc5dd115b835f2e233a Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 16:20:39 +0100 Subject: [PATCH 11/21] fix: pin version --- .github/workflows/docker.yaml | 37 ++++++++++++----------------------- Dockerfile | 17 +++------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index da2d920e..cb669bc6 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -8,29 +8,9 @@ permissions: contents: read issues: write jobs: - properties: - name: Set properties - runs-on: ubuntu-latest - outputs: - date: ${{ steps.set-properties.outputs.DATE }} - version: ${{ steps.set-properties.outputs.VERSION }} - steps: - - uses: GitHubSecurityLab/actions-permissions/monitor@v1 - with: - config: ${{ vars.PERMISSIONS_CONFIG }} - - name: Check out code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - name: Set properties - id: set-properties - run: | - DATE=$(date +'%Y-%m-%d') - VERSION=$(npm pkg get version | tr -d '"') - echo "DATE=${DATE}" >> "$GITHUB_OUTPUT" - echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" push: - name: Build and publish docker image + name: Set properties runs-on: ubuntu-latest - needs: properties env: IMAGE_REPOSITORY: docker.io/mongodb/apix_test TAG_PREFIX: mongodb-mcp-server- @@ -40,8 +20,6 @@ jobs: config: ${{ vars.PERMISSIONS_CONFIG }} - name: Check out code uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - with: - ref: v${{ needs.properties.outputs.version }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 - name: Login to Docker Hub @@ -49,20 +27,29 @@ jobs: with: username: "${{ secrets.DOCKERHUB_USERNAME }}" password: "${{ secrets.DOCKERHUB_SECRET }}" + - name: Set properties + id: set-properties + run: | + DATE=$(date +'%Y-%m-%d') + VERSION=$(npm pkg get version | tr -d '"') + echo "DATE=${DATE}" >> "$GITHUB_OUTPUT" + echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" - name: Build and push image to dockerhub registry uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 with: context: . platforms: linux/amd64,linux/arm64 # TODO: add latest tag - tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ needs.properties.outputs.version }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ needs.properties.outputs.version }}-${{ needs.properties.outputs.date }} + tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} file: Dockerfile push: true + build-args: | + VERSION=${{ steps.set-properties.outputs.VERSION }} # - name: Create Issue # if: ${{ failure() }} # uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd # with: # labels: failed-release - # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ needs.properties.outputs.version }}-${{ needs.properties.outputs.date }} + # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} # body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} # TODO: enable before merging diff --git a/Dockerfile b/Dockerfile index 984d4be5..d0778543 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,4 @@ -FROM node:22-alpine AS build -WORKDIR /app -COPY package.json package-lock.json tsconfig.build.json ./ -RUN npm install --ignore-scripts -COPY src src -RUN npm run build - +ARG VERSION=latest FROM node:22-alpine -WORKDIR /app -ENV NODE_ENV=production -COPY --from=build /app/package.json /app/package.json -COPY --from=build /app/package-lock.json /app/package-lock.json -RUN npm ci --omit=dev --ignore-scripts -COPY --from=build /app/dist /app/dist -CMD ["node", "dist/index.js"] +RUN npm install -g mongodb-mcp-server@${VERSION} +CMD ["mongodb-mcp-server"] From fabb1c805534e641d982bade5df89ab46ae4a9aa Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 16:24:22 +0100 Subject: [PATCH 12/21] fix: readme --- README.md | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 05696f67..5a859a75 100644 --- a/README.md +++ b/README.md @@ -115,20 +115,27 @@ You can run the MongoDB MCP Server in a Docker container, which provides isolati #### Run with Environment Variables -You need to provide either a MongoDB connection string OR Atlas API credentials: +You may provide either a MongoDB connection string OR Atlas API credentials: -##### Option A: With MongoDB connection string +##### Option A: No configuration ```shell -docker run -i \ +docker run --rm -i \ + mongodb/mongodb-mcp-server:latest +``` + +##### Option B: With MongoDB connection string + +```shell +docker run --rm -i \ -e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" \ mongodb/mongodb-mcp-server:latest ``` -##### Option B: With Atlas API credentials +##### Option C: With Atlas API credentials ```shell -docker run -i \ +docker run --rm -i \ -e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \ -e MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret" \ mongodb/mongodb-mcp-server:latest @@ -136,6 +143,24 @@ docker run -i \ ##### Docker in MCP Configuration File +Without options: + +```json +{ + "mcpServers": { + "MongoDB": { + "command": "docker", + "args": [ + "run", + "--rm", + "-i", + "mongodb/mongodb-mcp-server:latest" + ] + } + } +} +``` + With connection string: ```json From ee0ae2b4b72300641c069fc518c66d663967358a Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 16:24:50 +0100 Subject: [PATCH 13/21] fix: action name --- .github/workflows/docker.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index cb669bc6..678c4fa5 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -9,7 +9,6 @@ permissions: issues: write jobs: push: - name: Set properties runs-on: ubuntu-latest env: IMAGE_REPOSITORY: docker.io/mongodb/apix_test From 4b44f9bafe065e0dcc0f6c8e59ca6e9647009a8c Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 16:37:07 +0100 Subject: [PATCH 14/21] fix: styles and add latest tag --- .github/workflows/docker.yaml | 25 +++++++++++++++---------- README.md | 7 +------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 678c4fa5..cb48c689 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -38,17 +38,22 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - # TODO: add latest tag - tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + tags: ${{ env.IMAGE_REPOSITORY }}:latest, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} file: Dockerfile push: true build-args: | VERSION=${{ steps.set-properties.outputs.VERSION }} - # - name: Create Issue - # if: ${{ failure() }} - # uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd - # with: - # labels: failed-release - # title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} - # body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - # TODO: enable before merging + - uses: mongodb-js/devtools-shared/actions/setup-bot-token@main + id: app-token + if: ${{ failure() }} + with: + app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }} + private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }} + - name: Create Issue + if: ${{ failure() }} + uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd + with: + token: ${{ steps.app-token.outputs.token }} + title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + labels: "docker, release_failure" diff --git a/README.md b/README.md index 5a859a75..e11dd1b5 100644 --- a/README.md +++ b/README.md @@ -150,12 +150,7 @@ Without options: "mcpServers": { "MongoDB": { "command": "docker", - "args": [ - "run", - "--rm", - "-i", - "mongodb/mongodb-mcp-server:latest" - ] + "args": ["run", "--rm", "-i", "mongodb/mongodb-mcp-server:latest"] } } } From 4fd4a6fa900a29307e5017fc52e9ed2ee3e73651 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 16:39:10 +0100 Subject: [PATCH 15/21] fix: correct docker repo --- .github/workflows/docker.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index cb48c689..c62a6d26 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -3,7 +3,6 @@ on: schedule: - cron: "0 1 * * *" # Every day at 1:00 AM workflow_dispatch: # Run the action manually - pull_request: # TODO: delete this before merging permissions: contents: read issues: write @@ -11,8 +10,7 @@ jobs: push: runs-on: ubuntu-latest env: - IMAGE_REPOSITORY: docker.io/mongodb/apix_test - TAG_PREFIX: mongodb-mcp-server- + IMAGE_REPOSITORY: docker.io/mongodb/mongodb-mcp-server steps: - uses: GitHubSecurityLab/actions-permissions/monitor@v1 with: @@ -38,7 +36,7 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - tags: ${{ env.IMAGE_REPOSITORY }}:latest, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + tags: ${{ env.IMAGE_REPOSITORY }}:latest, ${{ env.IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} file: Dockerfile push: true build-args: | @@ -54,6 +52,6 @@ jobs: uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd with: token: ${{ steps.app-token.outputs.token }} - title: Release Failure for Docker Image ${{ env.TAG_PREFIX }}${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + title: Release Failure for Docker Image ${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} labels: "docker, release_failure" From 6c714b3d28feb045cf522095024719794adc6276 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 17:40:08 +0100 Subject: [PATCH 16/21] fix: add telemetry --- src/telemetry/telemetry.ts | 40 ++++++++++++++++++++++++++++++++++++++ src/telemetry/types.ts | 1 + 2 files changed, 41 insertions(+) diff --git a/src/telemetry/telemetry.ts b/src/telemetry/telemetry.ts index ccf0eb41..6036a49c 100644 --- a/src/telemetry/telemetry.ts +++ b/src/telemetry/telemetry.ts @@ -7,6 +7,10 @@ import { MACHINE_METADATA } from "./constants.js"; import { EventCache } from "./eventCache.js"; import nodeMachineId from "node-machine-id"; import { getDeviceId } from "@mongodb-js/device-id"; +import fs from "fs/promises"; +import os from "os"; +import path from "path"; +import { randomUUID } from "crypto"; type EventResult = { success: boolean; @@ -15,6 +19,26 @@ type EventResult = { export const DEVICE_ID_TIMEOUT = 3000; +async function fileExists(filepath: string): Promise { + try { + await fs.stat(filepath); + return true; + } catch { + return false; + } +} + +async function isContainerEnv(): Promise { + if (await fileExists("/.dockerenv")) { + return true; + } + return process.env.container != ""; +} + +function containerIdFilePath(): string { + return path.join(os.homedir(), ".mongodb", "container", ".containerId"); +} + export class Telemetry { private isBufferingEvents: boolean = true; /** Resolves when the device ID is retrieved or timeout occurs */ @@ -74,6 +98,22 @@ export class Telemetry { abortSignal: this.deviceIdAbortController.signal, }); + const containerEnv = await isContainerEnv(); + + if (containerEnv) { + const filePath = containerIdFilePath(); + const exists = await fileExists(filePath); + let content: string; + if (exists) { + content = await fs.readFile(filePath, "utf8"); + } else { + content = randomUUID().toString(); + await fs.mkdir(path.dirname(filePath), { recursive: true }); + await fs.writeFile(filePath, content, "utf8"); + } + this.commonProperties.container_id = content; + } + this.commonProperties.device_id = await this.deviceIdPromise; this.isBufferingEvents = false; diff --git a/src/telemetry/types.ts b/src/telemetry/types.ts index d77cc010..05b49619 100644 --- a/src/telemetry/types.ts +++ b/src/telemetry/types.ts @@ -71,4 +71,5 @@ export type CommonProperties = { config_atlas_auth?: TelemetryBoolSet; config_connection_string?: TelemetryBoolSet; session_id?: string; + container_id?: string; } & CommonStaticProperties; From f7ef00376fe73ba1884474af0f5786da7317d15c Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 17:45:54 +0100 Subject: [PATCH 17/21] fix: docker labels --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d0778543..a5673d7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -ARG VERSION=latest FROM node:22-alpine +ARG VERSION=latest RUN npm install -g mongodb-mcp-server@${VERSION} CMD ["mongodb-mcp-server"] +LABEL maintainer="MongoDB Inc " +LABEL description="MongoDB MCP Server" +LABEL version=${VERSION} From 9f7370ee5cc1fc04a9431eec66164c2d10da61dd Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 19:50:40 +0100 Subject: [PATCH 18/21] Revert "fix: add telemetry" This reverts commit 6c714b3d28feb045cf522095024719794adc6276. --- src/telemetry/telemetry.ts | 40 -------------------------------------- src/telemetry/types.ts | 1 - 2 files changed, 41 deletions(-) diff --git a/src/telemetry/telemetry.ts b/src/telemetry/telemetry.ts index 6036a49c..ccf0eb41 100644 --- a/src/telemetry/telemetry.ts +++ b/src/telemetry/telemetry.ts @@ -7,10 +7,6 @@ import { MACHINE_METADATA } from "./constants.js"; import { EventCache } from "./eventCache.js"; import nodeMachineId from "node-machine-id"; import { getDeviceId } from "@mongodb-js/device-id"; -import fs from "fs/promises"; -import os from "os"; -import path from "path"; -import { randomUUID } from "crypto"; type EventResult = { success: boolean; @@ -19,26 +15,6 @@ type EventResult = { export const DEVICE_ID_TIMEOUT = 3000; -async function fileExists(filepath: string): Promise { - try { - await fs.stat(filepath); - return true; - } catch { - return false; - } -} - -async function isContainerEnv(): Promise { - if (await fileExists("/.dockerenv")) { - return true; - } - return process.env.container != ""; -} - -function containerIdFilePath(): string { - return path.join(os.homedir(), ".mongodb", "container", ".containerId"); -} - export class Telemetry { private isBufferingEvents: boolean = true; /** Resolves when the device ID is retrieved or timeout occurs */ @@ -98,22 +74,6 @@ export class Telemetry { abortSignal: this.deviceIdAbortController.signal, }); - const containerEnv = await isContainerEnv(); - - if (containerEnv) { - const filePath = containerIdFilePath(); - const exists = await fileExists(filePath); - let content: string; - if (exists) { - content = await fs.readFile(filePath, "utf8"); - } else { - content = randomUUID().toString(); - await fs.mkdir(path.dirname(filePath), { recursive: true }); - await fs.writeFile(filePath, content, "utf8"); - } - this.commonProperties.container_id = content; - } - this.commonProperties.device_id = await this.deviceIdPromise; this.isBufferingEvents = false; diff --git a/src/telemetry/types.ts b/src/telemetry/types.ts index 05b49619..d77cc010 100644 --- a/src/telemetry/types.ts +++ b/src/telemetry/types.ts @@ -71,5 +71,4 @@ export type CommonProperties = { config_atlas_auth?: TelemetryBoolSet; config_connection_string?: TelemetryBoolSet; session_id?: string; - container_id?: string; } & CommonStaticProperties; From 440b3cfe5cc17a6dd256b21d86e8c43d24778a53 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Thu, 15 May 2025 20:08:58 +0100 Subject: [PATCH 19/21] fix: entrypoint --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a5673d7d..691a323a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM node:22-alpine ARG VERSION=latest RUN npm install -g mongodb-mcp-server@${VERSION} -CMD ["mongodb-mcp-server"] +ENTRYPOINT ["mongodb-mcp-server"] LABEL maintainer="MongoDB Inc " LABEL description="MongoDB MCP Server" LABEL version=${VERSION} From e12a3185d3610b94a371aa6e506e37bc9b89d894 Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Fri, 16 May 2025 10:14:42 +0100 Subject: [PATCH 20/21] fix: address small comments --- .github/workflows/docker.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index c62a6d26..ef807ccd 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -3,14 +3,13 @@ on: schedule: - cron: "0 1 * * *" # Every day at 1:00 AM workflow_dispatch: # Run the action manually + pull_request: # TODO: remove before merging permissions: contents: read issues: write jobs: push: runs-on: ubuntu-latest - env: - IMAGE_REPOSITORY: docker.io/mongodb/mongodb-mcp-server steps: - uses: GitHubSecurityLab/actions-permissions/monitor@v1 with: @@ -23,8 +22,8 @@ jobs: uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d with: username: "${{ secrets.DOCKERHUB_USERNAME }}" - password: "${{ secrets.DOCKERHUB_SECRET }}" - - name: Set properties + password: "${{ secrets.DOCKERHUB_PASSWORD }}" + - name: Set date and version id: set-properties run: | DATE=$(date +'%Y-%m-%d') @@ -36,7 +35,7 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - tags: ${{ env.IMAGE_REPOSITORY }}:latest, ${{ env.IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}, ${{ env.IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} + tags: ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:latest, ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}, ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }} file: Dockerfile push: true build-args: | From 5ede17a917cfc029c8e019114aa5698d01a955ab Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Fri, 16 May 2025 10:17:28 +0100 Subject: [PATCH 21/21] fix: remove pr --- .github/workflows/docker.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index ef807ccd..a4af190a 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -3,7 +3,6 @@ on: schedule: - cron: "0 1 * * *" # Every day at 1:00 AM workflow_dispatch: # Run the action manually - pull_request: # TODO: remove before merging permissions: contents: read issues: write