by kiliczsh
Enables LLMs to interact with MongoDB databases via a standardized interface, offering schema inspection, query execution, aggregation, and write capabilities, with optional read‑only mode and smart ObjectId handling.
Mcp Mongo Server provides a Model Context Protocol (MCP) endpoint that lets large language models query, aggregate, and modify MongoDB collections through a uniform JSON‑based API. It abstracts connection details, automatically converts string IDs to ObjectId when appropriate, and can enforce read‑only operation for production safety.
npm install -g mcp-mongo-server
or run directly via npx
.MCP_MONGODB_URI
environment variable. Add --read-only
(or set MCP_MONGODB_READONLY=true
) to disable write operations.
npx -y mcp-mongo-server mongodb://user:pass@localhost:27017/mydb --read-only
mcpServers
configuration (Claude Desktop, Windsurf, Cursor, etc.) pointing to the npx
command.query
, aggregate
, update
, insert
, or createIndex
. The server returns results or errors over stdio.docker run
commands.Q: Do I need to rebuild after changing code?
A: No. When using the published npm package or the Docker image, changes are already compiled. For local development use npm run watch
to auto‑rebuild.
Q: How does read‑only mode work?
A: The server sets the MongoDB read preference to secondaryPreferred
and disables any write‑related tool calls (update
, insert
, createIndex
).
Q: Can I force all ID fields to ObjectId?
A: Yes, set objectIdMode
to "force"
via the server’s configuration (environment variable or future CLI flag).
Q: What if my collection uses custom primary keys?
A: Use objectIdMode: "none"
to leave string IDs untouched.
Q: Is the server compatible with cloud MongoDB services? A: Absolutely – any standard MongoDB URI (Atlas, mLab, self‑hosted) works.
A Model Context Protocol server that enables LLMs to interact with MongoDB databases. This server provides capabilities for inspecting collection schemas and executing MongoDB operations through a standardized interface.
objectIdMode
parameter:
"auto"
: Convert based on field names (default)"none"
: No conversion"force"
: Force all string ID fields to ObjectIdMCP_MONGODB_URI
: MongoDB connection URIMCP_MONGODB_READONLY
: Enable read-only mode when set to "true"--read-only
or -r
: Connect in read-only modenpm install -g mcp-mongo-server
# Clone repository
git clone https://github.com/kiliczsh/mcp-mongo-server.git
cd mcp-mongo-server
# Install dependencies
npm install
# Build
npm run build
# Development with auto-rebuild
npm run watch
# Start server with MongoDB URI
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database
# Connect in read-only mode
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read-only
You can configure the server using environment variables, which is particularly useful for CI/CD pipelines, Docker containers, or when you don't want to expose connection details in command arguments:
# Set MongoDB connection URI
export MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database"
# Enable read-only mode
export MCP_MONGODB_READONLY="true"
# Run server (will use environment variables if no URI is provided)
npx -y mcp-mongo-server
Using environment variables in Claude Desktop configuration:
{
"mcpServers": {
"mongodb-env": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server"
],
"env": {
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
"MCP_MONGODB_READONLY": "true"
}
}
}
}
Using environment variables with Docker:
# Build
docker build -t mcp-mongo-server .
# Run
docker run -it -d -e MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" -e MCP_MONGODB_READONLY="true" mcp-mongo-server
# or edit docker-compose.yml and run
docker-compose up -d
Add the server configuration to Claude Desktop's config file:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
},
"mongodb-readonly": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database",
"--read-only"
]
}
}
}
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server"
],
"env": {
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database"
}
},
"mongodb-readonly": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server"
],
"env": {
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
"MCP_MONGODB_READONLY": "true"
}
}
}
}
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"github:kiliczsh/mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
},
"mongodb-readonly": {
"command": "npx",
"args": [
"-y",
"github:kiliczsh/mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database",
"--read-only"
]
}
}
}
The MCP MongoDB Server can be used with Windsurf and Cursor in a similar way to Claude Desktop.
Add the server to your Windsurf configuration:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
}
}
}
For Cursor, add the server configuration to your settings:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
}
}
}
You can also use the environment variables approach with both Windsurf and Cursor, following the same pattern shown in the Claude Desktop configuration.
Using Smithery:
npx -y @smithery/cli install mcp-mongo-server --client claude
Using mcp-get:
npx @michaellatman/mcp-get@latest install mcp-mongo-server
query: Execute MongoDB queries
{
collection: "users",
filter: { age: { $gt: 30 } },
projection: { name: 1, email: 1 },
limit: 20,
explain: "executionStats" // Optional
}
aggregate: Run aggregation pipelines
{
collection: "orders",
pipeline: [
{ $match: { status: "completed" } },
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } }
],
explain: "queryPlanner" // Optional
}
count: Count matching documents
{
collection: "products",
query: { category: "electronics" }
}
update: Modify documents
{
collection: "posts",
filter: { _id: "60d21b4667d0d8992e610c85" },
update: { $set: { title: "Updated Title" } },
upsert: false,
multi: false
}
insert: Add new documents
{
collection: "comments",
documents: [
{ author: "user123", text: "Great post!" },
{ author: "user456", text: "Thanks for sharing" }
]
}
createIndex: Create collection indexes
{
collection: "users",
indexes: [
{
key: { email: 1 },
unique: true,
name: "email_unique_idx"
}
]
}
{
includeDebugInfo: true // Optional
}
Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
npm run inspector
This will provide a URL to access the debugging tools in your browser.
The evals package loads an mcp client that then runs the index.ts file, so there is no need to rebuild between tests. You can load environment variables by prefixing the npx command. Full documentation can be found here.
OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts src/schemas/tools.ts
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
Please log in to share your review and rating for this MCP.
{ "mcpServers": { "mongodb": { "command": "npx", "args": [ "-y", "mcp-mongo-server" ], "env": { "MCP_MONGODB_URI": "<YOUR_MONGODB_URI>", "MCP_MONGODB_READONLY": "<true|false>" } } } }
Explore related MCPs that share similar capabilities and solve comparable challenges
by googleapis
An MCP server that streamlines database tool development by handling connection pooling, authentication, observability, and secure access, allowing agents to interact with databases via natural language.
by bytebase
Provides a universal gateway that lets MCP‑compatible clients explore and query MySQL, PostgreSQL, SQL Server, MariaDB, and SQLite databases through a single standardized interface.
by designcomputer
Enables secure interaction with MySQL databases via the Model Context Protocol, allowing AI applications to list tables, read contents, and execute queries safely.
by benborla
Provides read‑only access to MySQL databases for large language models, allowing schema inspection and safe execution of SQL queries.
by ClickHouse
Enables AI assistants to run read‑only ClickHouse queries, list databases and tables, and execute embedded chDB queries through an MCP interface.
by chroma-core
Offers an MCP server exposing Chroma's vector database capabilities for LLM applications, supporting collection and document management, multiple embedding functions, and flexible client types such as in‑memory, persistent, HTTP, and cloud.
by domdomegg
Provides read and write access to Airtable bases for AI systems, enabling inspection of schemas and manipulation of records.
by XGenerationLab
A Model Context Protocol (MCP) server that enables natural language queries to databases
by apache
Provides an MCP backend service built with Python and FastAPI to interact with Apache Doris databases, enabling natural language to SQL conversion, query execution, metadata extraction, and comprehensive enterprise data governance.