diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 00000000..a4af190a --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,55 @@ +name: Daily Release Docker Image +on: + schedule: + - cron: "0 1 * * *" # Every day at 1:00 AM + workflow_dispatch: # Run the action manually +permissions: + contents: read + issues: write +jobs: + push: + runs-on: ubuntu-latest + steps: + - uses: GitHubSecurityLab/actions-permissions/monitor@v1 + with: + config: ${{ vars.PERMISSIONS_CONFIG }} + - name: Check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - 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_USERNAME }}" + password: "${{ secrets.DOCKERHUB_PASSWORD }}" + - name: Set date and version + 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 + 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: | + VERSION=${{ steps.set-properties.outputs.VERSION }} + - 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 ${{ 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/Dockerfile b/Dockerfile new file mode 100644 index 00000000..691a323a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:22-alpine +ARG VERSION=latest +RUN npm install -g mongodb-mcp-server@${VERSION} +ENTRYPOINT ["mongodb-mcp-server"] +LABEL maintainer="MongoDB Inc " +LABEL description="MongoDB MCP Server" +LABEL version=${VERSION} diff --git a/README.md b/README.md index 28c0c755..e11dd1b5 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,95 @@ 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 may provide either a MongoDB connection string OR Atlas API credentials: + +##### Option A: No configuration + +```shell +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 C: With Atlas API credentials + +```shell +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 +``` + +##### 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 +{ + "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