Lists all available databases in the MongoDB instance
Lists all collections in a specified database
Retrieves the schema for a specified collection
Executes a find query on a collection
Finds a single document in a collection
Performs an aggregation pipeline on a collection
Counts documents in a collection matching a query
Finds distinct values for a field in a collection
Inserts a single document into a collection
Inserts multiple documents into a collection
Updates a single document in a collection
Updates multiple documents in a collection
Deletes a single document from a collection
Deletes multiple documents from a collection
Creates an index on a collection
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.
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.
You can install the MongoDB Server globally using npm:
npm install -g mcp-mongo-server
Or using yarn:
yarn global add mcp-mongo-server
Alternatively, you can use Docker to run the MongoDB Server:
docker pull kiliczsh/mcp-mongo-server
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 modeWhen 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)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
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"
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 ObjectIdFor safely connecting to production databases, enable read-only mode which:
The server can inspect and return MongoDB collection schemas, helping AI models understand the database structure before executing queries.
objectIdMode
parameter if you're experiencing issues with ID fields