@krazor/mongodb-mcp
v1.0.7
Published
MongoDB MCP server for database operations with secure connection handling
Downloads
790
Maintainers
Readme
@krazor/mongodb-mcp
A secure, production-ready MongoDB MCP (Model Context Protocol) server for database operations.
Features
- 🔒 Secure by default - No hardcoded credentials, environment-based configuration
- 🔄 Connection pooling - Efficient connection management with automatic retry
- 💪 Resilient - Handles connection drops, automatic reconnection
- 📦 Production-ready - Graceful shutdown, error handling, logging
- 🛠️ Full CRUD support - All MongoDB operations available as MCP tools
Installation
npm install -g @krazor/mongodb-mcpOr use with npx:
npx @krazor/mongodb-mcpConfiguration
Environment Variables
| Variable | Required | Description |
|----------|----------|-------------|
| MONGODB_URI | Yes | MongoDB connection string |
| MONGODB_DB_NAME | No | Default database name |
| MONGODB_OPTIONS | No | JSON string of MongoDB options |
Example Connection URIs
Local MongoDB:
export MONGODB_URI="mongodb://localhost:27017/myapp"MongoDB Atlas:
export MONGODB_URI="mongodb+srv://username:[email protected]/myapp"With Connection Pool Options:
export MONGODB_URI="mongodb://localhost:27017/myapp?maxPoolSize=50&minPoolSize=10"Usage with McpMux
- Install the server in McpMux
- Configure with your MongoDB URI
- Start using MongoDB tools!
Available Tools
Query Operations
find_documents- Find multiple documents with filtering, sorting, paginationfind_one- Find a single documentcount_documents- Count documents matching a filteraggregate- Run aggregation pipelines
Write Operations
insert_one- Insert a single documentinsert_many- Insert multiple documentsupdate_one- Update a single documentupdate_many- Update multiple documentsdelete_one- Delete a single documentdelete_many- Delete multiple documents
Schema Operations
list_collections- List all collections in a databaselist_databases- List all databasescreate_index- Create an index on a collectiondrop_collection- Drop a collection
Connection Options
Default connection settings (can be overridden with MONGODB_OPTIONS):
{
"maxPoolSize": 50,
"minPoolSize": 5,
"serverSelectionTimeoutMS": 30000,
"socketTimeoutMS": 0,
"connectTimeoutMS": 30000,
"keepAlive": true,
"heartbeatFrequencyMS": 10000,
"retryWrites": true,
"retryReads": true
}Override with:
export MONGODB_OPTIONS='{"maxPoolSize":100,"minPoolSize":10}'Security
⚠️ IMPORTANT:
- Never commit your
.envfile - Never hardcode credentials in your code
- The server redacts credentials from all logs
- Credentials are never exposed in error messages
Troubleshooting
"Transport closed" errors
- Check your MongoDB connection string
- Ensure MongoDB is running and accessible
- Verify network connectivity
- Check firewall settings
Connection timeouts
- Increase
serverSelectionTimeoutMS - Check MongoDB server load
- Verify connection pool settings
License
MIT © krazor
