MongoDB Lens is a local Model Context Protocol (MCP) server that enables natural language interactions with MongoDB databases. It allows you to perform queries, run aggregations, optimize performance, and manage your databases using conversational language through any MCP-compatible client like Claude Desktop.
MongoDB Lens can be installed and run in several ways:
Make sure Node.js is installed on your system:
node --version # Ideally >= v22.x but MongoDB Lens is >= v18.x compatible
Then run MongoDB Lens via NPX:
# Using default connection string mongodb://localhost:27017
npx -y mongodb-lens
# Using custom connection string
npx -y mongodb-lens mongodb://your-connection-string
# Using "@latest" to keep the package up-to-date
npx -y mongodb-lens@latest
Make sure Docker is installed:
docker --version # Ideally >= v27.x
Run MongoDB Lens via Docker Hub:
# Using default connection string mongodb://localhost:27017
docker run --rm -i --network=host furey/mongodb-lens
# Using custom connection string
docker run --rm -i --network=host furey/mongodb-lens mongodb://your-connection-string
# Using "--pull" to keep the Docker image up-to-date
docker run --rm -i --network=host --pull=always furey/mongodb-lens
Clone the repository:
git clone https://github.com/furey/mongodb-lens.git
Navigate to the cloned directory:
cd /path/to/mongodb-lens
Install dependencies:
npm ci
Start the server:
# Using default connection string mongodb://localhost:27017
node mongodb-lens.js
# Using custom connection string
node mongodb-lens.js mongodb://your-connection-string
Clone the repository:
git clone https://github.com/furey/mongodb-lens.git
Navigate to the cloned directory:
cd /path/to/mongodb-lens
Build the Docker image:
docker build -t mongodb-lens .
Run the container:
# Using default connection string mongodb://localhost:27017
docker run --rm -i --network=host mongodb-lens
# Using custom connection string
docker run --rm -i --network=host mongodb-lens mongodb://your-connection-string
To verify the installation, paste this JSONRPC message into the server's stdio:
{"method":"resources/read","params":{"uri":"mongodb://databases"},"jsonrpc":"2.0","id":1}
You should receive a list of databases in your MongoDB instance.
MongoDB Lens accepts a MongoDB connection string as its only argument:
npx -y mongodb-lens@latest mongodb://your-connection-string
Connection strings have the following format:
mongodb://[username:password@]host[:port][/database][?options]
Examples:
mongodb://localhost:27017
mongodb://username:password@hostname:27017/mydatabase?authSource=admin
mongodb://hostname:27017/mydatabase?retryWrites=true&w=majority
MongoDB Lens supports extensive customization via a JSON configuration file located at:
~/.mongodb-lens.jsonc
(preferred) or~/.mongodb-lens.json
You can customize the config file path by setting the CONFIG_PATH
environment variable.
To generate a configuration file:
# Generate config file
npx -y mongodb-lens@latest config:create
# Force overwrite existing file
npx -y mongodb-lens@latest config:create -- --force
You can configure multiple MongoDB URIs with aliases:
{
"mongoUri": {
"main": "mongodb://localhost:27017",
"backup": "mongodb://localhost:27018",
"atlas": "mongodb+srv://username:[email protected]/mydb"
}
}
The first URI becomes the default connection at startup. You can switch connections using natural language: "Connect to backup" or "Connect to atlas".
claude_desktop_config.json
:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"mongodb-lens": {
"command": "/path/to/npx",
"args": [
"-y",
"mongodb-lens@latest",
"mongodb://your-connection-string"
]
}
}
}
MCP Inspector is useful for testing and debugging:
# Run MCP Inspector with MongoDB Lens
npx -y @modelcontextprotocol/inspector npx -y mongodb-lens@latest
# With custom connection string
npx -y @modelcontextprotocol/inspector npx -y mongodb-lens@latest mongodb://your-connection-string
Then open http://localhost:5173 to access the inspector interface.
For better security, consider using read-only credentials:
// In MongoDB shell:
use admin
db.createUser({
user: 'readonly',
pwd: 'eXaMpLePaSsWoRd',
roles: [{ role: 'read', db: 'mydatabase' }]
})
Then connect using those credentials:
mongodb://readonly:eXaMpLePaSsWoRd@localhost:27017/mydatabase
MongoDB Lens implements a token-based confirmation system for destructive operations:
Tools that require confirmation include:
drop-user
, drop-index
, drop-database
, drop-collection
delete-document
, bulk-operations
(when including delete operations)rename-collection
(when the target collection exists)To bypass confirmation, set:
CONFIG_DISABLE_DESTRUCTIVE_OPERATION_TOKENS=true npx -y mongodb-lens@latest
To disable specific tools, add them to your configuration file:
{
"disabled": {
"tools": [
"drop-user",
"drop-index",
"drop-database",
"drop-collection",
"delete-document",
"bulk-operations",
"rename-collection"
]
}
}
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mongodb-lens" '{"command":"npx","args":["-y","mongodb-lens@latest","mongodb://localhost:27017"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mongodb-lens": {
"command": "npx",
"args": [
"-y",
"mongodb-lens@latest",
"mongodb://localhost:27017"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mongodb-lens": {
"command": "npx",
"args": [
"-y",
"mongodb-lens@latest",
"mongodb://localhost:27017"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect