Skip to content

Commit 20eda56

Browse files
committed
Merge branch 'main' into ni/create-user
2 parents 003179b + 30ee1f6 commit 20eda56

File tree

9 files changed

+208
-96
lines changed

9 files changed

+208
-96
lines changed

README.md

Lines changed: 129 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
11
# MongoDB MCP Server
22

3-
A Model Context Protocol server for interacting with MongoDB Atlas. This project implements a Model Context Protocol (MCP) server enabling AI assistants to interact with MongoDB Atlas resources through natural language.
4-
5-
> [!CAUTION]
6-
> Do not use this in production. This is a work in progress and is not intended for production use. It is meant for demonstration purposes only.
3+
A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas.
74

85
## 📚 Table of Contents
96

107
- [🚀 Getting Started](#getting-started)
118
- [Prerequisites](#prerequisites)
12-
- [Installation](#installation)
13-
- [VSCode](#vscode)
14-
- [Claude Desktop](#claude)
9+
- [Setup](#setup)
10+
- [Quick Start](#quick-start)
1511
- [🛠️ Supported Tools](#supported-tools)
16-
- [Tool List](#tool-list)
12+
- [MongoDB Atlas Tools](#mongodb-atlas-tools)
13+
- [MongoDB Database Tools](#mongodb-database-tools)
1714
- [⚙️ Configuration](#configuration)
1815
- [Configuration Options](#configuration-options)
1916
- [Atlas API Access](#atlas-api-access)
2017
- [Configuration Methods](#configuration-methods)
21-
- [👩‍💻 Client Integration](#client-integration)
22-
- [VSCode](#vscode)
23-
- [Claude](#claude)
18+
- [Environment Variables](#environment-variables)
19+
- [Command-Line Arguments](#command-line-arguments)
20+
- [MCP Client Configuration](#mcp-configuration-file-examples)
2421
- [🤝 Contributing](#contributing)
2522

2623
## Prerequisites
2724

2825
- Node.js (v20 or later)
29-
- MongoDB Atlas account
3026

31-
## Installation
27+
```shell
28+
node -v
29+
```
3230

33-
### VSCode
31+
- A MongoDB connection string or Atlas API credentials, **_the Server will not start unless configured_**.
32+
- **_Atlas API credentials_** are required to use the Atlas tools. You can create a service account in MongoDB Atlas and use its credentials for authentication. See [Atlas API Access](#atlas-api-access) for more details.
33+
- If you have a MongoDB connection string, you can use it directly to connect to your MongoDB instance.
3434

35-
Prerequisites:
35+
## Setup
3636

37-
- Node.js v20.x
37+
### Quick Start
3838

39-
Step 1: Add the mcp server to VSCode configuration
39+
Most MCP clients require a configuration file to be created or modified to add the MCP server.
4040

41-
- Press `Cmd + Shift + P` and type `MCP: Add MCP Server` and select it.
42-
- Select command (Stdio).
43-
- Input command `npx -y mongodb-mcp-server`.
44-
- Choose between user / workspace
45-
- Add arguments to the file
41+
- **Windsurf**:https://docs.windsurf.com/windsurf/mcp
42+
- **VSCode**: https://docs.codeium.com/docs/mcp
43+
- **Claude Desktop**: https://modelcontextprotocol.io/quickstart/user
44+
- **Cursor**: https://docs.cursor.com/context/model-context-protocol
4645

47-
Note: the file should look like:
46+
#### Option 1: Connection String args
4847

49-
```
48+
You can pass your connection string via args, make sure to use a valid username and password.
49+
50+
```json
5051
{
51-
"servers": {
52-
"MongoDB": {
53-
"type": "stdio",
54-
"command": "npx",
55-
"args": [
56-
"-y",
57-
"mongodb-mcp-server"
58-
]
59-
}
52+
"servers": {
53+
"MongoDB": {
54+
"command": "npx",
55+
"args": [
56+
"-y",
57+
"mongodb-mcp-server",
58+
"--connectionString",
59+
"mongodb+srv://username:[email protected]/myDatabase"
60+
]
6061
}
62+
}
6163
}
6264
```
6365

64-
Notes: You can configure the server with atlas access, make sure to follow configuration section for more details.
65-
66-
Step 2: Try talking to github copilot
67-
68-
- Can you connect to my mongodb instance?
69-
70-
### Claude Desktop
71-
72-
Step 1: Install claude and login
73-
74-
Note: follow instructions at https://claude.ai/download
75-
76-
Step 2: Launch Claude Settings -> Developer -> Edit Config
66+
#### Option 2: Atlas API credentials args
7767

78-
Paste the mcp server configuration into the file
68+
Use your Atlas API Service Account credentials. More details in the [Atlas API Access](#atlas-api-access) section.
7969

8070
```json
8171
{
82-
"mcpServers": {
72+
"servers": {
8373
"MongoDB": {
8474
"command": "npx",
85-
"args": ["-y", "mongodb-mcp-server"]
75+
"args": [
76+
"-y",
77+
"mongodb-mcp-server",
78+
"--apiClientId",
79+
"your-atlas-client-id",
80+
"--apiClientSecret",
81+
"your-atlas-client-secret"
82+
]
8683
}
8784
}
8885
}
8986
```
9087

91-
Step 3: Close and Relaunch Claude Desktop and click on the hammer icon, the MongoDB MCP server should be detected.
88+
#### Other options
9289

93-
You may experiment asking `Can you connect to my mongodb instance?`.
90+
Alternatively you can use environment variables in the config file or set them and run the server via npx.
91+
92+
- Connection String via environment variables in the MCP file [example](#connection-string-with-environment-variables)
93+
- Atlas API credentials via environment variables in the MCP file [example](#atlas-api-credentials-with-environment-variables)
9494

9595
## 🛠️ Supported Tools
9696

@@ -154,7 +154,7 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
154154
| `readOnly` | When set to true, only allows read and metadata operation types, disabling create/update/delete operations |
155155
| `telemetry` | When set to disabled, disables telemetry collection |
156156

157-
#### `logPath`
157+
#### Log Path
158158

159159
Default log location is as follows:
160160

@@ -220,6 +220,8 @@ To use the Atlas API tools, you'll need to create a service account in MongoDB A
220220
- Select appropriate permissions (for full access, use Organization Owner)
221221
- Click "Create"
222222

223+
To learn more about Service Accounts, check the [MongoDB Atlas documentation](https://www.mongodb.com/docs/atlas/api/service-accounts-overview/).
224+
223225
2. **Save Client Credentials:**
224226

225227
- After creation, you'll be shown the Client ID and Client Secret
@@ -250,6 +252,41 @@ export MDB_MCP_LOG_PATH="/path/to/logs"
250252

251253
```
252254

255+
#### MCP configuration file examples
256+
257+
##### Connection String with environment variables
258+
259+
```json
260+
{
261+
"servers": {
262+
"MongoDB": {
263+
"command": "npx",
264+
"args": ["-y", "mongodb-mcp-server"],
265+
"env": {
266+
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
267+
}
268+
}
269+
}
270+
}
271+
```
272+
273+
##### Atlas API credentials with environment variables
274+
275+
```json
276+
{
277+
"servers": {
278+
"MongoDB": {
279+
"command": "npx",
280+
"args": ["-y", "mongodb-mcp-server"],
281+
"env": {
282+
"MDB_MCP_API_CLIENT_ID": "your-atlas-client-id",
283+
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-client-secret"
284+
}
285+
}
286+
}
287+
}
288+
```
289+
253290
#### Command-Line Arguments
254291

255292
Pass configuration options as command-line arguments when starting the server:
@@ -258,6 +295,46 @@ Pass configuration options as command-line arguments when starting the server:
258295
npx -y mongodb-mcp-server --apiClientId="your-atlas-client-id" --apiClientSecret="your-atlas-client-secret" --connectionString="mongodb+srv://username:[email protected]/myDatabase" --logPath=/path/to/logs
259296
```
260297

298+
#### MCP configuration file examples
299+
300+
##### Connection String with command-line arguments
301+
302+
```json
303+
{
304+
"servers": {
305+
"MongoDB": {
306+
"command": "npx",
307+
"args": [
308+
"-y",
309+
"mongodb-mcp-server",
310+
"--connectionString",
311+
"mongodb+srv://username:[email protected]/myDatabase"
312+
]
313+
}
314+
}
315+
}
316+
```
317+
318+
##### Atlas API credentials with command-line arguments
319+
320+
```json
321+
{
322+
"servers": {
323+
"MongoDB": {
324+
"command": "npx",
325+
"args": [
326+
"-y",
327+
"mongodb-mcp-server",
328+
"--apiClientId",
329+
"your-atlas-client-id",
330+
"--apiClientSecret",
331+
"your-atlas-client-secret"
332+
]
333+
}
334+
}
335+
}
336+
```
337+
261338
## 🤝 Contributing
262339

263340
Interested in contributing? Great! Please check our [Contributing Guide](CONTRIBUTING.md) for guidelines on code contributions, standards, adding new tools, and troubleshooting information.

package-lock.json

Lines changed: 12 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mongodb-mcp-server",
33
"description": "MongoDB Model Context Protocol Server",
4-
"version": "0.0.7",
4+
"version": "0.1.0",
55
"main": "dist/index.js",
66
"author": "MongoDB <[email protected]>",
77
"homepage": "https://github.com/mongodb-js/mongodb-mcp-server",
@@ -69,7 +69,7 @@
6969
"mongodb-log-writer": "^2.4.1",
7070
"mongodb-redact": "^1.1.6",
7171
"mongodb-schema": "^12.6.2",
72-
"native-machine-id": "^0.1.0",
72+
"node-machine-id": "^1.1.12",
7373
"openapi-fetch": "^0.13.5",
7474
"simple-oauth2": "^5.1.0",
7575
"yargs-parser": "^21.1.1",

src/logger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export const LogId = {
1212

1313
atlasCheckCredentials: mongoLogId(1_001_001),
1414
atlasDeleteDatabaseUserFailure: mongoLogId(1_001_002),
15+
atlasConnectFailure: mongoLogId(1_001_003),
1516

1617
telemetryDisabled: mongoLogId(1_002_001),
1718
telemetryEmitFailure: mongoLogId(1_002_002),
1819
telemetryEmitStart: mongoLogId(1_002_003),
1920
telemetryEmitSuccess: mongoLogId(1_002_004),
2021
telemetryMetadataError: mongoLogId(1_002_005),
22+
telemetryDeviceIdFailure: mongoLogId(1_002_006),
2123

2224
toolExecute: mongoLogId(1_003_001),
2325
toolExecuteFailure: mongoLogId(1_003_002),

0 commit comments

Comments
 (0)