Skip to content

feat: docker support #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Daily Release 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
permissions:
contents: read
issues: write
jobs:
build_images:
name: Build and publish docker image
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 }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? Doesn't seem like it's created.

Copy link
Collaborator Author

@fmenezes fmenezes May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/GitHubSecurityLab/actions-permissions/tree/v1/monitor, it is advisable to keep a variable even if it does not exist yet.

- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set properties
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This name is a bit vague, forcing readers to actually read the script being executed - would it make sense to replace with "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: 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_SECRET }}"
- 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 }}${{ 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 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
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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-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"]
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -109,6 +109,75 @@ 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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the connection string anymore, though we should probably preface that with a warning that if you don't, you'll be exposing the connection string to the LLM.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated readme


##### 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
Expand Down
Loading