Provides a comprehensive MCP server for MongoDB CRUD, indexing, aggregation, and admin tasks via an MCP client.
Configuration
View docs{
"mcpServers": {
"441126098-mongo-mcp": {
"command": "uvx",
"args": [
"run",
"mongo-mcp"
],
"env": {
"LOG_LEVEL": "INFO",
"MONGODB_URI": "mongodb://localhost:27017",
"MONGODB_DEFAULT_DB": "your_database_name",
"MONGODB_AUTH_SOURCE": "admin",
"MONGODB_TLS_ENABLED": "false",
"MONGODB_MAX_POOL_SIZE": "100",
"MONGODB_MIN_POOL_SIZE": "0",
"MONGODB_AUTH_MECHANISM": "SCRAM-SHA-256",
"MONGODB_READ_PREFERENCE": "primary",
"MONGODB_WRITE_CONCERN_W": "1",
"MONGODB_MAX_IDLE_TIME_MS": "30000",
"MONGODB_SOCKET_TIMEOUT_MS": "0",
"MONGODB_CONNECT_TIMEOUT_MS": "20000",
"MONGODB_READ_CONCERN_LEVEL": "local",
"MONGODB_SERVER_SELECTION_TIMEOUT_MS": "30000"
}
}
}
}Mongo-MCP provides a Python-based MCP server that lets large language models perform comprehensive MongoDB operations—from databases and collections management to document CRUD, indexing, aggregation, and admin tasks—via a consistent MCP client interface. It is designed for easy local development and integration with MCP toolchains.
You interact with Mongo-MCP through an MCP client to perform CRUD operations, manage databases and collections, create and monitor indexes, run aggregations, and perform administrative checks. Use the same MCP workflow you rely on for other data sources: connect your client, call tools by name (e.g., list_databases, insert_document, aggregate_documents), and handle results and errors in your application logic. The server exposes a wide range of tools to cover typical MongoDB tasks and operational health checks.
Prerequisites you need before installing Mongo-MCP are clearly defined to ensure a smooth setup.
Install the MCP runtime and dependencies for your environment. Mongo-MCP is intended to run with uvx for local development and testing.
Run the MCP server locally using the standard MCP runner. The recommended start command is to execute the MCP server through uvx so it can be integrated with MCP clients using stdio transport.
Environment variables control how Mongo-MCP connects to MongoDB and how it logs and times out operations. You can customize the MongoDB URI, default database, pool sizes, timeouts, TLS/authentication, read/write concerns, and logging behavior.
You can run Mongo-MCP with a local MongoDB instance by setting the following environment variables (examples shown in placeholders): MONGODB_URI, MONGODB_DEFAULT_DB, and LOG_LEVEL. You can also tune pool sizes, timeouts, and security settings as needed.
Security-conscious deployments enable TLS and proper authentication. You can enable TLS (TLS/SSL) and specify authentication sources and mechanisms when connecting to MongoDB. Ensure sensitive credentials are managed securely (for example, via environment variables or a secret store) and limit dangerous operations to trusted clients.
Mongo-MCP includes logging with configurable levels. You can adjust LOG_LEVEL and related logging options to control what information is written to log files, including rotation behavior and backup counts.
If you run Mongo-MCP in a local development environment, you can debug and validate connections by performing a comprehensive connection test and querying server status or replica set status via the provided tools.
If you encounter connection or operation issues, verify that MongoDB is reachable at the configured URI, confirm the default database exists (if you rely on it), check the logs for errors, and ensure the MCP server process has the necessary permissions to access the MongoDB instance.
The server exposes a broad set of tools for databases, collections, documents, indexes, aggregations, and admin tasks. Each tool is described in detail under the tool reference, including how to use it to perform common MongoDB operations.
List all databases in the connected MongoDB instance
Create a new database within MongoDB
Delete a database and its contents
Retrieve statistics for a database
List all collections in a specified database
Create a new collection with optional settings
Delete a collection from a database
Rename an existing collection
Get statistics for a collection
Insert a single document into a collection
Insert multiple documents in a single operation
Query documents with options for sorting, projection, and limit
Query a single document matching criteria
Count documents matching a query
Update documents (single or batch)
Replace a document entirely
Delete documents (single or batch)
List all indexes for a collection
Create a regular index
Create a text search index
Create a compound index
Delete an index
Rebuild all indexes for a collection
Execute an aggregation pipeline on documents
Get distinct values for a field across documents
Get MongoDB server status
Get replica set status
Test the database connection with a ping
Comprehensive connection test to MongoDB
Get detailed information about the current connection