Connect Claude to MongoDB with Mongoose
MongoDB Mongoose MCP lets Claude query, insert, update, and soft-delete MongoDB documents, with optional schema validation.
Why it matters
Enable Claude to directly interact with MongoDB databases, leveraging Mongoose schemas for enhanced data validation and operations. This asset allows for complex data querying, manipulation, and management through natural language.
Outcomes
What it gets done
Query MongoDB collections using natural language commands.
Insert, update, and delete documents with optional Mongoose schema validation.
List collections, manage indexes, and perform aggregation queries.
Integrate with Claude Desktop for seamless database interaction.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-mongodb-mongoose | bash Capabilities
Tools your agent gets
Query documents with filtering and projection
List available collections
Insert a single document
Update a single document
Soft delete a single document
Count documents with filtering
Query documents with aggregation pipeline
Create a new index
Overview
MongoDB & Mongoose MCP Server
MongoDB Mongoose MCP gives Claude direct MongoDB query, insert, update, and soft-delete tools, with optional Mongoose schema validation. Use it when Claude needs to query or manage a MongoDB database conversationally, with or without Mongoose schema validation.
What it does
MongoDB Mongoose MCP is an MCP server that lets Claude interact directly with MongoDB databases, with optional Mongoose schema support layered on top for data validation and hooks. It cleanly separates schema-based operations from schemaless ones, so you can use it against a database with defined Mongoose schemas or a plain, schema-free MongoDB collection.
When to use - and when NOT to
Use it when you want Claude to query, aggregate, insert, update, or manage MongoDB collections conversationally, for example "Show me all users in my database who are older than 30" or "Create an index on the email field of the users collection." It requires Node.js 18+ and a running MongoDB instance, connected via MONGODB_URI. Deletes are implemented as soft deletes rather than hard removal, marking documents rather than destroying them, which matters if you're building on top of this for anything where accidental data loss is a real risk. Mongoose schema support is optional: point SCHEMA_PATH at a directory of schema files, named to match their collection, to get validation and hooks, or skip it entirely for schemaless operation.
Capabilities
Query tools include find, with filtering and projection, listCollections, insertOne, updateOne, deleteOne, a soft delete rather than a hard removal, count, and aggregate for pipeline-based queries. Index tools include createIndex, dropIndex, and indexes to list a collection's current indexes. Under the hood, the server uses the MongoDB native driver for direct database operations and layers in Mongoose for schema-based operations whenever a matching schema file is found under SCHEMA_PATH. A schema file is simply a default-exported plain object describing fields and their types, such as name, email, age, and the createdAt timestamp, rather than a full Mongoose model definition.
How to install
In Claude Desktop's claude_desktop_config.json, Settings, Developer, Edit config:
{
"mcpServers": {
"mongodb-mongoose": {
"command": "npx",
"args": [
"-y",
"mongo-mongoose-mcp",
],
"env": {
"MONGODB_URI": "<your mongodb uri>",
"SCHEMA_PATH" : "<path to the root folder of all your mongoose schema objects>"
}
}
}
}
To build from source instead: clone the repository, npm install, npm run build, and test it with the MCP Inspector via npx @modelcontextprotocol/inspector node dist/index.js.
Who it's for
Developers who want Claude to query and manage a MongoDB database conversationally, with optional Mongoose-backed validation for collections that need it, instead of writing MongoDB queries by hand. It is released under the MIT License. A typical Mongoose schema file, placed under SCHEMA_PATH and named after its collection, looks like a plain object defining fields such as name, email, age, createdAt, and the isDeleted/deletedAt pair the server's soft-delete behavior relies on.
Source README
MongoDB Mongoose MCP
An MCP (Model Context Protocol) server that enables Claude to interact with MongoDB databases, with optional Mongoose schema support.
Features
- Query, aggregation, insert, update, and manage MongoDB collections directly from Claude
- Optional Mongoose schema support for data validation and hooks
- Soft delete implementation for document safety
- Clean separation between schema-based and schemaless operations
Prerequisites
- Node.js (v18 or higher)
- MongoDB
Integrating with Claude Desktop
To add the MCP server to Claude Desktop:
- Go to Settings > Developer > Edit config
- Add the following to your claude_desktop_config.json file:
{
"mcpServers": {
"mongodb-mongoose": {
"command": "npx",
"args": [
"-y",
"mongo-mongoose-mcp",
],
"env": {
"MONGODB_URI": "<your mongodb uri>",
"SCHEMA_PATH" : "<path to the root folder of all your mongoose schema objects>"
}
}
}
}
Available MCP Commands
When integrated with Claude, the following commands become available:
Query Tools
find: Query documents with filtering and projectionlistCollections: List available collectionsinsertOne: Insert a single documentupdateOne: Update a single documentdeleteOne: Soft delete a single documentcount: Count documents with filteringaggregate: Query documents with aggregation pipeline
Index Tools
createIndex: Create a new indexdropIndex: Remove an indexindexes: List indexes for a collection
Example Usage
Once integrated with Claude Desktop, you can use natural language to interact with your MongoDB database:
- "Show me all users in my database who are older than 30"
- "Insert a new product with name 'Widget X', price $29.99, and category 'Electronics'"
- "Count all completed orders from the past week"
- "Create an index on the email field of the users collection"
For Developers
Building from Source
# Clone the repository
git clone https://github.com/nabid-pf/mongo-mongoose-mcp.git
cd mongo-mongoose-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Test with the MCP inspector
npx @modelcontextprotocol/inspector node dist/index.js
Creating Mongoose Schemas
Place your Mongoose schema object files in the a directory and specify that path in SCHEMA_PATH var
Make sure file names reflect the collection name
// models/users.js (for users collection)
export default {
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
age: Number,
createdAt: { type: Date, default: Date.now },
isDeleted: { type: Boolean, default: false },
deletedAt: Date
};
How It Works
This project uses:
- MongoDB native driver for direct database operations
- Mongoose for schema-based operations when schemas are available
- The Model Context Protocol (MCP) to communicate with Claude
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.
