Skip to content

Commit 7685461

Browse files
committed
Merge branch 'main' of https://github.com/Rujaxx/mongodb-mcp-server into feat/sse-transport
2 parents 3a20ae0 + 5f779a3 commit 7685461

File tree

7 files changed

+197
-14
lines changed

7 files changed

+197
-14
lines changed

.github/workflows/docker.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Daily Release Docker Image
2+
on:
3+
schedule:
4+
- cron: "0 1 * * *" # Every day at 1:00 AM
5+
workflow_dispatch: # Run the action manually
6+
permissions:
7+
contents: read
8+
issues: write
9+
jobs:
10+
push:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
14+
with:
15+
config: ${{ vars.PERMISSIONS_CONFIG }}
16+
- name: Check out code
17+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
20+
- name: Login to Docker Hub
21+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
22+
with:
23+
username: "${{ secrets.DOCKERHUB_USERNAME }}"
24+
password: "${{ secrets.DOCKERHUB_PASSWORD }}"
25+
- name: Set date and version
26+
id: set-properties
27+
run: |
28+
DATE=$(date +'%Y-%m-%d')
29+
VERSION=$(npm pkg get version | tr -d '"')
30+
echo "DATE=${DATE}" >> "$GITHUB_OUTPUT"
31+
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
32+
- name: Build and push image to dockerhub registry
33+
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1
34+
with:
35+
context: .
36+
platforms: linux/amd64,linux/arm64
37+
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 }}
38+
file: Dockerfile
39+
push: true
40+
provenance: mode=max
41+
sbom: true
42+
build-args: |
43+
VERSION=${{ steps.set-properties.outputs.VERSION }}
44+
- uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
45+
id: app-token
46+
if: ${{ failure() }}
47+
with:
48+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
49+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
50+
- name: Create Issue
51+
if: ${{ failure() }}
52+
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
53+
with:
54+
token: ${{ steps.app-token.outputs.token }}
55+
title: Release Failure for Docker Image ${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }}
56+
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
57+
labels: "docker, release_failure"

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:22-alpine
2+
ARG VERSION=latest
3+
RUN addgroup -S mcp && adduser -S mcp -G mcp
4+
RUN npm install -g mongodb-mcp-server@${VERSION}
5+
USER mcp
6+
WORKDIR /home/mcp
7+
ENTRYPOINT ["mongodb-mcp-server"]
8+
LABEL maintainer="MongoDB Inc <[email protected]>"
9+
LABEL description="MongoDB MCP Server"
10+
LABEL version=${VERSION}

