# mongodb-lens

> mongodb-lens is an open-source MCP server for databases. Local MCP server giving AI assistants natural-language access to MongoDB databases. It is available on CLI, API, Self-hosted, macOS, Windows and Linux.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, API, Self-hosted, macOS, Windows, Linux
- **Website:** https://www.npmjs.com/package/mongodb-lens
- **Repository:** https://github.com/furey/mongodb-lens
- **GitHub stars:** 207
- **License:** MIT
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-12-01

## About

Running as a local Model Context Protocol server, this project lets an MCP-capable AI client query, aggregate, and inspect MongoDB data without writing shell commands. It exposes a broad set of tools covering reads, writes, index management, schema inference, query plan analysis, and change streams, along with resources for stats and server status.

Safety is handled through several layers: a two-step token confirmation for destructive operations, a read-only mode that blocks write tools and pipeline stages, and field projection to keep sensitive values out of results sent to a remote model. Multiple named connection aliases let users switch between instances by name.

It suits developers and database administrators who want an assistant to explore collections, tune slow queries, or review schemas on local or remote MongoDB deployments. It can be launched through npx, Docker Hub, or a Node.js checkout.

## Features

- **Natural language queries:** Find, count, aggregate, and update documents by describing what you want to an AI client.
- **Destructive operation confirmation:** Deletes, drops, and similar actions require a short-lived token issued in a first step.
- **Read-only mode:** A config switch blocks write tools and pipeline stages for safer exploration.
- **Query performance analysis:** Explains query plans, profiles live query patterns, and suggests indexes.
- **Schema inference and validation:** Infers collection schemas, compares them, and generates JSON Schema validators.
- **Multiple connection aliases:** Save named MongoDB URIs in a config file and switch between them by name.

## Good for

- Exploring an unfamiliar MongoDB database through conversational queries
- Diagnosing slow queries and getting index recommendations
- Reviewing collection schemas before a migration or refactor
- Exporting filtered query results to JSON or CSV
- Testing risky changes against a restored backup copy with confirmation enabled

## Tools

From the tool list in its README, going by the names, 5 of 42 tools delete data and 9 change data; 13 names don't say. From the server's own tool labels and tool names; not verified by us.

- `find-documents` (name suggests: reads): Run queries with filters, projections, and sorting
- `aggregate-data`: Execute aggregation pipelines
- `analyze-query-patterns` (name suggests: reads): Analyze live queries and suggest optimizations
- `analyze-schema` (name suggests: reads): Automatically infer collection schemas
- `bulk-operations`: Perform multiple operations efficiently
- `clear-cache`: Clear memory caches to ensure fresh data
- `collation-query` (name suggests: reads): Find documents with language-specific collation rules
- `compare-schemas`: Compare schemas between two collections
- `connect-mongodb`: Connect to a different MongoDB URI
- `connect-original`: Connect back to the original MongoDB URI used at startup
- `count-documents` (name suggests: reads): Count documents matching specified criteria
- `create-collection` (name suggests: changes): Create new collections with custom options
- `create-database` (name suggests: changes): Create a new database with option to switch to it
- `create-index` (name suggests: changes): Create new indexes for performance optimization
- `create-timeseries` (name suggests: changes): Create time series collections for temporal data
- `create-user` (name suggests: changes): Create new database users with specific roles
- `current-database`: Show the current database context
- `delete-document` (name suggests: deletes): Delete documents matching specified criteria
- `distinct-values`: Extract unique values for any field
- `drop-collection` (name suggests: deletes): Remove collections from the database
- `drop-database` (name suggests: deletes): Drop a database
- `drop-index` (name suggests: deletes): Remove indexes from collections
- `drop-user` (name suggests: deletes): Remove database users
- `explain-query` (name suggests: reads): Analyze query execution plans
- `export-data` (name suggests: reads): Export query results in JSON or CSV format
- `generate-schema-validator`: Generate JSON Schema validators
- `geo-query` (name suggests: reads): Perform geospatial queries with various operators
- `get-stats` (name suggests: reads): Retrieve database or collection statistics
- `gridfs-operation`: Manage large files with GridFS buckets
- `insert-document` (name suggests: changes): Insert one or more documents into collections
- `list-collections` (name suggests: reads): Explore collections in the current database
- `list-connections` (name suggests: reads): View all available MongoDB connection aliases
- `list-databases` (name suggests: reads): View all accessible databases
- `rename-collection` (name suggests: changes): Rename existing collections
- `shard-status` (name suggests: reads): View sharding configuration for databases and collections
- `text-search` (name suggests: reads): Perform full-text search across text-indexed fields
- `transaction`: Execute multiple operations in a single ACID transaction
- `update-document` (name suggests: changes): Update documents matching specified criteria
- `use-database`: Switch to a specific database context
- `validate-collection` (name suggests: reads): Check for data inconsistencies
- `watch-changes`: Monitor real-time changes to collections
- `add-connection-alias` (name suggests: changes): Add a new MongoDB connection alias

## FAQ

### How do I run mongodb-lens?

Use npx -y mongodb-lens with an optional connection string, run the Docker Hub image, or run it from a Node.js clone.

### Can mongodb-lens be made read-only?

Yes. Setting readOnly to true in the config blocks tools and pipeline stages that write, and a read-only database user adds another layer.

### How are destructive operations protected?

The first call returns a 4-digit token that expires after five minutes, and the operation runs only when the token is supplied in a second call.

### Which MongoDB versions are supported?

The latest release targets MongoDB 4.0 and above. Older servers need a 3.x driver or an earlier release such as 8.3.0.

### Is mongodb-lens free?

Yes. mongodb-lens is open source, so you can use and self-host it for free.

### What are the best alternatives to mongodb-lens?

The closest alternatives to mongodb-lens are mongo-mcp, mcp-mongo-server, Mongodb MCP Server, Mongo Scout MCP and MongoDB Read-Only MCP.

## Where this comes from

- Description: written from the project's README.

## Alternatives

- [mongo-mcp](https://ai-powered.com/mcp/mongo-mcp): mongo-mcp is an open-source MCP server for databases.
- [mcp-mongo-server](https://ai-powered.com/mcp/mcp-mongo-server): mcp-mongo-server is an open-source MCP server for databases.
- [Mongodb MCP Server](https://ai-powered.com/mcp/mongodb-mcp-server): Mongodb MCP Server is an open-source MCP server for databases.
- [Mongo Scout MCP](https://ai-powered.com/mcp/mongo-scout-mcp): Mongo Scout MCP is an open-source MCP server for databases.
- [MongoDB Read-Only MCP](https://ai-powered.com/mcp/mongodb-read-only-mcp): MongoDB Read-Only MCP is an open-source MCP server for databases.
- [florentine-ai](https://ai-powered.com/mcp/florentine-ai): florentine-ai is a freemium MCP server for databases.
- [mongodb-atlas-mcp-server](https://ai-powered.com/mcp/mongodb-atlas-mcp-server): mongodb-atlas-mcp-server is an open-source MCP server for databases.
- [MCP Database Server](https://ai-powered.com/mcp/mcp-database-server): MCP Database Server is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/mongodb-lens
