Nisarg-Shah2302/mcp-mongo
If you are the rightful owner of mcp-mongo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server for MongoDB integration that provides AI systems with database access and management capabilities through a standardized interface.
create-database
Create a new MongoDB database with specified collections
insert-data
Insert data into a MongoDB collection
query-data
Query data from MongoDB using natural language
product-reviews
Get product reviews with filtering and sorting options
inventory-management
Manage product inventory with various operations
support-tickets
Manage customer support tickets
analytics-insights
Get insights from analytics data
shipping-locations
Manage shipping and warehouse locations
MongoDB MCP Server
A Model Context Protocol (MCP) server for MongoDB integration that provides AI systems with database access and management capabilities through a standardized interface.
Overview
This MongoDB MCP server enables AI systems to perform various MongoDB operations including:
- Creating databases and collections
- Inserting data into collections
- Querying data using natural language
- Managing product reviews and inventory
- Handling support tickets
- Analyzing shipping locations and inventory capacity
- Generating analytics insights
Prerequisites
- Node.js (v16 or higher)
- npm or yarn
- MongoDB (local installation or MongoDB Atlas account)
Installation
- Clone the repository:
git clone <repository-url>
cd mongo-mcp
- Install dependencies:
npm install
- Create a
.env
file in the root directory with the following variables:
MONGO_URI=mongodb://localhost:27017
MONGO_DB_NAME=MONGO_DB_NAME
Replace the MongoDB URI with your own connection string. You can use a local MongoDB instance or a MongoDB Atlas connection string.
Configuration
MongoDB Connection
The server uses the following configuration parameters:
- MONGO_URI: MongoDB connection string (default:
mongodb+srv://test.nckd7.mongodb.net/MONGO_DB_NAME
) - MONGO_DB_NAME: Name of the MongoDB database to use (default:
MONGO_DB_NAME
)
You can configure these parameters in three ways:
- Environment variables (recommended for production)
.env
file (recommended for development)- Default values in
src/config.ts
(not recommended for production)
MongoDB Connection Options
The connection options are defined in src/config.ts
:
export const MONGO_OPTIONS = {
serverSelectionTimeoutMS: 5000, // 5 seconds timeout for server selection
connectTimeoutMS: 5000, // 5 seconds timeout for initial connection
};
Building and Running
Build the Server
npm run build
Start the Server
npm run start
Using the Start Script
For convenience, you can use the provided start script:
./start-mcp-server.sh
This script:
- Checks if MongoDB is running locally
- Builds the server
- Sets environment variables for MongoDB connection
- Starts the server
Setting Up Sample Data
The server includes sample data for testing. To set up this data:
npm run setup-enhanced
This will create the following collections with sample data:
- reviews
- inventory_transactions
- support_tickets
- shipping_locations
- analytics_events
Integrating with CopilotKit
To configure this MCP server in your CopilotKit application:
- Open the MCP configuration modal
- Add a new server with the following details:
- Server Name:
mongodb
- Connection Type:
stdio
- Command:
node
- Arguments:
/path/to/mongo-mcp/build/index.js
- Server Name:
Available Tools
Basic Tools
-
create-database
- Create a new MongoDB database with specified collections
- Parameters:
collections
(array of collection names)
-
insert-data
- Insert data into a MongoDB collection
- Parameters:
collection
(collection name),data
(object or array of objects)
-
query-data
- Query data from MongoDB using natural language
- Parameters:
collection
(collection name),query
(natural language query),limit
(optional, max results)
Enhanced Tools
-
product-reviews
- Get product reviews with filtering and sorting options
- Parameters:
productId
(optional),minRating
(optional),verifiedOnly
(optional),sortBy
(optional),limit
(optional)
-
inventory-management
- Manage product inventory with various operations
- Parameters:
operation
(check/history/update),productId
,locationId
(optional),quantity
(optional),type
(optional),notes
(optional)
-
support-tickets
- Manage customer support tickets
- Parameters:
action
(list/view/create/update),ticketId
(optional),userId
(optional),status
(optional),priority
(optional),subject
(optional),description
(optional),category
(optional),limit
(optional)
-
analytics-insights
- Get insights from analytics data
- Parameters:
insightType
,timeframe
(optional),productId
(optional),limit
(optional)
-
shipping-locations
- Manage shipping and warehouse locations
- Parameters:
action
(list/view/capacity),locationType
(optional),locationCode
(optional),activeOnly
(optional)
Use Cases
Creating a Database and Collections
{
"collections": ["users", "products", "orders"]
}
Inserting Data
{
"collection": "products",
"data": {
"name": "Laptop",
"price": 999.99,
"category": "Electronics",
"stock": 50
}
}
Querying Data
{
"collection": "products",
"query": "find all laptops with price less than 1000",
"limit": 5
}
Managing Product Reviews
{
"productId": "Laptop",
"minRating": 4,
"verifiedOnly": true,
"sortBy": "rating",
"limit": 10
}
Checking Inventory
{
"operation": "check",
"productId": "Laptop"
}
Managing Support Tickets
{
"action": "list",
"status": "open",
"priority": "high",
"limit": 5
}
Getting Analytics Insights
{
"insightType": "product_popularity",
"timeframe": "month",
"limit": 5
}
Managing Shipping Locations
{
"action": "capacity",
"locationType": "warehouse",
"activeOnly": true
}
Troubleshooting
MongoDB Connection Issues
If you encounter connection issues:
-
Verify MongoDB is running:
nc -z localhost 27017
-
Check your MongoDB URI in the
.env
file or environment variables -
Ensure network connectivity to your MongoDB instance
-
Check MongoDB logs for any errors:
sudo journalctl -u mongod
Server Startup Issues
If the server fails to start:
-
Check for build errors:
npm run build
-
Verify Node.js version:
node --version
-
Check for dependency issues:
npm install
License
ISC
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.