MongoDB That Works

by sourabhfb

Not rated
GitHub

About

A MongoDB MCP server with schema discovery and field validation. Requires a MONGODB_URI environment variable.

Details

Author
sourabhfb
Categories
Database, Other

Setup

Install MongoDB That Works in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/sourabhfb/mongodb-mcp-that-works

Follow the installation instructions in the repository README, then restart your MCP client.

A reliable MongoDB MCP (Model Context Protocol) server that provides seamless MongoDB integration for Claude Desktop with built-in schema discovery and field validation.

- πŸ”Schema Discovery: Automatically analyze collection structures
- βœ…Field Validation: Prevent field name mistakes
- πŸ“ŠFull MongoDB Support: Find, aggregate, insert, update, delete operations
- πŸš€High Performance: Efficient connection pooling and query optimization
- πŸ”Secure: Support for MongoDB Atlas and authentication
- 🎯Type-Safe: Built with TypeScript and Zod validation

npm install -g @sourabhshegane/mongodb-mcp-that-works

Add to your Claude Desktop configuration file:

macOS:~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:%APPDATA%\Claude\claude_desktop_config.json

{ "mcpServers": { "mongodb": { "command": "npx", "args": ["-y", "@sourabhshegane/mongodb-mcp-that-works@latest"], "env": { "MONGODB_URI": "mongodb+srv://username:password@cluster.mongodb.net/database", "MONGODB_DATABASE": "your_database_name" } } } }

- MONGODB_URI: Your MongoDB connection string (required)
- MONGODB_DATABASE: Default database name (optional)

// Example mcp.listCollections({ filter: {} })

Find documents in a collection with filtering, sorting, and pagination.

// Example mcp.find({ collection: "users", filter: { status: "active" }, sort: { createdAt: -1 }, limit: 10 })
// Example mcp.findOne({ collection: "users", filter: { email: "user@example.com" } })
// Example mcp.aggregate({ collection: "orders", pipeline: [ { $match: { status: "completed" } }, { $group: { _id: "$userId", total: { $sum: "$amount" } } } ] })
// Example mcp.count({ collection: "products", filter: { inStock: true } })
// Example mcp.distinct({ collection: "orders", field: "status" })
// Example mcp.insertOne({ collection: "users", document: { name: "John Doe", email: "john@example.com" } })
// Example mcp.updateOne({ collection: "users", filter: { _id: "123" }, update: { $set: { status: "active" } } })
// Example mcp.deleteOne({ collection: "users", filter: { _id: "123" } })

Analyze collection structure and discover field names.

// Example mcp.getSchema({ collection: "users", sampleSize: 100 }) // Returns: { "collection": "users", "sampleSize": 100, "fields": { "_id": { "types": ["ObjectId"], "examples": ["507f1f77bcf86cd799439011"], "frequency": "100/100", "percentage": 100 }, "email": { "types": ["string"], "examples": ["user@example.com"], "frequency": "100/100", "percentage": 100 } } }

- Use Schema Discovery First: Before querying, rungetSchemato understand field names
- Handle ObjectIds: The server automatically converts string IDs to ObjectIds
- Use Projections: Limit returned fields to improve performance
- Batch Operations: Use aggregation pipelines for complex queries

// Get schema first to avoid field name mistakes const schema = await mcp.getSchema({ collection: "reports" }); // Use correct field names from schema const reports = await mcp.find({ collection: "reports", filter: { organization_id: "64ba7374f8b63db2083b2665" }, limit: 10 });
const analytics = await mcp.aggregate({ collection: "orders", pipeline: [ { $match: { createdAt: { $gte: new Date("2024-01-01") } } }, { $group: { _id: { $dateToString: { format: "%Y-%m", date: "$createdAt" } }, revenue: { $sum: "$amount" }, count: { $sum: 1 } }}, { $sort: { _id: 1 } } ] });

- Verify your MongoDB URI is correct
- Check network connectivity to MongoDB Atlas
- Ensure IP whitelist includes your current IP

- Always usegetSchemato discover correct field names
- Remember MongoDB is case-sensitive
- Check for typos in nested field paths (e.g., "user.profile.name")

- Use indexes for frequently queried fields
- Limit result sets withlimitparameter
- Use projections to return only needed fields

MIT License - see LICENSE file for details

- Initial release
- Full MongoDB CRUD operations
- Schema discovery tool
- Automatic ObjectId conversion
- TypeScript support

Made out of pain since the official MongoDB MCP didn't work for me

Interact with MongoDB databases using natural language to query collections, inspect schemas, and manage data.

Interact with MongoDB databases using natural language. Query collections, inspect schemas, and manage data.

Provides read-only access to MongoDB databases through standardized MCP tools and resources.

An MCP server providing tools and prompts for interacting with a MongoDB database.

A server for performing CRUD operations on a MongoDB database.

A server for querying and analyzing the MongoDB sample_mflix movie database.

Official MCP server for dbt (data build tool) providing integration with dbt Core/Cloud CLI, project metadata discovery, model information, and semantic layer querying capabilities.

Provides AI assistants with a secure and structured way to explore and analyze data in GreptimeDB.

Build robust data workflows, integrations, and analytics on a single intuitive platform.

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.