# mongo-mcp

> MCP Server

This repository provides a Model Context Protocol (MCP) server, enabling Large Language Models to interact with MongoDB databases using natural language for querying, schema inspection, and data management.

## Overview

- **Category:** Database
- **Language:** TypeScript
- **Stars:** 175
- **Forks:** 16
- **Owner:** QuantGeekDev
- **GitHub:** https://github.com/QuantGeekDev/mongo-mcp
- **Created:** 2024-12-05T23:12:54+00:00
- **Updated:** 2025-03-28T23:46:23+00:00
- **Source:** https://model-context-protocol.com/servers/mongo-db-model-context-protocol-server

## Setup

## Setup

1.  Find your mongodb connection url and add the configuration to your Claude Desktop config file.
2.  **MacOS**: `~/Library/Application\ Support/Claude/claude_desktop_config.json`
3.  **Windows**: `%APPDATA%/Claude/claude_desktop_config.json`

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

### Installing via Smithery

To install MongoDB MCP Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/mongo-mcp):

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

### Prerequisites

- Node.js 18+
- npx
- Docker and Docker Compose (for local sandbox testing only)
- MCP Client (Claude Desktop App for example)

### Test Sandbox Setup

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

1. Start MongoDB using Docker Compose:

```bash
docker-compose up -d
```

2. Seed the database with test data:

```bash
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:

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

## Tools

## Available Tools

1.  Collection schema inspection (Allows inspection of collection schemas).
2.  Document querying and filtering (Enables querying and filtering of documents).
3.  Index management (Provides tools for managing indexes).
4.  Document operations (insert, update, delete) (Supports document operations like insert, update, and delete).
5.  `find` (Query documents with filtering and projection)
6.  `listCollections` (List available collections)
7.  `insertOne` (Insert a single document)
8.  `updateOne` (Update a single document)
9.  `deleteOne` (Delete a single document)
10. `createIndex` (Create a new index)
11. `dropIndex` (Remove an index)
12. `indexes` (List indexes for a collection)