README.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Use your Atlas API Service Accounts credentials. Must follow all the steps in [A
8989
}
9090
```
9191

92-
### Option 3: Standalone Service using command arguments
92+
#### Option 3: Standalone Service using command arguments
9393

9494
Start Server using npx command:
9595

@@ -111,7 +111,98 @@ You can use environment variables in the config file or set them and run the ser
111111
- Connection String via environment variables in the MCP file [example](#connection-string-with-environment-variables)
112112
- Atlas API credentials via environment variables in the MCP file [example](#atlas-api-credentials-with-environment-variables)
113113

114-
#### Option 5: HTTP/SSE Transport (Custom Port)
114+
#### Option 5: Using Docker
115+
116+
You can run the MongoDB MCP Server in a Docker container, which provides isolation and doesn't require a local Node.js installation.
117+
118+
#### Run with Environment Variables
119+
120+
You may provide either a MongoDB connection string OR Atlas API credentials:
121+
122+
##### Option A: No configuration
123+
124+
```shell
125+
docker run --rm -i \
126+
mongodb/mongodb-mcp-server:latest
127+
```
128+
129+
##### Option B: With MongoDB connection string
130+
131+
```shell
132+
docker run --rm -i \
133+
-e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/myDatabase" \
134+
mongodb/mongodb-mcp-server:latest
135+
```
136+
137+
##### Option C: With Atlas API credentials
138+
139+
```shell
140+
docker run --rm -i \
141+
-e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \
142+
-e MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret" \
143+
mongodb/mongodb-mcp-server:latest
144+
```
145+
146+
##### Docker in MCP Configuration File
147+
148+
Without options:
149+
150+
```json
151+
{
152+
"mcpServers": {
153+
"MongoDB": {
154+
"command": "docker",
155+
"args": ["run", "--rm", "-i", "mongodb/mongodb-mcp-server:latest"]
156+
}
157+
}
158+
}
159+
```
160+
161+
With connection string:
162+
163+
```json
164+
{
165+
"mcpServers": {
166+
"MongoDB": {
167+
"command": "docker",
168+
"args": [
169+
"run",
170+
"--rm",
171+
"-i",
172+
"-e",
173+
"MDB_MCP_CONNECTION_STRING=mongodb+srv://username:[email protected]/myDatabase",
174+
"mongodb/mongodb-mcp-server:latest"
175+
]
176+
}
177+
}
178+
}
179+
```
180+
181+
With Atlas API credentials:
182+
183+
```json
184+
{
185+
"mcpServers": {
186+
"MongoDB": {
187+
"command": "docker",
188+
"args": [
189+
"run",
190+
"--rm",
191+
"-i",
192+
"-e",
193+
"MDB_MCP_API_CLIENT_ID=your-atlas-service-accounts-client-id",
194+
"-e",
195+
"MDB_MCP_API_CLIENT_SECRET=your-atlas-service-accounts-client-secret",
196+
"mongodb/mongodb-mcp-server:latest"
197+
]
198+
}
199+
}
200+
}
201+
202+
203+
```
204+
205+
#### Option 6: HTTP/SSE Transport (Custom Port)
115206

116207
You can run the MCP server using HTTP or SSE transport by specifying the `--transportType` and (optionally) `--port` arguments. The default port is `5700` if not specified.
117208

src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ try {
106106
app.listen(PORT);
107107
} else {
108108
const transport = createEJsonTransport();
109+
110+
process.on("SIGINT", () => {
111+
logger.info(LogId.serverCloseRequested, "server", `Server close requested`);
112+
113+
server
114+
.close()
115+
.then(() => {
116+
logger.info(LogId.serverClosed, "server", `Server closed successfully`);
117+
process.exit(0);
118+
})
119+
.catch((err: unknown) => {
120+
const error = err instanceof Error ? err : new Error(String(err));
121+
logger.error(LogId.serverCloseFailure, "server", `Error closing server: ${error.message}`);
122+
process.exit(1);
123+
});
124+
});
109125
await server.connect(transport);
110126
}
111127
} catch (error: unknown) {

src/logger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export type LogLevel = LoggingMessageNotification["params"]["level"];
99
export const LogId = {
1010
serverStartFailure: mongoLogId(1_000_001),
1111
serverInitialized: mongoLogId(1_000_002),
12+
serverCloseRequested: mongoLogId(1_000_003),
13+
serverClosed: mongoLogId(1_000_004),
14+
serverCloseFailure: mongoLogId(1_000_005),
1215

1316
atlasCheckCredentials: mongoLogId(1_001_001),
1417
atlasDeleteDatabaseUserFailure: mongoLogId(1_001_002),

src/tools/mongodb/read/count.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ export const CountArgs = {
88
.record(z.string(), z.unknown())
99
.optional()
1010
.describe(
11-
"The query filter to count documents. Matches the syntax of the filter argument of db.collection.count()"
11+
"A filter/query parameter. Allows users to filter the documents to count. Matches the syntax of the filter argument of db.collection.count()."
1212
),
1313
};
1414

1515
export class CountTool extends MongoDBToolBase {
1616
protected name = "count";
17-
protected description = "Gets the number of documents in a MongoDB collection";
17+
protected description =
18+
"Gets the number of documents in a MongoDB collection using db.collection.count() and query as an optional filter parameter";
1819
protected argsShape = {
1920
...DbOperationArgs,
2021
...CountArgs,

tests/integration/tools/mongodb/read/count.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ import {
88
} from "../../../helpers.js";
99

1010
describeWithMongoDB("count tool", (integration) => {
11-
validateToolMetadata(integration, "count", "Gets the number of documents in a MongoDB collection", [
12-
{
13-
name: "query",
14-
description:
15-
"The query filter to count documents. Matches the syntax of the filter argument of db.collection.count()",
16-
type: "object",
17-
required: false,
18-
},
19-
...databaseCollectionParameters,
20-
]);
11+
validateToolMetadata(
12+
integration,
13+
"count",
14+
"Gets the number of documents in a MongoDB collection using db.collection.count() and query as an optional filter parameter",
15+
[
16+
{
17+
name: "query",
18+
description:
19+
"A filter/query parameter. Allows users to filter the documents to count. Matches the syntax of the filter argument of db.collection.count().",
20+
type: "object",
21+
required: false,
22+
},
23+
...databaseCollectionParameters,
24+
]
25+
);
2126

2227
validateThrowsForInvalidArguments(integration, "count", [
2328
{},

0 commit comments

Comments
 (0)