Back to MCP Catalog

MongoDB Server MCP Server

DatabasesJavaScript
Connect LLMs to MongoDB databases with schema inspection and query capabilities
Available Tools

listDatabases

Lists all available databases in the MongoDB instance

listCollections

Lists all collections in a specified database

database

getSchema

Retrieves the schema for a specified collection

databasecollection

find

Executes a find query on a collection

databasecollectionqueryoptionsobjectIdMode

findOne

Finds a single document in a collection

databasecollectionqueryoptionsobjectIdMode

aggregate

Performs an aggregation pipeline on a collection

databasecollectionpipelineoptionsobjectIdMode

count

Counts documents in a collection matching a query

databasecollectionqueryoptionsobjectIdMode

distinct

Finds distinct values for a field in a collection

databasecollectionfieldqueryoptionsobjectIdMode

insertOne

Inserts a single document into a collection

databasecollectiondocumentoptionsobjectIdMode

insertMany

Inserts multiple documents into a collection

databasecollectiondocumentsoptionsobjectIdMode

updateOne

Updates a single document in a collection

databasecollectionfilterupdateoptionsobjectIdMode

updateMany

Updates multiple documents in a collection

databasecollectionfilterupdateoptionsobjectIdMode

deleteOne

Deletes a single document from a collection

databasecollectionfilteroptionsobjectIdMode

deleteMany

Deletes multiple documents from a collection

databasecollectionfilteroptionsobjectIdMode

createIndex

Creates an index on a collection

databasecollectionkeysoptionsobjectIdMode

MongoDB Server provides a standardized interface for AI models to interact with MongoDB databases. It enables LLMs to inspect collection schemas, execute queries, and perform database operations through a Model Context Protocol implementation. With features like smart ObjectId handling, read-only mode for safe production access, and flexible configuration options, this server bridges the gap between natural language processing and database management. It allows AI assistants to help with database operations, query construction, and data analysis without direct database access.

Overview

MongoDB Server enables AI models to interact with MongoDB databases through a standardized Model Context Protocol interface. This server allows LLMs to inspect database schemas, execute queries, and perform various MongoDB operations.

Installation

NPM Installation

You can install the MongoDB Server globally using npm:

npm install -g mcp-mongo-server

Or using yarn:

yarn global add mcp-mongo-server

Docker Installation

Alternatively, you can use Docker to run the MongoDB Server:

docker pull kiliczsh/mcp-mongo-server

Configuration

Environment Variables

The server can be configured using the following environment variables:

  • MCP_MONGODB_URI: MongoDB connection URI (required)
  • MCP_MONGODB_READONLY: Set to "true" to enable read-only mode

Command-line Options

When running the server, you can use these command-line options:

  • --read-only or -r: Connect in read-only mode
  • --port or -p: Specify the port to run on (default: 3000)
  • --host or -h: Specify the host to bind to (default: localhost)

Usage

Starting the Server

Start the server by providing your MongoDB connection URI:

MCP_MONGODB_URI="mongodb://username:password@localhost:27017/mydatabase" mcp-mongo-server

Or with command-line options:

mcp-mongo-server --read-only --port 3001

Using Docker

Run the server using Docker:

docker run -e MCP_MONGODB_URI="mongodb://username:password@localhost:27017/mydatabase" -p 3000:3000 kiliczsh/mcp-mongo-server

Or with docker-compose:

version: '3'
services:
  mcp-mongo-server:
    image: kiliczsh/mcp-mongo-server
    environment:
      - MCP_MONGODB_URI=mongodb://username:password@mongodb:27017/mydatabase
      - MCP_MONGODB_READONLY=true
    ports:
      - "3000:3000"

Features

Smart ObjectId Handling

The server intelligently handles MongoDB ObjectIds with three modes:

  • "auto" (default): Automatically converts fields named _id, id, or ending with Id to ObjectId
  • "none": No automatic conversion
  • "force": Forces all string ID fields to be converted to ObjectId

Read-Only Mode

For safely connecting to production databases, enable read-only mode which:

  • Prevents write operations (update, insert, delete, createIndex)
  • Uses MongoDB's secondary read preference for optimal performance
  • Provides an additional layer of security

Schema Inspection

The server can inspect and return MongoDB collection schemas, helping AI models understand the database structure before executing queries.

Troubleshooting

  • Connection Issues: Ensure your MongoDB URI is correct and that network access is properly configured
  • Authentication Errors: Verify that the provided credentials have appropriate access to the database
  • Performance Concerns: Consider using read-only mode when connecting to production databases
  • ObjectId Errors: Adjust the objectIdMode parameter if you're experiencing issues with ID fields

Related MCPs

Milvus Vector Database
DatabasesPython

Connect to Milvus vector database for semantic search and vector operations

MotherDuck DuckDB
DatabasesPython

SQL analytics with DuckDB and MotherDuck for AI assistants

Alibaba Cloud Tablestore
DatabasesJava, Python

Connect to Alibaba Cloud Tablestore for vector search and RAG applications

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.