mcp-mongo-server 1.3.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -339
- package/build/index.js +1825 -63
- package/package.json +74 -50
- package/build/mongo.js +0 -33
- package/build/schemas/call.js +0 -591
- package/build/schemas/completion.js +0 -112
- package/build/schemas/ping.js +0 -20
- package/build/schemas/prompts.js +0 -71
- package/build/schemas/resource.js +0 -213
- package/build/schemas/templates.js +0 -39
- package/build/schemas/tools.js +0 -281
- package/build/server.js +0 -65
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|

|
|
6
6
|

|
|
7
7
|
[](https://smithery.ai/server/mcp-mongo-server)
|
|
8
|
+
[](https://mseep.ai/app/e274a3dd-7fe6-4440-8c43-043bae668251)
|
|
8
9
|
|
|
9
10
|
A Model Context Protocol server that enables LLMs to interact with MongoDB databases. This server provides capabilities for inspecting collection schemas and executing MongoDB operations through a standardized interface.
|
|
10
11
|
|
|
@@ -14,70 +15,21 @@ A Model Context Protocol server that enables LLMs to interact with MongoDB datab
|
|
|
14
15
|
|
|
15
16
|
## Key Features
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Flexible Configuration
|
|
25
|
-
- **Environment Variables**:
|
|
26
|
-
- `MCP_MONGODB_URI`: MongoDB connection URI
|
|
27
|
-
- `MCP_MONGODB_READONLY`: Enable read-only mode when set to "true"
|
|
28
|
-
- **Command-line Options**:
|
|
29
|
-
- `--read-only` or `-r`: Connect in read-only mode
|
|
30
|
-
|
|
31
|
-
### Read-Only Mode
|
|
32
|
-
- Protection against write operations (update, insert, createIndex)
|
|
33
|
-
- Uses MongoDB's secondary read preference for optimal performance
|
|
34
|
-
- Ideal for safely connecting to production databases
|
|
35
|
-
|
|
36
|
-
### MongoDB Operations
|
|
37
|
-
- **Read Operations**:
|
|
38
|
-
- Query documents with optional execution plan analysis
|
|
39
|
-
- Execute aggregation pipelines
|
|
40
|
-
- Count documents matching criteria
|
|
41
|
-
- Get collection schema information
|
|
42
|
-
- **Write Operations** (when not in read-only mode):
|
|
43
|
-
- Update documents
|
|
44
|
-
- Insert new documents
|
|
45
|
-
- Create indexes
|
|
46
|
-
|
|
47
|
-
### LLM Integration
|
|
48
|
-
- Collection completions for enhanced LLM interaction
|
|
49
|
-
- Schema inference for improved context understanding
|
|
50
|
-
- Collection analysis for data insights
|
|
18
|
+
- **Smart ObjectId Handling** - Configurable auto/none/force modes for string-to-ObjectId conversion
|
|
19
|
+
- **Read-Only Mode** - Protection against write operations, uses secondary read preference
|
|
20
|
+
- **Schema Inference** - Automatic collection schema detection from document samples
|
|
21
|
+
- **Query & Aggregation** - Full MongoDB query and aggregation pipeline support with optional explain plans
|
|
22
|
+
- **Write Operations** - Insert, update, and index creation (when not in read-only mode)
|
|
23
|
+
- **Collection Completions** - Auto-complete collection names for LLM integration
|
|
51
24
|
|
|
52
25
|
## Installation
|
|
53
26
|
|
|
54
|
-
### Global Installation
|
|
55
|
-
|
|
56
27
|
```bash
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### For Development
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
# Clone repository
|
|
64
|
-
git clone https://github.com/kiliczsh/mcp-mongo-server.git
|
|
65
|
-
cd mcp-mongo-server
|
|
66
|
-
|
|
67
|
-
# Install dependencies
|
|
68
|
-
npm install
|
|
69
|
-
|
|
70
|
-
# Build
|
|
71
|
-
npm run build
|
|
72
|
-
|
|
73
|
-
# Development with auto-rebuild
|
|
74
|
-
npm run watch
|
|
28
|
+
npx -y mcp-mongo-server mongodb://localhost:27017/database
|
|
75
29
|
```
|
|
76
30
|
|
|
77
31
|
## Usage
|
|
78
32
|
|
|
79
|
-
### Basic Usage
|
|
80
|
-
|
|
81
33
|
```bash
|
|
82
34
|
# Start server with MongoDB URI
|
|
83
35
|
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database
|
|
@@ -88,291 +40,18 @@ npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read
|
|
|
88
40
|
|
|
89
41
|
### Environment Variables
|
|
90
42
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database"
|
|
96
|
-
|
|
97
|
-
# Enable read-only mode
|
|
98
|
-
export MCP_MONGODB_READONLY="true"
|
|
99
|
-
|
|
100
|
-
# Run server (will use environment variables if no URI is provided)
|
|
101
|
-
npx -y mcp-mongo-server
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Using environment variables in Claude Desktop configuration:
|
|
105
|
-
|
|
106
|
-
```json
|
|
107
|
-
{
|
|
108
|
-
"mcpServers": {
|
|
109
|
-
"mongodb-env": {
|
|
110
|
-
"command": "npx",
|
|
111
|
-
"args": [
|
|
112
|
-
"-y",
|
|
113
|
-
"mcp-mongo-server"
|
|
114
|
-
],
|
|
115
|
-
"env": {
|
|
116
|
-
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
|
|
117
|
-
"MCP_MONGODB_READONLY": "true"
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Using environment variables with Docker:
|
|
125
|
-
|
|
126
|
-
```bash
|
|
127
|
-
# Build
|
|
128
|
-
docker build -t mcp-mongo-server .
|
|
129
|
-
|
|
130
|
-
# Run
|
|
131
|
-
docker run -it -d -e MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" -e MCP_MONGODB_READONLY="true" mcp-mongo-server
|
|
132
|
-
|
|
133
|
-
# or edit docker-compose.yml and run
|
|
134
|
-
docker-compose up -d
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## Integration with Claude Desktop
|
|
138
|
-
|
|
139
|
-
### Manual Configuration
|
|
140
|
-
|
|
141
|
-
Add the server configuration to Claude Desktop's config file:
|
|
142
|
-
|
|
143
|
-
**MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
144
|
-
**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
145
|
-
|
|
146
|
-
#### Command-line Arguments Approach:
|
|
147
|
-
|
|
148
|
-
```json
|
|
149
|
-
{
|
|
150
|
-
"mcpServers": {
|
|
151
|
-
"mongodb": {
|
|
152
|
-
"command": "npx",
|
|
153
|
-
"args": [
|
|
154
|
-
"-y",
|
|
155
|
-
"mcp-mongo-server",
|
|
156
|
-
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
157
|
-
]
|
|
158
|
-
},
|
|
159
|
-
"mongodb-readonly": {
|
|
160
|
-
"command": "npx",
|
|
161
|
-
"args": [
|
|
162
|
-
"-y",
|
|
163
|
-
"mcp-mongo-server",
|
|
164
|
-
"mongodb://muhammed:kilic@localhost:27017/database",
|
|
165
|
-
"--read-only"
|
|
166
|
-
]
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
#### Environment Variables Approach:
|
|
173
|
-
|
|
174
|
-
```json
|
|
175
|
-
{
|
|
176
|
-
"mcpServers": {
|
|
177
|
-
"mongodb": {
|
|
178
|
-
"command": "npx",
|
|
179
|
-
"args": [
|
|
180
|
-
"-y",
|
|
181
|
-
"mcp-mongo-server"
|
|
182
|
-
],
|
|
183
|
-
"env": {
|
|
184
|
-
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database"
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
"mongodb-readonly": {
|
|
188
|
-
"command": "npx",
|
|
189
|
-
"args": [
|
|
190
|
-
"-y",
|
|
191
|
-
"mcp-mongo-server"
|
|
192
|
-
],
|
|
193
|
-
"env": {
|
|
194
|
-
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
|
|
195
|
-
"MCP_MONGODB_READONLY": "true"
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
```
|
|
43
|
+
| Variable | Description |
|
|
44
|
+
|----------|-------------|
|
|
45
|
+
| `MCP_MONGODB_URI` | MongoDB connection URI |
|
|
46
|
+
| `MCP_MONGODB_READONLY` | Enable read-only mode (`"true"`) |
|
|
201
47
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
```json
|
|
205
|
-
{
|
|
206
|
-
"mcpServers": {
|
|
207
|
-
"mongodb": {
|
|
208
|
-
"command": "npx",
|
|
209
|
-
"args": [
|
|
210
|
-
"-y",
|
|
211
|
-
"github:kiliczsh/mcp-mongo-server",
|
|
212
|
-
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
213
|
-
]
|
|
214
|
-
},
|
|
215
|
-
"mongodb-readonly": {
|
|
216
|
-
"command": "npx",
|
|
217
|
-
"args": [
|
|
218
|
-
"-y",
|
|
219
|
-
"github:kiliczsh/mcp-mongo-server",
|
|
220
|
-
"mongodb://muhammed:kilic@localhost:27017/database",
|
|
221
|
-
"--read-only"
|
|
222
|
-
]
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
## Integration with Windsurf and Cursor
|
|
229
|
-
|
|
230
|
-
The MCP MongoDB Server can be used with Windsurf and Cursor in a similar way to Claude Desktop.
|
|
231
|
-
|
|
232
|
-
### Windsurf Configuration
|
|
233
|
-
|
|
234
|
-
Add the server to your Windsurf configuration:
|
|
235
|
-
|
|
236
|
-
```json
|
|
237
|
-
{
|
|
238
|
-
"mcpServers": {
|
|
239
|
-
"mongodb": {
|
|
240
|
-
"command": "npx",
|
|
241
|
-
"args": [
|
|
242
|
-
"-y",
|
|
243
|
-
"mcp-mongo-server",
|
|
244
|
-
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
245
|
-
]
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Cursor Configuration
|
|
252
|
-
|
|
253
|
-
For Cursor, add the server configuration to your settings:
|
|
254
|
-
|
|
255
|
-
```json
|
|
256
|
-
{
|
|
257
|
-
"mcpServers": {
|
|
258
|
-
"mongodb": {
|
|
259
|
-
"command": "npx",
|
|
260
|
-
"args": [
|
|
261
|
-
"-y",
|
|
262
|
-
"mcp-mongo-server",
|
|
263
|
-
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
264
|
-
]
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
You can also use the environment variables approach with both Windsurf and Cursor, following the same pattern shown in the Claude Desktop configuration.
|
|
271
|
-
|
|
272
|
-
### Automated Installation
|
|
273
|
-
|
|
274
|
-
**Using Smithery**:
|
|
275
|
-
```bash
|
|
276
|
-
npx -y @smithery/cli install mcp-mongo-server --client claude
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
**Using mcp-get**:
|
|
280
|
-
```bash
|
|
281
|
-
npx @michaellatman/mcp-get@latest install mcp-mongo-server
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Available Tools
|
|
285
|
-
|
|
286
|
-
### Query Operations
|
|
287
|
-
|
|
288
|
-
- **query**: Execute MongoDB queries
|
|
289
|
-
```javascript
|
|
290
|
-
{
|
|
291
|
-
collection: "users",
|
|
292
|
-
filter: { age: { $gt: 30 } },
|
|
293
|
-
projection: { name: 1, email: 1 },
|
|
294
|
-
limit: 20,
|
|
295
|
-
explain: "executionStats" // Optional
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
- **aggregate**: Run aggregation pipelines
|
|
300
|
-
```javascript
|
|
301
|
-
{
|
|
302
|
-
collection: "orders",
|
|
303
|
-
pipeline: [
|
|
304
|
-
{ $match: { status: "completed" } },
|
|
305
|
-
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } }
|
|
306
|
-
],
|
|
307
|
-
explain: "queryPlanner" // Optional
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
- **count**: Count matching documents
|
|
312
|
-
```javascript
|
|
313
|
-
{
|
|
314
|
-
collection: "products",
|
|
315
|
-
query: { category: "electronics" }
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
### Write Operations
|
|
320
|
-
|
|
321
|
-
- **update**: Modify documents
|
|
322
|
-
```javascript
|
|
323
|
-
{
|
|
324
|
-
collection: "posts",
|
|
325
|
-
filter: { _id: "60d21b4667d0d8992e610c85" },
|
|
326
|
-
update: { $set: { title: "Updated Title" } },
|
|
327
|
-
upsert: false,
|
|
328
|
-
multi: false
|
|
329
|
-
}
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
- **insert**: Add new documents
|
|
333
|
-
```javascript
|
|
334
|
-
{
|
|
335
|
-
collection: "comments",
|
|
336
|
-
documents: [
|
|
337
|
-
{ author: "user123", text: "Great post!" },
|
|
338
|
-
{ author: "user456", text: "Thanks for sharing" }
|
|
339
|
-
]
|
|
340
|
-
}
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
- **createIndex**: Create collection indexes
|
|
344
|
-
```javascript
|
|
345
|
-
{
|
|
346
|
-
collection: "users",
|
|
347
|
-
indexes: [
|
|
348
|
-
{
|
|
349
|
-
key: { email: 1 },
|
|
350
|
-
unique: true,
|
|
351
|
-
name: "email_unique_idx"
|
|
352
|
-
}
|
|
353
|
-
]
|
|
354
|
-
}
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
### System Operations
|
|
358
|
-
|
|
359
|
-
- **serverInfo**: Get MongoDB server details
|
|
360
|
-
```javascript
|
|
361
|
-
{
|
|
362
|
-
includeDebugInfo: true // Optional
|
|
363
|
-
}
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
## Debugging
|
|
367
|
-
|
|
368
|
-
Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
|
|
369
|
-
|
|
370
|
-
```bash
|
|
371
|
-
npm run inspector
|
|
372
|
-
```
|
|
48
|
+
## Documentation
|
|
373
49
|
|
|
374
|
-
|
|
50
|
+
- [Integration Guide](docs/integration.md) - Claude Desktop, Windsurf, Cursor, Docker
|
|
51
|
+
- [Available Tools](docs/tools.md) - Query, aggregate, update, insert, and more
|
|
52
|
+
- [Development](docs/development.md) - Setup, scripts, and debugging
|
|
53
|
+
- [Contributing](CONTRIBUTING.md)
|
|
375
54
|
|
|
376
55
|
## License
|
|
377
56
|
|
|
378
|
-
|
|
57
|
+
MIT - see [LICENSE](LICENSE) for details.
|