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 CHANGED
@@ -1,147 +1,144 @@
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
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
- The Inspector will provide a URL to access debugging tools in your browser.
128
-
129
- ## Components
130
-
131
-
132
- ### Resources
132
+ ## Integration with Claude Desktop
133
133
 
134
- The server provides schema information for each collection in the database:
134
+ ### Manual Configuration
135
135
 
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
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
- ## Usage with Claude Desktop
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@mongodb.localhost/sample_namespace"
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@mongodb.localhost/sample_namespace",
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-github": {
209
+ "mongodb-readonly": {
167
210
  "command": "npx",
168
211
  "args": [
169
212
  "-y",
170
213
  "github:kiliczsh/mcp-mongo-server",
171
- "mongodb://muhammed:kilic@mongodb.localhost/sample_namespace",
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
- ### Installing via Smithery
222
+ ## Integration with Windsurf and Cursor
180
223
 
181
- To install MCP MongoDB Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/mcp-mongo-server):
224
+ The MCP MongoDB Server can be used with Windsurf and Cursor in a similar way to Claude Desktop.
182
225
 
183
- ```bash
184
- npx -y @smithery/cli install mcp-mongo-server --client claude
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
- ### Installing via mcp-get
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
- You can install this package using mcp-get:
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
- Replace `/sample_namespace` with your database name.
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
- ## Using Read-Only Mode
353
+ - **serverInfo**: Get MongoDB server details
354
+ ```javascript
355
+ {
356
+ includeDebugInfo: true // Optional
357
+ }
358
+ ```
359
+
360
+ ## Debugging
198
361
 
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.
362
+ Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
200
363
 
201
364
  ```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
365
+ npm run inspector
204
366
  ```
205
367
 
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
368
+ This will provide a URL to access the debugging tools in your browser.
211
369
 
212
370
  ## License
213
371