Back to MCP Catalog

MongoDB Lens MCP Server

DatabasesJavaScript
Natural language interface for MongoDB databases
Available Tools

add-connection-alias

Add a new MongoDB connection alias

aggregate-data

Execute aggregation pipelines

analyze-query-patterns

Analyze live queries and suggest optimizations

analyze-schema

Automatically infer collection schemas

bulk-operations

Perform multiple operations efficiently

clear-cache

Clear memory caches to ensure fresh data

collation-query

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

Count documents matching specified criteria

create-collection

Create new collections with custom options

create-database

Create a new database with option to switch to it

create-index

Create new indexes for performance optimization

create-timeseries

Create time series collections for temporal data

create-user

Create new database users with specific roles

current-database

Show the current database context

delete-document

Delete documents matching specified criteria

distinct-values

Extract unique values for any field

drop-collection

Remove collections from the database

MongoDB Lens is a powerful Model Context Protocol server that provides natural language access to MongoDB databases. It enables users to query, analyze, and manage MongoDB databases using conversational language through LLMs like Claude. With MongoDB Lens, you can perform complex database operations including queries, aggregations, schema analysis, index creation, and performance optimization without writing MongoDB syntax. The tool offers comprehensive database management capabilities while incorporating safeguards for destructive operations.

Getting Started with MongoDB Lens

MongoDB Lens is a Model Context Protocol (MCP) server that allows you to interact with MongoDB databases using natural language through LLMs.

Installation Options

You can install MongoDB Lens using npm or Docker:

NPM Installation:

npm install -g mongodb-lens

Docker Installation:

docker pull furey/mongodb-lens

Configuration

MongoDB Lens requires configuration to connect to your MongoDB databases. You can configure it in several ways:

  1. Environment Variables:

    • MONGODB_URI: Your MongoDB connection string
    • MONGODB_DB: Default database to use
    • MCP_PORT: Port for the MCP server (default: 8000)
  2. Configuration File: You can create a configuration file using the provided script:

    npx mongodb-lens-config
    

    This will guide you through creating a configuration with multiple database connections.

  3. Command Line Arguments:

    mongodb-lens --uri mongodb://localhost:27017/mydb --port 8000
    

Running MongoDB Lens

Using NPM:

mongodb-lens

Using Docker:

docker run -p 8000:8000 -e MONGODB_URI=mongodb://host.docker.internal:27017/mydb furey/mongodb-lens

Client Setup

To use MongoDB Lens with your LLM client (like Claude Desktop or Cursor), you need to configure the MCP server in your client settings:

  1. Claude Desktop:

    • Go to Settings > Model Context Protocol
    • Add a new server with:
      • Name: MongoDB Lens
      • URL: http://localhost:8000
  2. Cursor:

    • Open Settings
    • Navigate to AI > Model Context Protocol
    • Add MongoDB Lens as a server

Data Protection

MongoDB Lens includes safety features to protect your data:

  • Confirmation prompts for destructive operations (delete, drop)
  • Read-only mode option for preventing write operations
  • Query limits to prevent excessive data retrieval

Usage Examples

Once connected, you can interact with your MongoDB databases using natural language. Examples:

  • "Show me all collections in the current database"
  • "Find the top 5 users by order count"
  • "Create an index on the email field in the users collection"
  • "Analyze the schema of the products collection"
  • "Show me query performance statistics for the last hour"

MongoDB Lens will translate these natural language requests into the appropriate MongoDB operations and return the results.

Related MCPs

Milvus Vector Database
DatabasesPython

Connect to Milvus vector database for semantic search and vector operations

MotherDuck DuckDB
DatabasesPython

SQL analytics with DuckDB and MotherDuck for AI assistants

Alibaba Cloud Tablestore
DatabasesJava, Python

Connect to Alibaba Cloud Tablestore for vector search and RAG applications

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.