npm package: @surajswarnkar1001/mongodb-mcp-server
Description: Production-ready Model Context Protocol (MCP) server for MongoDB with zero configuration setup.
Author: Suraj
Latest version: 1.0.4

# MongoDB MCP Server 🚀

A production-ready, plug-and-play Model Context Protocol (MCP) server that securely exposes MongoDB CRUD operations to AI agents like **Cursor**, **Claude Desktop**, and **Antigravity**.

Built as a lightweight microservice, you can drop this into any workflow with **zero local configuration**. No `.env` files needed, no complex setups. Just point your agent to the file and provide your database string.

---

## ✨ Features

- **Zero Local Config:** Inject your database credentials directly through your AI agent's secure MCP settings.
- **Dynamic Collections:** Perform CRUD operations on *any* collection dynamically.
- **Strict Security Validation:** Built-in `Joi` validation prevents NoSQL injection attempts and empty-filter accidental wipes.
- **Plug-and-Play STDIO:** Optimized specifically for Cursor and Antigravity background execution.

---

## ⚡ Direct Integration (Cursor / Claude Desktop / Antigravity)

The easiest way to use this server is directly inside your AI IDE or assistant using the standard `stdio` transport. 

### 1. Configure Your Agent (Cursor/Antigravity/Claude)
Open your AI Agent's MCP Configuration settings (e.g., `Cursor > Settings > MCP` or `Antigravity MCP settings`). 

Add the exact JSON block below. Update the `MONGODB_URI` environment variable with your actual connection string. You don't even need to pre-install anything; `npx` will fetch and run it automatically!

```json
{
  "mcpServers": {
    "mongodb-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@surajswarnkar1001/mongodb-mcp-server"
      ],
      "env": {
        "MONGODB_URI": "Your mongodb connection string"
      },
      "disabledTools": []
    }
  }
}
```
*Note: If you are using MongoDB Atlas, replace the URI with your `mongodb+srv://...` cloud connection string.*

### 3. Usage & Testing
Once your agent connects, the server automatically registers **4 powerful tools** (`mongo_read`, `mongo_insert`, `mongo_update`, `mongo_delete`). 

To test if your connection is working properly, simply copy and paste this prompt into your AI assistant (e.g., Cursor Chat):

> **"Create a dummy user document in a collection called `test_users` with the name 'Alice' and then read it back to me to verify my MongoDB MCP connection is working."**

Once you confirm it is working, you can ask for more complex operations like:
- *"Fetch the last 5 sign-ups from the `users` collection sorted by date"*
- *"Update the document in `users` where email is 'test@domain.com' and set role to 'admin'"*
- *"We are building a new feature. Delete all records in the `analytics` collection to give us a fresh start."*

---

## 🛠️ Extending Tools
Want to add a custom MongoDB aggregation or specific logic?
1. Create `mcp-tools/mongo_custom.js`.
2. Export `schema` and `handler`.
3. Import and mount it onto the central `TOOL_REGISTRY` in `mcp-tools/index.js`. 
4. It auto-routes and appears in agent discovery instantly!