
A Model Context Protocol server for MongoDB integration with Claude
A Model Context Protocol server for MongoDB integration with Claude
A Model Context Protocol (MCP) server that provides Claude with the ability to interact with MongoDB databases. This implementation allows Claude to perform a wide range of MongoDB operations, including querying, aggregation, data manipulation (CRUD), and database management directly from the conversation.
This MongoDB MCP server implements the Model Context Protocol to create a bridge between Claude and MongoDB databases. It enables Claude to execute MongoDB commands through a standardized interface, making it possible to analyze, manage, and work with your data directly in conversations.
find, findOne), perform aggregations (aggregate), count documents (count), get distinct values (distinct), and sample data (sample).insertOne, insertMany), update (updateOne, updateMany), and delete (deleteOne, deleteMany) documents.listDatabases), list collections (listCollections), and drop collections (dropCollection).explain).DEFAULT_DATABASE).Clone this repository (replace ryaker with your username if forked):
git clone [email protected]:ryaker/mongodb-mcp-server.git
# Or use HTTPS if preferred
# git clone https://github.com/ryaker/mongodb-mcp-server.git
cd mongodb-mcp-serverInstall dependencies:
npm installConfigure Claude Desktop or Cursor:
Settings > Extensions > Model Context Protocol. In Claude Desktop, it might be in a config.json file.mongo-mcp-server.js file and set the required environment variables.Example Configuration (adjust path as needed):
{
"mcpServers": {
"mongo-custom-server": { // You can name this key anything descriptive
"command": "node",
"args": ["/Volumes/Dev/localDev/MCPServers/CustomMongo_clean/mongo-mcp-server.js"], // <-- Make sure this path is correct!
"env": {
"MONGODB_URI": "mongodb+srv://your_username:your_password@your_cluster.mongodb.net/?retryWrites=true&w=majority", // <-- Your MongoDB connection string
"DEFAULT_DATABASE": "YourDefaultDbName" // <-- Optional: Set a default database
}
}
}
}MONGODB_URI with your actual MongoDB connection string. Ensure the user specified in the URI has the necessary permissions for the operations you intend to perform.DEFAULT_DATABASE is optional. If set, operations will target this database unless overridden by the database parameter in a tool call.Restart Claude Desktop or Cursor to load the new MCP server.
The server exposes the following tools. Most tools accept an optional database parameter to specify the target database, otherwise they use the DEFAULT_DATABASE set in the environment variables.
Querying & Reading
aggregate: Run a MongoDB aggregation pipeline.
collection (string, required): Name of the collection.pipeline (array, required): Aggregation pipeline stages.database (string, optional): Target database.sample: Get random sample documents.
collection (string, required): Name of the collection.count (number, optional, default: 5, max: 10): Number of documents to sample.database (string, optional): Target database.explain: Get the execution plan for an aggregation pipeline.
collection (string, required): Name of the collection.pipeline (array, required): Aggregation pipeline stages.database (string, optional): Target database.find: Find documents matching a query.
collection (string, required): Name of the collection.filter (object, optional, default: {}): Query filter.projection (object, optional, default: {}): Fields to include/exclude.limit (number, optional, default: 10, max: 100): Max documents to return.sort (object, optional, default: {}): Sort criteria.database (string, optional): Target database.findOne: Find a single document matching a query.
collection (string, required): Name of the collection.filter (object, required): Query filter.projection (object, optional, default: {}): Fields to include/exclude.database (string, optional): Target database.count: Count documents matching a query.
collection (string, required): Name of the collection.filter (object, optional, default: {}): Query filter.database (string, optional): Target database.distinct: Get distinct values for a field.
collection (string, required): Name of the collection.field (string, required): Field name.filter (object, optional, default: {}): Query filter.database (string, optional): Target database.Data Manipulation (Write/Delete)
insertOne: Insert a single document.
collection (string, required): Name of the collection.document (object, required): Document to insert.database (string, optional): Target database.insertMany: Insert multiple documents.
collection (string, required): Name of the collection.documents (array, required): Array of documents.database (string, optional): Target database.updateOne: Update a single document.
collection (string, required): Name of the collection.filter (object, required): Filter to select document.update (object, required): Update operations (e.g., $set).upsert (boolean, optional, default: false): Create if not found?database (string, optional): Target database.updateMany: Update multiple documents.
collection (string, required): Name of the collection.filter (object, required): Filter to select documents.update (object, required): Update operations.database (string, optional): Target database.deleteOne: Delete a single document.
collection (string, required): Name of the collection.filter (object, required): Filter to select document.database (string, optional): Target database.deleteMany: Delete multiple documents.
collection (string, required): Name of the collection.filter (object, required): Filter to select documents.database (string, optional): Target database.Database/Collection Management
listCollections: List all collections in a database.
nameOnly (boolean, optional, default: false): Return only names?database (string, optional): Target database.listDatabases: List all databases on the server.
nameOnly (boolean, optional, default: true): Return only names?dropCollection: Drop an entire collection.
collection (string, required): Name of the collection to drop.confirm (boolean, required): Must be true to confirm deletion.database (string, optional): Target database.Querying Data:
User: Find the 5 most recent user documents in the 'users' collection.
Claude: (Calls 'find' with collection='users', limit=5, sort={createdAt: -1})
User: Show me the user document with email '[email protected]'.
Claude: (Calls 'findOne' with collection='users', filter={email: '[email protected]'})
User: How many orders were placed yesterday in the 'orders' collection in the 'sales' database?
Claude: (Calls 'count' with collection='orders', filter={orderDate: {$gte: startOfDay, $lt: endOfDay}}, database='sales')Aggregating Data:
User: What are the distinct product categories in the 'products' collection?
Claude: (Calls 'distinct' with collection='products', field='category')
User: Show me the total sales per month from the 'orders' collection.
Claude: (Calls 'aggregate' with collection='orders', pipeline=[...])Modifying Data:
User: Insert a new user document: { name: 'Alice', email: '[email protected]' }
Claude: (Calls 'insertOne' with collection='users', document={ name: 'Alice', email: '[email protected]' })
User: Update the user with email '[email protected]' to set their status to 'active'.
Claude: (Calls 'updateOne' with collection='users', filter={email: '[email protected]'}, update={$set: {status: 'active'}})
User: Delete all log entries older than 30 days from the 'logs' collection.
Claude: (Calls 'deleteMany' with collection='logs', filter={timestamp: {$lt: thirtyDaysAgo}})Managing Collections:
User: List all collections in the 'staging' database.
Claude: (Calls 'listCollections' with database='staging')
User: Please drop the 'test_data' collection. Confirm deletion.
Claude: (Calls 'dropCollection' with collection='test_data', confirm=true)MONGODB_URI) for connection strings.MONGODB_URI is correct. Ensure the MongoDB user has permissions and network access (firewalls, IP lists). Check server logs (console.error) via Claude Desktop/Cursor logs.Pick your client and paste the snippet. Each one is the same server, written the way that client expects it.
claude mcp add mongo-custom-server -- node /Volumes/Dev/localDev/MCPServers/CustomMongo_clean/mongo-mcp-server.js{
"mcpServers": {
"mongo-custom-server": {
"env": {
"MONGODB_URI": "",
"DEFAULT_DATABASE": ""
},
"args": [
"/Volumes/Dev/localDev/MCPServers/CustomMongo_clean/mongo-mcp-server.js"
],
"command": "node"
}
}
}code --add-mcp '{"name":"mongo-custom-server","env":{"MONGODB_URI":"","DEFAULT_DATABASE":""},"args":["/Volumes/Dev/localDev/MCPServers/CustomMongo_clean/mongo-mcp-server.js"],"command":"node"}'[mcp_servers.mongo-custom-server]
command = "node"
args = ["/Volumes/Dev/localDev/MCPServers/CustomMongo_clean/mongo-mcp-server.js"]Runs locally on your device. Your client starts the server itself, so nothing has to be hosted.
Paste this prompt into your agent. It reads this page and does the setup for you.
Read https://aiagentslisting.com/mcp/mongodb-mcp-server-2 to learn what the "MongoDB MCP Server" MCP server does and how to install it. Add it to my coding agent's MCP configuration as documented on that page, then confirm the server connects and list the tools it exposes.Agents can also browse this directory over MCP at https://aiagentslisting.com/api/mcp
This server runs locally, so we can't read its tool list over the web yet.
Maintain this server? Claiming proves you own the listing and earns the last 4 points.
Claim this listingPaste this line near the top of your repository's README. The badge always renders the current score.
[](https://aiagentslisting.com/mcp/mongodb-mcp-server-2)Nothing comparable is listed yet.
No tagged releases on record.
Connect to the AI Agents Listing MCP server at https://aiagentslisting.com/api/mcp using the HTTP transport and complete the sign-in when it asks. Then call the submit_review tool for the listing "mongodb-mcp-server-2" with a rating from 1 to 5 and a short note on what worked and what did not.No reviews yet
Be the first to share your experience with this tool.
One email a week. New agents, MCP servers and skills, and what is actually getting traction.