
MongoDB Lens
Full-featured MCP server for querying, aggregating, and managing MongoDB databases via natural language.
Add to your client
Copy the config for your MCP client and paste it into its config file.
npx -y mongodb-lens@latestPaste into ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"mongodb-lens": {
"command": "/path/to/npx",
"args": [
"-y",
"mongodb-lens@latest",
"mongodb://your-connection-string"
]
}
}
}Step-by-step guides: Add to Claude Desktop · Add to Cursor · Add to Windsurf
Before you start
- Node.js (>= v18.x; >= v22.x recommended) for NPX/local installation, or Docker
- A running MongoDB instance with a connection string (defaults to mongodb://localhost:27017)
- An MCP-compatible client such as Claude Desktop or Cursor
About MongoDB Lens
MongoDB Lens is a local MCP server providing comprehensive, natural-language access to MongoDB databases for LLM clients such as Claude Desktop and Cursor. It bundles 40+ tools for CRUD, aggregation, schema analysis, indexing, performance optimization, administration, geospatial/text search, GridFS, transactions, and change streams, alongside MCP resources and guided prompts. Installation is easiest via NPX (Node.js >= 18.x), with Docker Hub and local source options also documented.
Tools & capabilities (41)
find-documentsRun queries with filters, projections, and sorting.
aggregate-dataExecute aggregation pipelines.
count-documentsCount documents matching specified criteria.
distinct-valuesExtract unique values for any field.
insert-documentInsert one or more documents into collections.
update-documentUpdate documents matching specified criteria.
delete-documentDelete documents matching specified criteria (requires confirmation).
bulk-operationsPerform multiple operations efficiently (requires confirmation for destructive operations).
analyze-schemaAutomatically infer collection schemas.
compare-schemasCompare schemas between two collections.
generate-schema-validatorGenerate JSON Schema validators.
explain-queryAnalyze query execution plans.
analyze-query-patternsAnalyze live queries and suggest optimizations.
create-indexCreate new indexes for performance optimization.
drop-indexRemove indexes from collections (requires confirmation).
list-databasesView all accessible databases.
use-databaseSwitch to a specific database context.
create-databaseCreate a new database with option to switch to it.
drop-databaseDrop a database (requires confirmation).
list-collectionsExplore collections in the current database.
create-collectionCreate new collections with custom options.
rename-collectionRename existing collections (requires confirmation when dropping targets).
drop-collectionRemove collections from the database (requires confirmation).
validate-collectionCheck for data inconsistencies.
create-timeseriesCreate time series collections for temporal data.
text-searchPerform full-text search across text-indexed fields.
geo-queryPerform geospatial queries with various operators.
collation-queryFind documents with language-specific collation rules.
transactionExecute multiple operations in a single ACID transaction.
gridfs-operationManage large files with GridFS buckets.
export-dataExport query results in JSON or CSV format.
watch-changesMonitor real-time changes to collections.
get-statsRetrieve database or collection statistics.
shard-statusView sharding configuration for databases and collections.
create-userCreate new database users with specific roles.
drop-userRemove database users (requires confirmation).
add-connection-aliasAdd a new MongoDB connection alias.
list-connectionsView all available MongoDB connection aliases.
connect-mongodbConnect to a different MongoDB URI.
connect-originalConnect back to the original MongoDB URI used at startup.
clear-cacheClear memory caches to ensure fresh data.
What this server can do
MongoDB Lens provides tools for these capabilities — tap one to see every MCP server that does the same:
When to use it
- Explore and query MongoDB databases conversationally without writing query syntax by hand
- Build and refine aggregation pipelines step by step
- Analyze and compare collection schemas and generate JSON Schema validators
- Diagnose slow queries and get index recommendations to optimize performance
- Perform administrative tasks such as managing collections, indexes, users, and time series data
- Run geospatial, full-text, and collation-aware searches, and monitor real-time change streams
Security notes
Permissions are dictated by the MongoDB connection string user; using a read-only account prevents unintended writes/deletes. Destructive operations (drop-collection, drop-database, delete-document, drop-index, drop-user, etc.) require two-step token confirmation by default. This can be bypassed by setting CONFIG_DISABLE_DESTRUCTIVE_OPERATION_TOKENS=true, which executes destructive operations immediately without confirmation. Connection string passwords are obfuscated in logs.
MongoDB Lens FAQ
What is the easiest way to run MongoDB Lens?
Run it with NPX: `npx -y mongodb-lens@latest` (optionally followed by your MongoDB connection string). Docker Hub and local Node.js/Docker installs are also supported.
How does it connect to my database?
Pass a MongoDB connection string as an argument (e.g. mongodb://your-connection-string). If omitted, it defaults to mongodb://localhost:27017. You can also define multiple named connection aliases.
How are destructive operations protected?
By default, destructive operations require a two-step token confirmation. You can bypass this in controlled environments by setting CONFIG_DISABLE_DESTRUCTIVE_OPERATION_TOKENS=true. Using a read-only MongoDB user also prevents writes and deletes.
Which MongoDB versions are supported?
MongoDB Lens is backwards compatible, supporting both modern and legacy MongoDB versions, and requires Node.js >= 18.x (>= 22.x recommended).
Alternatives to MongoDB Lens
Compare all alternatives →Google's official MCP server with prebuilt BigQuery tools, querying datasets via Application Default Credentials.
Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.
Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.
Compare MongoDB Lens with: