mcp mongo server
A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute read-only queries.
A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute read-only queries.
A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute MongoDB operations.
--read-only
or -r
flagmongodb://
URIsReturns query results or execution plan
aggregate
Returns aggregation results or execution plan
update
Returns update operation results
serverInfo
Returns version, storage engine, and server details
insert
Returns insert operation results
createIndex
Returns index creation results
count
analyze_collection
- Analyze collection structure and contentsInstall dependencies:
npm install
Build the server:
npm run build
For development with auto-rebuild:
npm run watch
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"
]
}
}
}
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.
The server provides schema information for each collection in the database:
mongodb://<host>/<collection>/schema
)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"
]
}
}
}
To install MCP MongoDB Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mcp-mongo-server --client claude
You can install this package using mcp-get:
npx @michaellatman/mcp-get@latest install mcp-mongo-server
Replace /sample_namespace
with your database name.
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:
1. All write operations (update, insert, createIndex) will be blocked
2. The server connects using MongoDB's secondary read preference
3. The connection status indicates read-only mode is active
4. The ping
and serverInfo
responses include read-only status information
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.