ujjawalptdr/Mongo-MCP-Server
If you are the rightful owner of Mongo-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MongoDB MCP Server is a middleware layer that connects AI models with MongoDB databases, enabling real-time CRUD operations through the Model Context Protocol.
🧠 MongoDB MCP Server
A Model Context Protocol (MCP) server built with Node.js, MongoDB, and the MCP SDK, enabling Large Language Models (LLMs) to perform real-time CRUD operations on MongoDB databases through structured, validated, and modular tools.
🚀 Overview
The MongoDB MCP Server acts as a middleware layer that bridges AI models (LLMs) and MongoDB databases.
It provides a set of dynamic MCP tools that allow LLMs to directly create, read, update, delete, and manage database documents — all through a structured, schema-validated protocol.
This project demonstrates how AI can interact safely and intelligently with databases using the Model Context Protocol (MCP).
✨ Key Features
- 🔗 LLM Integration: Enables language models to perform real-time CRUD operations on MongoDB.
- ⚙️ Modular MCP Tools: Each operation is defined as a reusable, independent tool.
- 🧩 Zod-Based Validation: Ensures all inputs are structured, safe, and schema-compliant.
- ⚡ Asynchronous Handlers: Designed for performance, scalability, and error resilience.
- 🔁 Persistent MongoDB Connection: Maintains a single client instance for efficient access.
- 🧠 AI-Driven Operations: Allows AI systems to manage data contextually and intelligently.
🧰 Available Tools
| Tool Name | Description |
|---|---|
| creatorInfo | Get detailed information about the creator. |
| getDocument | Retrieve a document by its unique ID. |
| listDocuments | List all documents from a MongoDB collection. |
| createDocument | Create a new document in a specified collection. |
| updateDocument | Update an existing document by ID. |
| deleteDocument | Delete a document by ID from a collection. |
| clearCollection | Remove all documents from a collection. |
🛠️ Tech Stack
- Node.js – Runtime environment
- MongoDB – NoSQL database
- Model Context Protocol (MCP) SDK – Server framework for LLM integration
- Zod – Input validation library
- dotenv – Environment variable management
⚙️ Installation
# Clone the repository
git clone https://github.com/ujjawalptdr/mongodb-mcp-server.git
# Navigate into the project
cd Mongo-MCP-Server
# Install dependencies
npm install
🧾 Configuration
Create a .env file in the project root:
MONGODB_URI=mongodb://localhost:27017 (your_MongoDB_URI)
DB_NAME=<your_database_name>
▶️ Usage
Run the MCP Server
node src/server.js
You’ll see:
✅ Connected to MongoDB: <your_database_name>
🧠 MongoDB MCP Server running...
The server exposes a suite of tools that can be consumed by LLMs or MCP-compatible clients such as AI assistants, Copilot, Claude or custom applications.
🧠 How It Works
- MCP SDK handles communication between the LLM and the server.
- Each database operation (like
createDocumentorlistDocuments) is defined as a tool with strict Zod validation. - LLMs can query, insert, update, or delete data by calling these tools through the protocol.
- The server ensures data integrity and returns formatted responses that the LLM can interpret.
💡 Example Tool Definition
server.tool(
"createDocument",
"Insert a document into MongoDB",
{
collectionName: z.string(),
data: z.record(z.any()),
},
mongoHandlers.createDocument
);
🧱 Project Structure
📦 mongo-MCP-Server
├── 📦 src # MCP Server configuration and tool registration
├── 📜 server.js # MCP Server configuration
├── 📜 mongoHandlers.js # CRUD logic and MongoDB connection
├── 📜 mcpServerMongo.js # MCP Server configuration and tool registration
├── 📜 package.json
├── 📜 package-lock.json
├── 📜 .gitignore
├── 📜 .env # Environment variables
└── 📜 README.md # Documentation
⚡ Example Operations
| Action | Example |
|---|---|
| Create | { "collectionName": "users", "data": { "name": "Ujjawal", "role": "Developer" } } |
| Read | { "collectionName": "users", "documentId": "6529a..." } |
| List | { "collectionName": "users", "limit": 10 } |
| Update | { "collectionName": "users", "documentId": "6529a...", "updateData": { "role": "Admin" } } |
| Delete | { "collectionName": "users", "documentId": "6529a..." } |
| Clear | { "collectionName": "users" } |
🧩 Future Enhancements
- 🧠 Add support for advanced query filters and aggregation pipelines.
- 🔄 Implement automatic reconnection and connection health monitoring.
- ⚙️ Introduce caching for frequent document retrievals to improve performance.
- 🧰 Extend MCP tools for multi-database or cross-collection operations.
- 🔐 Integrate optional authentication for secure AI–database communication.
👨💻 Creator Info
Ujjawal Patidar
Full Stack Developer | Problem Solver
🔗 GitHub
📜 License
This project is open-source and available under the MIT License.
MongoDB MCP Server – bridging AI intelligence with real-time database control through the Model Context Protocol.