mcp-mongo-server 1.1.1 → 1.2.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 +276 -118
- package/build/index.js +44 -1023
- package/build/mongo.js +33 -0
- package/build/schemas/call.js +507 -0
- package/build/schemas/completion.js +112 -0
- package/build/schemas/ping.js +20 -0
- package/build/schemas/prompts.js +71 -0
- package/build/schemas/resource.js +62 -0
- package/build/schemas/templates.js +33 -0
- package/build/schemas/tools.js +278 -0
- package/build/server.js +65 -0
- package/package.json +1 -1
- package/build/types.js +0 -169
package/README.md
CHANGED
|
@@ -1,147 +1,144 @@
|
|
|
1
1
|
# MCP MongoDB Server
|
|
2
2
|
---
|
|
3
|
+
|
|
3
4
|

|
|
4
5
|

|
|
5
6
|

|
|
6
7
|
[](https://smithery.ai/server/mcp-mongo-server)
|
|
7
8
|
|
|
8
|
-
A Model Context Protocol server that
|
|
9
|
+
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.
|
|
9
10
|
|
|
10
11
|
## Demo
|
|
11
12
|
|
|
12
13
|
[](https://www.youtube.com/watch?v=FI-oE_voCpA)
|
|
13
14
|
|
|
14
|
-
## Features
|
|
15
|
+
## Key Features
|
|
16
|
+
|
|
17
|
+
### Smart ObjectId Handling
|
|
18
|
+
- Intelligent conversion between string IDs and MongoDB ObjectId
|
|
19
|
+
- Configurable with `objectIdMode` parameter:
|
|
20
|
+
- `"auto"`: Convert based on field names (default)
|
|
21
|
+
- `"none"`: No conversion
|
|
22
|
+
- `"force"`: Force all string ID fields to ObjectId
|
|
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
|
|
15
30
|
|
|
16
31
|
### Read-Only Mode
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- Returns update operation results
|
|
42
|
-
|
|
43
|
-
- **serverInfo**
|
|
44
|
-
- Get MongoDB server information and status
|
|
45
|
-
- Input: Optional debug info flag
|
|
46
|
-
- Returns version, storage engine, and server details
|
|
47
|
-
|
|
48
|
-
- **insert**
|
|
49
|
-
- Insert documents into a collection
|
|
50
|
-
- Input: Collection name, documents array, write options
|
|
51
|
-
- Returns insert operation results
|
|
52
|
-
|
|
53
|
-
- **createIndex**
|
|
54
|
-
- Create indexes on a collection
|
|
55
|
-
- Input: Collection name, index specifications, write options
|
|
56
|
-
- Returns index creation results
|
|
57
|
-
|
|
58
|
-
- **count**
|
|
59
|
-
- Count documents matching a query
|
|
60
|
-
- Input: Collection name, query filter, count options
|
|
61
|
-
- Returns document count
|
|
62
|
-
|
|
63
|
-
### Prompts
|
|
64
|
-
- `analyze_collection` - Analyze collection structure and contents
|
|
65
|
-
- Input: Collection name
|
|
66
|
-
- Output: Insights about schema, data types, and statistics
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## Development
|
|
70
|
-
|
|
71
|
-
Install dependencies:
|
|
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
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
### Global Installation
|
|
55
|
+
|
|
72
56
|
```bash
|
|
73
|
-
npm install
|
|
57
|
+
npm install -g mcp-mongo-server
|
|
74
58
|
```
|
|
75
59
|
|
|
76
|
-
|
|
60
|
+
### For Development
|
|
61
|
+
|
|
77
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
|
|
78
71
|
npm run build
|
|
72
|
+
|
|
73
|
+
# Development with auto-rebuild
|
|
74
|
+
npm run watch
|
|
79
75
|
```
|
|
80
76
|
|
|
81
|
-
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
### Basic Usage
|
|
80
|
+
|
|
82
81
|
```bash
|
|
83
|
-
|
|
82
|
+
# Start server with MongoDB URI
|
|
83
|
+
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database
|
|
84
|
+
|
|
85
|
+
# Connect in read-only mode
|
|
86
|
+
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read-only
|
|
84
87
|
```
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
### Environment Variables
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
You can configure the server using environment variables, which is particularly useful for CI/CD pipelines, Docker containers, or when you don't want to expose connection details in command arguments:
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
```bash
|
|
94
|
+
# Set MongoDB connection URI
|
|
95
|
+
export MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database"
|
|
96
|
+
|
|
97
|
+
# Enable read-only mode
|
|
98
|
+
export MCP_MONGODB_READONLY="true"
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
# Run server (will use environment variables if no URI is provided)
|
|
101
|
+
npx -y mcp-mongo-server
|
|
102
|
+
```
|
|
93
103
|
|
|
94
|
-
|
|
104
|
+
Using environment variables in Claude Desktop configuration:
|
|
95
105
|
|
|
96
106
|
```json
|
|
97
107
|
{
|
|
98
108
|
"mcpServers": {
|
|
99
|
-
"mongodb": {
|
|
100
|
-
"command": "
|
|
101
|
-
"args": [
|
|
102
|
-
"~/mcp-mongo-server/build/index.js",
|
|
103
|
-
"mongodb://muhammed:kilic@mongodb.localhost/namespace"
|
|
104
|
-
]
|
|
105
|
-
},
|
|
106
|
-
"mongodb-readonly": {
|
|
107
|
-
"command": "node",
|
|
109
|
+
"mongodb-env": {
|
|
110
|
+
"command": "npx",
|
|
108
111
|
"args": [
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
}
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
```
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
### Debugging
|
|
120
|
-
|
|
121
|
-
Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector), which is available as a package script:
|
|
124
|
+
Using environment variables with Docker:
|
|
122
125
|
|
|
123
126
|
```bash
|
|
124
|
-
|
|
127
|
+
docker run -e MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" \
|
|
128
|
+
-e MCP_MONGODB_READONLY="true" \
|
|
129
|
+
mcp-mongo-server
|
|
125
130
|
```
|
|
126
131
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
## Components
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
### Resources
|
|
132
|
+
## Integration with Claude Desktop
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
### Manual Configuration
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
- JSON schema information for each collection
|
|
138
|
-
- Includes field names and data types
|
|
139
|
-
- Automatically inferred from collection documents
|
|
136
|
+
Add the server configuration to Claude Desktop's config file:
|
|
140
137
|
|
|
138
|
+
**MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
139
|
+
**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your `claude_desktop_config.json`:
|
|
141
|
+
#### Command-line Arguments Approach:
|
|
145
142
|
|
|
146
143
|
```json
|
|
147
144
|
{
|
|
@@ -151,7 +148,7 @@ To use this server with the Claude Desktop app, add the following configuration
|
|
|
151
148
|
"args": [
|
|
152
149
|
"-y",
|
|
153
150
|
"mcp-mongo-server",
|
|
154
|
-
"mongodb://muhammed:kilic@
|
|
151
|
+
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
155
152
|
]
|
|
156
153
|
},
|
|
157
154
|
"mongodb-readonly": {
|
|
@@ -159,16 +156,62 @@ To use this server with the Claude Desktop app, add the following configuration
|
|
|
159
156
|
"args": [
|
|
160
157
|
"-y",
|
|
161
158
|
"mcp-mongo-server",
|
|
162
|
-
"mongodb://muhammed:kilic@
|
|
159
|
+
"mongodb://muhammed:kilic@localhost:27017/database",
|
|
163
160
|
"--read-only"
|
|
164
161
|
]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Environment Variables Approach:
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"mcpServers": {
|
|
172
|
+
"mongodb": {
|
|
173
|
+
"command": "npx",
|
|
174
|
+
"args": [
|
|
175
|
+
"-y",
|
|
176
|
+
"mcp-mongo-server"
|
|
177
|
+
],
|
|
178
|
+
"env": {
|
|
179
|
+
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"mongodb-readonly": {
|
|
183
|
+
"command": "npx",
|
|
184
|
+
"args": [
|
|
185
|
+
"-y",
|
|
186
|
+
"mcp-mongo-server"
|
|
187
|
+
],
|
|
188
|
+
"env": {
|
|
189
|
+
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
|
|
190
|
+
"MCP_MONGODB_READONLY": "true"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
### GitHub Package Usage:
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"mcpServers": {
|
|
201
|
+
"mongodb": {
|
|
202
|
+
"command": "npx",
|
|
203
|
+
"args": [
|
|
204
|
+
"-y",
|
|
205
|
+
"github:kiliczsh/mcp-mongo-server",
|
|
206
|
+
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
207
|
+
]
|
|
165
208
|
},
|
|
166
|
-
"mongodb-
|
|
209
|
+
"mongodb-readonly": {
|
|
167
210
|
"command": "npx",
|
|
168
211
|
"args": [
|
|
169
212
|
"-y",
|
|
170
213
|
"github:kiliczsh/mcp-mongo-server",
|
|
171
|
-
"mongodb://muhammed:kilic@
|
|
214
|
+
"mongodb://muhammed:kilic@localhost:27017/database",
|
|
172
215
|
"--read-only"
|
|
173
216
|
]
|
|
174
217
|
}
|
|
@@ -176,38 +219,153 @@ To use this server with the Claude Desktop app, add the following configuration
|
|
|
176
219
|
}
|
|
177
220
|
```
|
|
178
221
|
|
|
179
|
-
|
|
222
|
+
## Integration with Windsurf and Cursor
|
|
180
223
|
|
|
181
|
-
|
|
224
|
+
The MCP MongoDB Server can be used with Windsurf and Cursor in a similar way to Claude Desktop.
|
|
182
225
|
|
|
183
|
-
|
|
184
|
-
|
|
226
|
+
### Windsurf Configuration
|
|
227
|
+
|
|
228
|
+
Add the server to your Windsurf configuration:
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"mcpServers": {
|
|
233
|
+
"mongodb": {
|
|
234
|
+
"command": "npx",
|
|
235
|
+
"args": [
|
|
236
|
+
"-y",
|
|
237
|
+
"mcp-mongo-server",
|
|
238
|
+
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Cursor Configuration
|
|
246
|
+
|
|
247
|
+
For Cursor, add the server configuration to your settings:
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"mcpServers": {
|
|
252
|
+
"mongodb": {
|
|
253
|
+
"command": "npx",
|
|
254
|
+
"args": [
|
|
255
|
+
"-y",
|
|
256
|
+
"mcp-mongo-server",
|
|
257
|
+
"mongodb://muhammed:kilic@localhost:27017/database"
|
|
258
|
+
]
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
185
262
|
```
|
|
186
263
|
|
|
187
|
-
|
|
264
|
+
You can also use the environment variables approach with both Windsurf and Cursor, following the same pattern shown in the Claude Desktop configuration.
|
|
188
265
|
|
|
189
|
-
|
|
266
|
+
### Automated Installation
|
|
190
267
|
|
|
268
|
+
**Using Smithery**:
|
|
269
|
+
```bash
|
|
270
|
+
npx -y @smithery/cli install mcp-mongo-server --client claude
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Using mcp-get**:
|
|
191
274
|
```bash
|
|
192
275
|
npx @michaellatman/mcp-get@latest install mcp-mongo-server
|
|
193
276
|
```
|
|
194
277
|
|
|
195
|
-
|
|
278
|
+
## Available Tools
|
|
279
|
+
|
|
280
|
+
### Query Operations
|
|
281
|
+
|
|
282
|
+
- **query**: Execute MongoDB queries
|
|
283
|
+
```javascript
|
|
284
|
+
{
|
|
285
|
+
collection: "users",
|
|
286
|
+
filter: { age: { $gt: 30 } },
|
|
287
|
+
projection: { name: 1, email: 1 },
|
|
288
|
+
limit: 20,
|
|
289
|
+
explain: "executionStats" // Optional
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
- **aggregate**: Run aggregation pipelines
|
|
294
|
+
```javascript
|
|
295
|
+
{
|
|
296
|
+
collection: "orders",
|
|
297
|
+
pipeline: [
|
|
298
|
+
{ $match: { status: "completed" } },
|
|
299
|
+
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } }
|
|
300
|
+
],
|
|
301
|
+
explain: "queryPlanner" // Optional
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
- **count**: Count matching documents
|
|
306
|
+
```javascript
|
|
307
|
+
{
|
|
308
|
+
collection: "products",
|
|
309
|
+
query: { category: "electronics" }
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Write Operations
|
|
314
|
+
|
|
315
|
+
- **update**: Modify documents
|
|
316
|
+
```javascript
|
|
317
|
+
{
|
|
318
|
+
collection: "posts",
|
|
319
|
+
filter: { _id: "60d21b4667d0d8992e610c85" },
|
|
320
|
+
update: { $set: { title: "Updated Title" } },
|
|
321
|
+
upsert: false,
|
|
322
|
+
multi: false
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
- **insert**: Add new documents
|
|
327
|
+
```javascript
|
|
328
|
+
{
|
|
329
|
+
collection: "comments",
|
|
330
|
+
documents: [
|
|
331
|
+
{ author: "user123", text: "Great post!" },
|
|
332
|
+
{ author: "user456", text: "Thanks for sharing" }
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
- **createIndex**: Create collection indexes
|
|
338
|
+
```javascript
|
|
339
|
+
{
|
|
340
|
+
collection: "users",
|
|
341
|
+
indexes: [
|
|
342
|
+
{
|
|
343
|
+
key: { email: 1 },
|
|
344
|
+
unique: true,
|
|
345
|
+
name: "email_unique_idx"
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### System Operations
|
|
196
352
|
|
|
197
|
-
|
|
353
|
+
- **serverInfo**: Get MongoDB server details
|
|
354
|
+
```javascript
|
|
355
|
+
{
|
|
356
|
+
includeDebugInfo: true // Optional
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Debugging
|
|
198
361
|
|
|
199
|
-
|
|
362
|
+
Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
|
|
200
363
|
|
|
201
364
|
```bash
|
|
202
|
-
|
|
203
|
-
npx mcp-mongo-server mongodb://user:password@mongodb.example.com/database --read-only
|
|
365
|
+
npm run inspector
|
|
204
366
|
```
|
|
205
367
|
|
|
206
|
-
|
|
207
|
-
1. All write operations (update, insert, createIndex) will be blocked
|
|
208
|
-
2. The server connects using MongoDB's secondary read preference
|
|
209
|
-
3. The connection status indicates read-only mode is active
|
|
210
|
-
4. The `ping` and `serverInfo` responses include read-only status information
|
|
368
|
+
This will provide a URL to access the debugging tools in your browser.
|
|
211
369
|
|
|
212
370
|
## License
|
|
213
371
|
|