{"id":"02444ea3-6242-47c2-83cd-52d77f821926","slug":"az-coder-123-mongodb-mcp","kind":"mcp","name":"mongodb-mcp","summary":"Professional MongoDB MCP Server. Empowers LLMs with intelligent document management, complex aggregation pipeline construction, and collection analysis. Built for secure, AI-driven NoSQL development w","owner":"az-coder-123","repoUrl":"https://github.com/az-coder-123/mongodb-mcp","license":"MIT","licenseTier":"permissive","trust":"community","stars":4,"match":null,"fewStars":true,"format":"mcp","createdAt":null,"addedAt":"2026-10-14T05:29:27.558Z","logoUrl":"https://avatars.githubusercontent.com/u/226820260?u=7d50c7c04a51a1e217413d07ae0ad531a92e9afd&v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["databases","files-documents","cloud-infra"],"tags":["ai-agent","database-tools","llm","mongodb","nosql","typescript"],"runtime":"node","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-14T10:19:08.052Z","sample":false,"url":"https://conduits.dev/tools/az-coder-123-mongodb-mcp","language":"TypeScript","transports":["stdio"],"install":{"npm":"mongodb-mcp"},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"# MongoDB MCP Server\n\nA Model Context Protocol (MCP) server for MongoDB operations, enabling AI assistants to interact with MongoDB databases through a standardized interface.\n\n## Features\n\n### Core Operations\n- **Database Operations**: List, stats, drop databases\n- **Collection Operations**: Create, drop, rename, list collections\n- **Document Operations**: Full CRUD (find, insert, update, delete), aggregation\n- **Index Operations**: Create, list, drop indexes\n\n### Security & Access Control\n- **Permission System**: Role-based access control with allowed/denied databases and collections\n- **Read-Only Mode**: Prevent all write operations\n- **Query Result Limits**: Configurable maximum results per query\n- **Bulk Operation Limits**: Control maximum bulk operations\n\n### Monitoring & Auditing\n- **Audit Logging**: Track all operations with timestamps, success/failure status\n- **Rate Limiting**: Prevent abuse with configurable request limits\n- **Health Check**: Monitor MongoDB connection and server status\n\n### Data Protection\n- **Data Masking**: Automatically mask sensitive fields (passwords, tokens, etc.)\n- **Confirmation Prompts**: Require confirmation for dangerous operations (drop database/collection)\n\n### Configuration\n- **Configuration File**: Support for JSON configuration files\n- **Environment Variables**: All settings configurable via environment variables\n- **Connection Pooling**: MongoDB driver connection pooling\n\n## Installation\n\n```bash\nnpm install mongodb-mcp\n```\n\nOr from source:\n\n```bash\ngit clone https://github.com/az-coder-123/mongodb-mcp.git\ncd mongodb-mcp\nnpm install\nnpm run build\n```\n\n## Configuration\n\n### Configuration File\n\nCreate a `mcp-settings.json` file in your project root or home directory:\n\n```json\n{\n  \"connectionString\": \"mongodb://localhost:27017\",\n  \"permissions\": {\n    \"readOnly\": false,\n    \"allowedDatabases\": [\"myapp\", \"analytics\"],\n    \"deniedDatabases\": [\"admin\", \"config\"],\n    \"allowedCollections\": {\n      \"myapp\": [\"users\", \"orders\", \"products\"]\n    },\n    \"deniedTools\": [\"drop_database\"],\n    \"maxQueryResults\": 1000,\n    \"maxBulkOperations\": 1000\n  },\n  \"auditLog\": {\n    \"enabled\": true,\n    \"logFilePath\": \"./logs/audit.log\",\n    \"maxEntries\": 10000,\n    \"logSuccess\": true,\n    \"logFailure\": true\n  },\n  \"rateLimit\": {\n    \"enabled\": true,\n    \"maxRequests\": 100,\n    \"windowMs\": 60000\n  },\n  \"dataMasking\": true,\n  \"maskedFields\": [\"password\", \"secret\", \"token\", \"apiKey\"]\n}\n```\n\n### Environment Variables\n\n| Variable | Description | Default |\n|----------|-------------|---------|\n| `MONGODB_URI` | MongoDB connection string | `mongodb://localhost:27017` |\n| `MCP_READ_ONLY` | Enable read-only mode | `false` |\n| `MCP_ALLOWED_DATABASES` | Comma-separated list of allowed databases | (all allowed) |\n| `MCP_DENIED_DATABASES` | Comma-separated list of denied databases | (none) |\n| `MCP_DENIED_TOOLS` | Comma-separated list of denied tools | (none) |\n| `MCP_MAX_QUERY_RESULTS` | Maximum query results | `1000` |\n| `MCP_MAX_BULK_OPERATIONS` | Maximum bulk operations | `1000` |\n| `MCP_AUDIT_LOG_ENABLED` | Enable audit logging | `true` |\n| `MCP_AUDIT_LOG_PATH` | Audit log file path | (console only) |\n| `MCP_RATE_LIMIT_ENABLED` | Enable rate limiting | `true` |\n| `MCP_RATE_LIMIT_MAX_REQUESTS` | Max requests per window | `100` |\n| `MCP_RATE_LIMIT_WINDOW_MS` | Rate limit window (ms) | `60000` |\n| `MCP_DATA_MASKING_ENABLED` | Enable data masking | `true` |\n| `MCP_MASKED_FIELDS` | Comma-separated masked fields | `password,secret,token,apiKey` |\n\n## Usage with Claude Desktop\n\nAdd to your Claude Desktop configuration:\n\n**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`\n**Windows**: `%APPDATA%\\Claude\\claude_desktop_config.json`\n\n```json\n{\n  \"mcpServers\": {\n    \"mongodb\": {\n      \"command\": \"node\",\n      \"args\": [\"/path/to/mongodb-mcp/dist/index.js\"],\n      \"env\": {\n        \"MONGODB_URI\": \"mongodb://localhost:27017\"\n      }\n    }\n  }\n}\n```\n\n## Available Tools\n\n### Database Operations\n\n#### list_databases\nList all databases in the MongoDB instance.\n\n```json\n{}\n```\n\n#### database_stats\nGet statistics for a specific database.\n\n```json\n{\n  \"database\": \"mydb\"\n}\n```\n\n#### drop_database\n⚠️ Drop a database (requires confirmation).\n\n```json\n{\n  \"database\": \"test_db\",\n  \"confirm\": true\n}\n```\n\n### Collection Operations\n\n#### list_collections\nList all collections in a database.\n\n```json\n{\n  \"database\": \"mydb\"\n}\n```\n\n#### create_collection\nCreate a new collection.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"options\": {\n    \"capped\": true,\n    \"size\": 1048576,\n    \"max\": 1000\n  }\n}\n```\n\n#### drop_collection\n⚠️ Drop a collection (requires confirmation).\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"temp_data\",\n  \"confirm\": true\n}\n```\n\n### Document Operations\n\n#### find\nFind documents with filters, projections, sorting, and pagination.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"filter\": { \"age\": { \"$gte\": 18 } },\n  \"projection\": { \"name\": 1, \"email\": 1 },\n  \"sort\": { \"name\": 1 },\n  \"limit\": 10,\n  \"skip\": 0\n}\n```\n\n#### insert_one\nInsert a single document.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"document\": {\n    \"name\": \"John Doe\",\n    \"email\": \"john@example.com\",\n    \"age\": 30\n  }\n}\n```\n\n#### insert_many\nInsert multiple documents.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"documents\": [\n    { \"name\": \"User 1\", \"email\": \"user1@example.com\" },\n    { \"name\": \"User 2\", \"email\": \"user2@example.com\" }\n  ]\n}\n```\n\n#### update_one\nUpdate a single document.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"filter\": { \"email\": \"john@example.com\" },\n  \"update\": { \"$set\": { \"age\": 31 } },\n  \"upsert\": false\n}\n```\n\n#### delete_one\nDelete a single document.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"filter\": { \"email\": \"john@example.com\" }\n}\n```\n\n#### aggregate\nRun an aggregation pipeline.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"orders\",\n  \"pipeline\": [\n    { \"$match\": { \"status\": \"completed\" } },\n    { \"$group\": { \"_id\": \"$customerId\", \"total\": { \"$sum\": \"$amount\" } } },\n    { \"$sort\": { \"total\": -1 } },\n    { \"$limit\": 10 }\n  ]\n}\n```\n\n### Index Operations\n\n#### create_index\nCreate an index on a collection.\n\n```json\n{\n  \"database\": \"mydb\",\n  \"collection\": \"users\",\n  \"keys\": { \"email\": 1 },\n  \"options\": {\n    \"unique\": true,\n    \"name\": \"email_unique_idx\"\n  }\n}\n```\n\n### Monitoring Tools\n\n#### health_check\nCheck MongoDB connection health and server status.\n\n```json\n{}\n```\n\n#### get_audit_log\nGet audit log entries.\n\n```json\n{\n  \"limit\": 100,\n  \"toolName\": \"insert_one\",\n  \"failuresOnly\": false\n}\n```\n\n#### get_server_config\nGet current server configuration.\n\n```json\n{}\n```\n\n#### set_read_only\nEnable or disable read-only mode.\n\n```json\n{\n  \"enabled\": true\n}\n```\n\n## Security Features\n\n### Permission System\n\nControl access to databases and collections:\n\n```json\n{\n  \"permissions\": {\n    \"allowedDatabases\": [\"myapp\"],\n    \"deniedDatabases\": [\"admin\"],\n    \"allowedCollections\": {\n      \"myapp\": [\"users\", \"orders\"]\n    },\n    \"deniedTools\": [\"drop_database\", \"drop_collection\"]\n  }\n}\n```\n\n### Read-Only Mode\n\nPrevent all write operations:\n\n```bash\nMCP_READ_ONLY=true node dist/index.js\n```\n\nOr via tool call:\n\n```json\n{\n  \"name\": \"set_read_only\",\n  \"arguments\": { \"enabled\": true }\n}\n```\n\n### Confirmation Prompts\n\nDangerous operations require explicit confirmation:\n\n- `drop_database` requires `\"confirm\": true`\n- `drop_collection` requires `\"confirm\": true`\n\n### Data Masking\n\nSensitive fields are automatically masked in responses:\n\n```json\n{\n  \"dataMasking\": true,\n  \"maskedFields\": [\"password\", \"secret\", \"token\", \"apiKey\", \"creditCard\"]\n}\n```\n\n### Rate Limiting\n\nPrevent abuse with configurable limits:\n\n```json\n{\n  \"rateLimit\": {\n    \"enabled\": true,\n    \"maxRequests\": 100,\n    \"windowMs\": 60000\n  }\n}\n```\n\n## Error Handling\n\nThe server implements a comprehensive error handling system with structured error classes, automatic categorization, and actionable recovery suggestions.\n\n### Error Format\n\nThe server returns errors in the following format:\n\n```json\n{\n  \"content\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"VALIDATION_ERROR: Invalid value for 'collection': expected string, got number\\n\\nSuggestions:\\n  1. Check 'collection' parameter\\n  2. Refer to documentation for valid values\\n\\nContext: {\\n  \\\"field\\\": \\\"collection\\\",\\n  \\\"value\\\": 123,\\n  \\\"expectedType\\\": \\\"string\\\"\\n}\"\n    }\n  ],\n  \"isError\": true\n}\n```\n\n### Error Categories\n\nAll errors are categorized for proper handling:\n\n| Category | Description |\n|-----------|-------------|\n| `VALIDATION` | Invalid input parameters |\n| `PERMISSION` | Access denied |\n| `RATE_LIMIT` | Too many requests |\n| `CONNECTION` | MongoDB connection issues |\n| `OPERATION` | Database operation failures |\n| `NOT_FOUND` | Resource not found |\n| `CONFIGURATION` | Invalid configuration |\n\n### Error Types\n\nThe server provides specific error types with recovery suggestions:\n\n- **ValidationError** - Input validation errors\n- **PermissionError** - Access denied errors\n- **RateLimitError** - Rate limit exceeded\n- **ConnectionError** - MongoDB connection failures\n- **OperationError** - Database operation failures\n- **NotFoundError** - Resource not found\n- **ConfigurationError** - Configuration errors\n- **ReadOnlyError** - Read-only mode violations\n- **BulkLimitError** - Bulk operation limits\n- **QueryLimitError** - Query result limits\n- **ConfirmationRequiredError** - Dangerous operations without confirmation\n\n### Documentation\n\nFor comprehensive error handling documentation, see [docs/error-handling.md](docs/error-handling.md).\n\nThis guide includes:\n- Complete error classes reference\n- Error handling utilities\n- Best practices\n- Error recovery patterns\n- Common troubleshooting scenarios\n\n## Development\n\n### Running in development mode\n\n```bash\nnpm run dev\n```\n\nThis will watch for file changes and automatically rebuild.\n\n### Building\n\n```bash\nnpm run build\n```\n\n### Cleaning\n\n```bash\nnpm run clean\n```\n\n## Architecture\n\n```\nsrc/\n├── types/\n│   └── index.ts          # TypeScript interfaces and types\n├── validators/\n│   └── index.ts          # Input validation functions\n├── handlers/\n│   ├── database.ts       # Database operation handlers\n│   ├── collection.ts     # Collection operation handlers\n│   ├── document.ts       # Document CRUD handlers\n│   ├── index-operations.ts # Index operation handlers\n│   └── index.ts          # Handler exports\n├── resources/\n│   └── index.ts          # MCP resource handlers\n├── tools/\n│   └── index.ts          # Tool definitions\n├── utils/\n│   ├── permission-checker.ts  # Permission system\n│   ├── audit-logger.ts        # Audit logging\n│   ├── rate-limiter.ts        # Rate limiting\n│   ├── data-masker.ts         # Data masking\n│   ├── config-loader.ts       # Configuration loading\n│   └── index.ts               # Utility exports\n├── server.ts             # Main server class\n└── index.ts              # Entry point\n```\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request"}