mcp-mongo-server 1.1.2 → 1.3.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 CHANGED
@@ -1,147 +1,149 @@
1
1
  # MCP MongoDB Server
2
2
  ---
3
+
3
4
  ![NPM Version](https://img.shields.io/npm/v/mcp-mongo-server)
4
5
  ![NPM Downloads](https://img.shields.io/npm/dm/mcp-mongo-server)
5
6
  ![NPM License](https://img.shields.io/npm/l/mcp-mongo-server)
6
7
  [![smithery badge](https://smithery.ai/badge/mcp-mongo-server)](https://smithery.ai/server/mcp-mongo-server)
7
8
 
8
- A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute MongoDB operations.
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
  [![MCP MongoDB Server Demo | Claude Desktop](https://img.youtube.com/vi/FI-oE_voCpA/0.jpg)](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
- - Connect to MongoDB in read-only mode with `--read-only` or `-r` flag
18
- - Prevents write operations (update, insert, createIndex)
19
- - Uses MongoDB's secondary read preference for optimal read performance
20
- - Provides additional safety for production database connections
21
-
22
- ### Resources
23
- - List and access collections via `mongodb://` URIs
24
- - Each collection has a name, description and schema
25
- - JSON mime type for schema access
26
-
27
- ### Tools
28
- - **query**
29
- - Execute MongoDB queries with optional execution plan analysis
30
- - Input: Collection name, filter, projection, limit, explain options
31
- - Returns query results or execution plan
32
-
33
- - **aggregate**
34
- - Execute MongoDB aggregation pipelines with optional execution plan analysis
35
- - Input: Collection name, pipeline stages, explain options
36
- - Returns aggregation results or execution plan
37
-
38
- - **update**
39
- - Update documents in a collection
40
- - Input: Collection name, filter, update operations, upsert/multi options
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
- Build the server:
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
- For development with auto-rebuild:
77
+ ## Usage
78
+
79
+ ### Basic Usage
80
+
82
81
  ```bash
83
- npm run watch
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
- ## Installation for Development
89
+ ### Environment Variables
87
90
 
88
- ### Using Claude Desktop
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
- To use with Claude Desktop, add the server config:
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
- On MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
100
+ # Run server (will use environment variables if no URI is provided)
101
+ npx -y mcp-mongo-server
102
+ ```
93
103
 
94
- On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
104
+ Using environment variables in Claude Desktop configuration:
95
105
 
96
106
  ```json
97
107
  {
98
108
  "mcpServers": {
99
- "mongodb": {
100
- "command": "node",
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
- "~/mcp-mongo-server/build/index.js",
110
- "mongodb://muhammed:kilic@mongodb.localhost/namespace",
111
- "--read-only"
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
- npm run inspector
125
- ```
126
-
127
- The Inspector will provide a URL to access debugging tools in your browser.
127
+ # Build
128
+ docker build -t mcp-mongo-server .
128
129
 
129
- ## Components
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
130
132
 
133
+ # or edit docker-compose.yml and run
134
+ docker-compose up -d
135
+ ```
131
136
 
132
- ### Resources
133
-
134
- The server provides schema information for each collection in the database:
137
+ ## Integration with Claude Desktop
135
138
 
136
- - **Collection Schemas** (`mongodb://<host>/<collection>/schema`)
137
- - JSON schema information for each collection
138
- - Includes field names and data types
139
- - Automatically inferred from collection documents
139
+ ### Manual Configuration
140
140
 
141
+ Add the server configuration to Claude Desktop's config file:
141
142
 
142
- ## Usage with Claude Desktop
143
+ **MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
144
+ **Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
143
145
 
144
- To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your `claude_desktop_config.json`:
146
+ #### Command-line Arguments Approach:
145
147
 
146
148
  ```json
147
149
  {
@@ -151,7 +153,7 @@ To use this server with the Claude Desktop app, add the following configuration
151
153
  "args": [
152
154
  "-y",
153
155
  "mcp-mongo-server",
154
- "mongodb://muhammed:kilic@mongodb.localhost/sample_namespace"
156
+ "mongodb://muhammed:kilic@localhost:27017/database"
155
157
  ]
156
158
  },
157
159
  "mongodb-readonly": {
@@ -159,16 +161,63 @@ To use this server with the Claude Desktop app, add the following configuration
159
161
  "args": [
160
162
  "-y",
161
163
  "mcp-mongo-server",
162
- "mongodb://muhammed:kilic@mongodb.localhost/sample_namespace",
164
+ "mongodb://muhammed:kilic@localhost:27017/database",
163
165
  "--read-only"
164
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
+ }
165
186
  },
166
- "mongodb-github": {
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
+ ```
201
+
202
+ ### GitHub Package Usage:
203
+
204
+ ```json
205
+ {
206
+ "mcpServers": {
207
+ "mongodb": {
167
208
  "command": "npx",
168
209
  "args": [
169
210
  "-y",
170
211
  "github:kiliczsh/mcp-mongo-server",
171
- "mongodb://muhammed:kilic@mongodb.localhost/sample_namespace",
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",
172
221
  "--read-only"
173
222
  ]
174
223
  }
@@ -176,38 +225,153 @@ To use this server with the Claude Desktop app, add the following configuration
176
225
  }
177
226
  ```
178
227
 
179
- ### Installing via Smithery
228
+ ## Integration with Windsurf and Cursor
180
229
 
181
- To install MCP MongoDB Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/mcp-mongo-server):
230
+ The MCP MongoDB Server can be used with Windsurf and Cursor in a similar way to Claude Desktop.
182
231
 
183
- ```bash
184
- npx -y @smithery/cli install mcp-mongo-server --client claude
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
+ }
185
268
  ```
186
269
 
187
- ### Installing via mcp-get
270
+ You can also use the environment variables approach with both Windsurf and Cursor, following the same pattern shown in the Claude Desktop configuration.
188
271
 
189
- You can install this package using mcp-get:
272
+ ### Automated Installation
190
273
 
274
+ **Using Smithery**:
275
+ ```bash
276
+ npx -y @smithery/cli install mcp-mongo-server --client claude
277
+ ```
278
+
279
+ **Using mcp-get**:
191
280
  ```bash
192
281
  npx @michaellatman/mcp-get@latest install mcp-mongo-server
193
282
  ```
194
283
 
195
- Replace `/sample_namespace` with your database name.
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
196
358
 
197
- ## Using Read-Only Mode
359
+ - **serverInfo**: Get MongoDB server details
360
+ ```javascript
361
+ {
362
+ includeDebugInfo: true // Optional
363
+ }
364
+ ```
365
+
366
+ ## Debugging
198
367
 
199
- You can connect to MongoDB in read-only mode by adding the `--read-only` or `-r` flag when starting the server. This is recommended when you need to protect your data from accidental writes or when connecting to production databases.
368
+ Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
200
369
 
201
370
  ```bash
202
- # Connect in read-only mode using the command line
203
- npx mcp-mongo-server mongodb://user:password@mongodb.example.com/database --read-only
371
+ npm run inspector
204
372
  ```
205
373
 
206
- When in read-only mode:
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
374
+ This will provide a URL to access the debugging tools in your browser.
211
375
 
212
376
  ## License
213
377