MongoDB

by 1rb

9 stars
Not rated
GitHub

About

Enables interaction with MongoDB databases through TypeScript and the MongoDB driver, providing seamless integration of MongoDB operations into workflows.

Details

Author
1rb
Repository
1RB/mongo-mcp
GitHub stars
9
Categories
Database, Other, Productivity, Design, Developer Tools, AI, Infrastructure, Frontend
Tags
#integration, #mongodb, #sql-agent, #data-analysis

- πŸ” Collection schema inspection
- πŸ“Š Document querying and filtering
- πŸ“ˆ Index management
- πŸ“ Document operations (insert, update, delete)
- πŸ”’ Secure database access through connection strings
- πŸ“‹ Comprehensive error handling and validation

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MongoDB
    Command (node, npx, python, etc.) npx
    Arguments
    • Argument 1 mongo-mcp
    • Argument 2 mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

To get started, find your MongoDB connection URL and add this configuration to your Claude Desktop config file:

MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
      ]
    }
  }
}

Smithery.ai is a registry platform for MCP servers that simplifies discovery and installation. To install MongoDB MCP Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install mongo-mcp --client claude

If you don't have a MongoDB server to connect to and want to create a sample sandbox, follow these steps:

1. Start MongoDB using Docker Compose:

docker-compose up -d

2. Seed the database with test data:

npm run seed

Add this configuration to your Claude Desktop config file:

MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

npm install

You can deploy this MCP server in several ways:

- Locally via npx (as shown in Quick Start)
- As a global npm package: npm install -g @coderay/mongo-mcp-server
- In a Docker container (see Dockerfile in the repository)
- As a service on platforms like Heroku, Vercel, or AWS

If you encounter issues:
- Review the MCP Documentation
- Submit an issue on our GitHub repository

listCollections

Lists available collections in the database.

find

Queries documents with filtering and projection.

insertOne

Inserts a single document into a collection.

updateOne

Updates a single document in a collection.

deleteOne

Deletes a single document from a collection.

createIndex

Creates a new index on a collection.

dropIndex

Removes an index from a collection.

indexes

Lists indexes for a collection.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mongodb": {
            "env": {},
            "args": [
                "mongo-mcp",
                "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
            ],
            "command": "npx"
        }
    }
}

Linux

{
    "env": [],
    "args": [
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
    ],
    "command": "npx"
}

Macos

{
    "env": [],
    "args": [
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
    ],
    "command": "npx"
}

Windows

{
    "env": [],
    "args": [
        "/c",
        "npx",
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
    ],
    "command": "cmd"
}

πŸ—„οΈ MongoDB MCP Server for LLMS

Node.js 18+
License: MIT
npm version
smithery badge

A Model Context Protocol (MCP) server that enables LLMs to interact directly with MongoDB databases. Query collections, inspect schemas, and manage data seamlessly through natural language.

πŸ“š What is Model Context Protocol (MCP)?

The Model Context Protocol (MCP) is an open standard developed by Anthropic that creates a universal way for AI systems to connect with external data sources and tools. MCP establishes a standardized communication channel between:

- MCP Clients: AI assistants like Claude that consume data (e.g., Claude Desktop, Cursor.ai)
- MCP Servers: Services that expose data and functionality (like this MongoDB server)

Key benefits of MCP:
- Universal Access: Provides a single protocol for AI assistants to query data from various sources
- Standardized Connections: Handles authentication, usage policies, and data formats consistently
- Sustainable Ecosystem: Promotes reusable connectors that work across multiple LLM clients

✨ Features

- πŸ” Collection schema inspection
- πŸ“Š Document querying and filtering
- πŸ“ˆ Index management
- πŸ“ Document operations (insert, update, delete)
- πŸ”’ Secure database access through connection strings
- πŸ“‹ Comprehensive error handling and validation

πŸ“‹ Prerequisites

Before you begin, ensure you have:

- Node.js (v18 or higher)
- MongoDB instance (local or remote)
- An MCP client like Claude Desktop or Cursor.ai

You can verify your Node.js installation by running:

node --version  # Should show v18.0.0 or higher

πŸš€ Quick Start

To get started, find your MongoDB connection URL and add this configuration to your Claude Desktop config file:

MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
      ]
    }
  }
}

Installing via Smithery

Smithery.ai is a registry platform for MCP servers that simplifies discovery and installation. To install MongoDB MCP Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install mongo-mcp --client claude

Cursor.ai Integration

To use MongoDB MCP with Cursor.ai:

1. Open Cursor.ai and navigate to Settings > Features
2. Look for "MCP Servers" in the features panel
3. Add a new MCP server with the following configuration:
- Name: mongodb
- Command: npx
- Args: mongo-mcp mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin

Note: Cursor currently supports MCP tools only in the Agent in Composer feature.

Test Sandbox Setup

If you don't have a MongoDB server to connect to and want to create a sample sandbox, follow these steps:

1. Start MongoDB using Docker Compose:

docker-compose up -d

2. Seed the database with test data:

npm run seed

Configure Claude Desktop

Add this configuration to your Claude Desktop config file:

MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

Local Development Mode:

{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": [
        "dist/index.js",
        "mongodb://root:example@localhost:27017/test?authSource=admin"
      ]
    }
  }
}

Test Sandbox Data Structure

The seed script creates three collections with sample data:

Users

- Personal info (name, email, age)
- Nested address with coordinates
- Arrays of interests
- Membership dates

Products

- Product details (name, SKU, category)
- Nested specifications
- Price and inventory info
- Tags and ratings

Orders

- Order details with items
- User references
- Shipping and payment info
- Status tracking

🎯 Example Prompts

Try these prompts with Claude to explore the functionality:

Basic Operations

"What collections are available in the database?"
"Show me the schema for the users collection"
"Find all users in San Francisco"

Advanced Queries

"Find all electronics products that are in stock and cost less than $1000"
"Show me all orders from the user john@example.com"
"List the products with ratings above 4.5"

Index Management

"What indexes exist on the users collection?"
"Create an index on the products collection for the 'category' field"
"List all indexes across all collections"

Document Operations

"Insert a new product with name 'Gaming Laptop' in the products collection"
"Update the status of order with ID X to 'shipped'"
"Find and delete all products that are out of stock"

πŸ“ Available Tools

The server provides these tools for database interaction:

Query Tools

- listCollections: Lists available collections in the database
- find: Queries documents with filtering and projection
- insertOne: Inserts a single document into a collection
- updateOne: Updates a single document in a collection
- deleteOne: Deletes a single document from a collection

Index Tools

- createIndex: Creates a new index on a collection
- dropIndex: Removes an index from a collection
- indexes: Lists indexes for a collection

πŸ› οΈ Development

This project is built with:

- TypeScript for type-safe development
- MongoDB Node.js driver for database operations
- Zod for schema validation
- Model Context Protocol SDK for server implementation

To set up the development environment:

```bash

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.