
mongo mcp
Connect LLMs to MongoDB
Repository Info
About This Server
Connect LLMs to MongoDB
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
Mongo MCP Server
An MCP (Model Context Protocol) server for interacting with MongoDB. Provides tools for querying and inserting documents into a MongoDB database via STDIO transport.
Features
- MongoDB Query Tool: Query collections with customizable limits.
- MongoDB Insert Tool: Insert documents into collections.
- STDIO Transport: Compatible with MCP clients over standard input/output.
Prerequisites
- Node.js: v18+ (with ES module support).
- MongoDB: A running instance (local or remote).
- npm: For dependency management.
Installation
-
Clone the repository:
git clone https://github.com/stevederico/mongo-mcp.gitcd mongo-mcp -
Install dependencies:
npm install -
Configure environment variables:
- Create a .env file in the root directory: MONGO_URL=mongodb://localhost:27017 DB_NAME=myDatabase
- Replace mongodb://localhost:27017 with your MongoDB connection string and myDatabase with your database name.
Usage
-
Start the server:
npm startThe server will connect to MongoDB and listen for MCP commands via STDIO.
-
Interact with the server using an MCP client (e.g., via STDIO):
- Query Example: { "tool": "mongo_query", "args": { "collection": "users", "query": "{"name": "Alice"}", "limit": 5 } }
- Insert Example: { "tool": "mongo_insert", "args": { "collection": "users", "document": "{"name": "Bob", "age": 30}" } }
Tools
-
mongo_query:
- Args:
- collection (string): Target collection name.
- query (string): JSON-stringified MongoDB query.
- limit (number, optional): Max results (default: 10).
- Returns: Array of matching documents as JSON.
- Args:
-
mongo_insert:
- Args:
- collection (string): Target collection name.
- document (string | object): JSON-stringified or raw document to insert.
- Returns: Inserted document ID.
- Args:
Configuration
{
"mcpServers": {
"mongo-mcp": {
"command": "node",
"args": [
"/mongo-mcp/index.js"
],
"env": {
"MONGO_URL": "mongodb://localhost:27017",
"DB_NAME": "mongomcp"
},
"disabled": false,
"autoApprove": []
}
}
}
- Environment Variables:
- MONGO_URL: MongoDB connection URI (e.g., mongodb://localhost:27017).
- DB_NAME: Database name.
- Set these in .env or via system environment variables:
export MONGO_URL="mongodb://localhost:27017"export DB_NAME="myDatabase"npm start
Development
- Run in dev mode:
npm run dev - Modify server.js to add more tools or adjust behavior.
Dependencies
- @modelcontextprotocol/sdk: MCP server framework.
- mongodb: MongoDB driver for Node.js.
- zod: Schema validation for tool arguments.
License
MIT License. See LICENSE for details.
Contributing
Pull requests welcome! Open an issue to discuss changes first.
Quick Start
Clone the repository
git clone https://github.com/stevederico/mongo-mcpInstall dependencies
cd mongo-mcp
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.