home / mcp / mongo-mcp server

Mongo-MCP Server

Provides a comprehensive MCP server for MongoDB CRUD, indexing, aggregation, and admin tasks via an MCP client.

Installation
Add the following to your MCP client configuration file.

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.

How to use

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.

How to install

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.

Additional setup notes

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.

Environment and security considerations

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.

Monitoring and logging

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.

Notes

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.

Troubleshooting

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.

Notes on tooling availability

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.

Available tools

list_databases

List all databases in the connected MongoDB instance

create_database

Create a new database within MongoDB

drop_database

Delete a database and its contents

get_database_stats

Retrieve statistics for a database

list_collections

List all collections in a specified database

create_collection

Create a new collection with optional settings

drop_collection

Delete a collection from a database

rename_collection

Rename an existing collection

get_collection_stats

Get statistics for a collection

insert_document

Insert a single document into a collection

insert_many_documents

Insert multiple documents in a single operation

find_documents

Query documents with options for sorting, projection, and limit

find_one_document

Query a single document matching criteria

count_documents

Count documents matching a query

update_document

Update documents (single or batch)

replace_document

Replace a document entirely

delete_document

Delete documents (single or batch)

list_indexes

List all indexes for a collection

create_index

Create a regular index

create_text_index

Create a text search index

create_compound_index

Create a compound index

drop_index

Delete an index

reindex_collection

Rebuild all indexes for a collection

aggregate_documents

Execute an aggregation pipeline on documents

distinct_values

Get distinct values for a field across documents

get_server_status

Get MongoDB server status

get_replica_set_status

Get replica set status

ping_database

Test the database connection with a ping

test_mongodb_connection

Comprehensive connection test to MongoDB

get_connection_details

Get detailed information about the current connection