Skip to content

Commit b41a289

Browse files
chore: update readme following sec recommendations
This commit ensures that our examples promote use of environment variables for providing sensitive configuration options. Additionally we callout, whereever necessary, our recommendation of choosing env variables over command line arguments for the same.
1 parent dd7760b commit b41a289

File tree

1 file changed

+72
-62
lines changed

1 file changed

+72
-62
lines changed

README.md

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ node -v
4747

4848
### Quick Start
4949

50-
**Note:** When using Atlas API credentials, be sure to assign only the minimum required permissions to your service account. See [Atlas API Permissions](#atlas-api-permissions) for details.
50+
> **🔒 Security Recommendation 1:** When using Atlas API credentials, be sure to assign only the minimum required permissions to your service account. See [Atlas API Permissions](#atlas-api-permissions) for details.
51+
52+
> **🔒 Security Recommendation 2:** For enhanced security, we strongly recommend using environment variables to pass sensitive configuration such as connection strings and API credentials instead of command line arguments. Command line arguments can be visible in process lists and logged in various system locations, potentially exposing your secrets. Environment variables provide a more secure way to handle sensitive information.
5153
5254
Most MCP clients require a configuration file to be created or modified to add the MCP server.
5355

@@ -60,30 +62,27 @@ Note: The configuration file syntax can be different across clients. Please refe
6062

6163
> **Default Safety Notice:** All examples below include `--readOnly` by default to ensure safe, read-only access to your data. Remove `--readOnly` if you need to enable write operations.
6264
63-
#### Option 1: Connection String args
65+
#### Option 1: Connection String
6466

65-
You can pass your connection string via args, make sure to use a valid username and password.
67+
You can pass your connection string via environment variables, make sure to use a valid username and password.
6668

6769
```json
6870
{
6971
"mcpServers": {
7072
"MongoDB": {
7173
"command": "npx",
72-
"args": [
73-
"-y",
74-
"mongodb-mcp-server",
75-
"--connectionString",
76-
"mongodb://localhost:27017/myDatabase",
77-
"--readOnly"
78-
]
74+
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
75+
"env": {
76+
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
77+
}
7978
}
8079
}
8180
}
8281
```
8382

8483
NOTE: The connection string can be configured to connect to any MongoDB cluster, whether it's a local instance or an Atlas cluster.
8584

86-
#### Option 2: Atlas API credentials args
85+
#### Option 2: Atlas API Credentials
8786

8887
Use your Atlas API Service Accounts credentials. Must follow all the steps in [Atlas API Access](#atlas-api-access) section.
8988

@@ -92,43 +91,35 @@ Use your Atlas API Service Accounts credentials. Must follow all the steps in [A
9291
"mcpServers": {
9392
"MongoDB": {
9493
"command": "npx",
95-
"args": [
96-
"-y",
97-
"mongodb-mcp-server",
98-
"--apiClientId",
99-
"your-atlas-service-accounts-client-id",
100-
"--apiClientSecret",
101-
"your-atlas-service-accounts-client-secret",
102-
"--readOnly"
103-
]
94+
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
95+
"env": {
96+
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
97+
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
98+
}
10499
}
105100
}
106101
}
107102
```
108103

109-
#### Option 3: Standalone Service using command arguments
104+
#### Option 3: Standalone Service using environment variables and command line arguments
110105

111-
Start Server using npx command:
106+
You can source environment variables defined in a config file or explicitly set them like we do in the example below and run the server via npx.
112107

113108
```shell
114-
npx -y mongodb-mcp-server@latest --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret" --readOnly
115-
```
116-
117-
- For a complete list of arguments see [Configuration Options](#configuration-options)
118-
- To configure your Atlas Service Accounts credentials please refer to [Atlas API Access](#atlas-api-access)
119-
120-
#### Option 4: Standalone Service using environment variables
109+
# Set your credentials as environment variables first
110+
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
111+
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
121112

122-
```shell
123-
npx -y mongodb-mcp-server@latest --readOnly
113+
# Then start the server
114+
npx -y mongodb-mcp-server@latest --readOnly
124115
```
125116

126-
You can use environment variables in the config file or set them and run the server via npx.
127-
117+
- For a complete list of configuration options see [Configuration Options](#configuration-options)
118+
- To configure your Atlas Service Accounts credentials please refer to [Atlas API Access](#atlas-api-access)
128119
- Connection String via environment variables in the MCP file [example](#connection-string-with-environment-variables)
129120
- Atlas API credentials via environment variables in the MCP file [example](#atlas-api-credentials-with-environment-variables)
130121

131-
#### Option 5: Using Docker
122+
#### Option 4: Using Docker
132123

133124
You can run the MongoDB MCP Server in a Docker container, which provides isolation and doesn't require a local Node.js installation.
134125

@@ -146,18 +137,27 @@ docker run --rm -i \
146137
##### Option B: With MongoDB connection string
147138

148139
```shell
140+
# Set your credentials as environment variables first
141+
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/myDatabase"
142+
143+
# Then start the docker container
149144
docker run --rm -i \
150-
-e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/myDatabase" \
145+
-e MDB_MCP_CONNECTION_STRING \
151146
-e MDB_MCP_READ_ONLY="true" \
152147
mongodb/mongodb-mcp-server:latest
153148
```
154149

155150
##### Option C: With Atlas API credentials
156151

157152
```shell
153+
# Set your credentials as environment variables first
154+
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
155+
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
156+
157+
# Then start the docker container
158158
docker run --rm -i \
159-
-e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \
160-
-e MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret" \
159+
-e MDB_MCP_API_CLIENT_ID \
160+
-e MDB_MCP_API_CLIENT_SECRET \
161161
-e MDB_MCP_READ_ONLY="true" \
162162
mongodb/mongodb-mcp-server:latest
163163
```
@@ -196,11 +196,14 @@ With connection string:
196196
"--rm",
197197
"-i",
198198
"-e",
199-
"MDB_MCP_CONNECTION_STRING=mongodb+srv://username:[email protected]/myDatabase",
199+
"MDB_MCP_CONNECTION_STRING",
200200
"-e",
201201
"MDB_MCP_READ_ONLY=true",
202202
"mongodb/mongodb-mcp-server:latest"
203-
]
203+
],
204+
"env": {
205+
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
206+
}
204207
}
205208
}
206209
}
@@ -220,17 +223,21 @@ With Atlas API credentials:
220223
"-e",
221224
"MDB_MCP_READ_ONLY=true",
222225
"-e",
223-
"MDB_MCP_API_CLIENT_ID=your-atlas-service-accounts-client-id",
226+
"MDB_MCP_API_CLIENT_ID",
224227
"-e",
225-
"MDB_MCP_API_CLIENT_SECRET=your-atlas-service-accounts-client-secret",
228+
"MDB_MCP_API_CLIENT_SECRET",
226229
"mongodb/mongodb-mcp-server:latest"
227-
]
230+
],
231+
"env": {
232+
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
233+
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
234+
}
228235
}
229236
}
230237
}
231238
```
232239

233-
#### Option 6: Running as an HTTP Server
240+
#### Option 5: Running as an HTTP Server
234241

235242
> **⚠️ Security Notice:** This server now supports Streamable HTTP transport for remote connections. **HTTP transport is NOT recommended for production use without implementing proper authentication and security measures.**
236243
@@ -316,6 +323,8 @@ NOTE: atlas tools are only available when you set credentials on [configuration]
316323

317324
## Configuration
318325

326+
> **🔒 Security Best Practice:** We strongly recommend using environment variables for sensitive configuration such as API credentials (`MDB_MCP_API_CLIENT_ID`, `MDB_MCP_API_CLIENT_SECRET`) and connection strings (`MDB_MCP_CONNECTION_STRING`) instead of command-line arguments. Environment variables are not visible in process lists and provide better security for your sensitive data.
327+
319328
The MongoDB MCP Server can be configured using multiple methods, with the following precedence (highest to lowest):
320329

321330
1. Command-line arguments
@@ -551,47 +560,48 @@ export MDB_MCP_LOG_PATH="/path/to/logs"
551560

552561
Pass configuration options as command-line arguments when starting the server:
553562

563+
> **🔒 Security Note:** For sensitive configuration like API credentials and connection strings, use environment variables instead of command-line arguments.
564+
554565
```shell
555-
npx -y mongodb-mcp-server@latest --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret" --connectionString="mongodb+srv://username:[email protected]/myDatabase" --logPath=/path/to/logs --readOnly --indexCheck
566+
# Set sensistive data as environment variable
567+
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
568+
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
569+
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/myDatabase"
570+
571+
# Start the server with command line arguments
572+
npx -y mongodb-mcp-server@latest --logPath=/path/to/logs --readOnly --indexCheck
556573
```
557574

558575
#### MCP configuration file examples
559576

560-
##### Connection String with command-line arguments
577+
##### Connection String with environment variables
561578

562579
```json
563580
{
564581
"mcpServers": {
565582
"MongoDB": {
566583
"command": "npx",
567-
"args": [
568-
"-y",
569-
"mongodb-mcp-server",
570-
"--connectionString",
571-
"mongodb+srv://username:[email protected]/myDatabase",
572-
"--readOnly"
573-
]
584+
"args": ["-y", "mongodb-mcp-server", "--readOnly"],
585+
"env": {
586+
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
587+
}
574588
}
575589
}
576590
}
577591
```
578592

579-
##### Atlas API credentials with command-line arguments
593+
##### Atlas API credentials with environment variables
580594

581595
```json
582596
{
583597
"mcpServers": {
584598
"MongoDB": {
585599
"command": "npx",
586-
"args": [
587-
"-y",
588-
"mongodb-mcp-server",
589-
"--apiClientId",
590-
"your-atlas-service-accounts-client-id",
591-
"--apiClientSecret",
592-
"your-atlas-service-accounts-client-secret",
593-
"--readOnly"
594-
]
600+
"args": ["-y", "mongodb-mcp-server", "--readOnly"],
601+
"env": {
602+
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
603+
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
604+
}
595605
}
596606
}
597607
}

0 commit comments

Comments
 (0)