MongoDB MCP Server
by NoSQLTeam
A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute MongoDB operations.
What is MongoDB MCP Server
MCP MongoDB Server
A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute MongoDB operations.
Demo
Features
Read-Only Mode
- Connect to MongoDB in read-only mode with
--read-only
or-r
flag - Prevents write operations (update, insert, createIndex)
- Uses MongoDB's secondary read preference for optimal read performance
- Provides additional safety for production database connections
Resources
- List and access collections via
mongodb://
URIs - Each collection has a name, description and schema
- JSON mime type for schema access
Tools
-
query
- Execute MongoDB queries with optional execution plan analysis
- Input: Collection name, filter, projection, limit, explain options
- Returns query results or execution plan
-
aggregate
- Execute MongoDB aggregation pipelines with optional execution plan analysis
- Input: Collection name, pipeline stages, explain options
- Returns aggregation results or execution plan
-
update
- Update documents in a collection
- Input: Collection name, filter, update operations, upsert/multi options
- Returns update operation results
-
serverInfo
- Get MongoDB server information and status
- Input: Optional debug info flag
- Returns version, storage engine, and server details
-
insert
- Insert documents into a collection
- Input: Collection name, documents array, write options
- Returns insert operation results
-
createIndex
- Create indexes on a collection
- Input: Collection name, index specifications, write options
- Returns index creation results
-
count
- Count documents matching a query
- Input: Collection name, query filter, count options
- Returns document count
Prompts
analyze_collection
- Analyze collection structure and contents- Input: Collection name
- Output: Insights about schema, data types, and statistics
Development
Install dependencies:
npm install
Build the server:
npm run build
For development with auto-rebuild:
npm run watch
Installation for Development
Using Claude Desktop
To use with Claude Desktop, add the server config:
On MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
On Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": [
"~/mcp-mongo-server/build/index.js",
"mongodb://muhammed:[email protected]/namespace"
]
},
"mongodb-readonly": {
"command": "node",
"args": [
"~/mcp-mongo-server/build/index.js",
"mongodb://muhammed:[email protected]/namespace",
"--read-only"
]
}
}
}
Debugging
Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the MCP Inspector, which is available as a package script:
npm run inspector
The Inspector will provide a URL to access debugging tools in your browser.
Components
Resources
The server provides schema information for each collection in the database:
- Collection Schemas (
mongodb://<host>/<collection>/schema
)- JSON schema information for each collection
- Includes field names and data types
- Automatically inferred from collection documents
Usage with Claude Desktop
To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json
:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:[email protected]/sample_namespace"
]
},
"mongodb-readonly": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:[email protected]/sample_namespace",
"--read-only"
]
},
"mongodb-github": {
"command": "npx",
"args": [
"-y",
"github:kiliczsh/mcp-mongo-server",
"mongodb://muhammed:[email protected]/sample_namespace",
"--read-only"
]
}
}
}
Installing via Smithery
To install MCP MongoDB Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mcp-mongo-server --client claude
Installing via mcp-get
You can install this package using mcp-get:
npx @michaellatman/mcp-get@latest install mcp-mongo-server
Replace /sample_namespace
with your database name.
Using Read-Only Mode
You can connect to MongoDB in read-only mode by adding the --read-only
or -r
flag when starting the server. This is recommended when you need to protect your data from accidental writes or when connecting to production databases.
# Connect in read-only mode using the command line
npx mcp-mongo-server mongodb://user:[email protected]/database --read-only
When in read-only mode:
- All write operations (update, insert, createIndex) will be blocked
- The server connects using MongoDB's secondary read preference
- The connection status indicates read-only mode is active
- The
ping
andserverInfo
responses include read-only status information
License
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.
How to Use
Leave a Comment
Comments section will be available soon. Stay tuned!
Frequently Asked Questions
What is MCP?
MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.
What are MCP Servers?
MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.
How do MCP Servers work?
MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.
Are MCP Servers secure?
Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.
Related MCP Servers
PostgreSQL MCP Server
A Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
AWS Knowledge Base Retrieval
An MCP server implementation for retrieving information from the AWS Knowledge Base using the Bedrock Agent Runtime.
Docker Control MCP
Manage Docker containers and images through Claude. Build, run, and monitor containers using natural language instructions.
GitHub MCP Server
MCP Server for the GitHub API, enabling file operations, repository management, search functionality, and more.
EverArt MCP Server
Image generation server for Claude Desktop using EverArt's API.
ClickHouse
Query your ClickHouse database server.
Fireproof
Immutable ledger database with live synchronization
MotherDuck
Query and analyze data with MotherDuck and local DuckDB
mcp-neo4j
Neo4j graph database server (schema + read/write-cypher) and separate graph database backed memory
Neon
Interact with the Neon serverless Postgres platform
Submit Your MCP Server
Share your MCP server with the community
Submit Now