---
title: "MongoDB MCP Server Setup Guide and Schema"
slug: "mongodb"
category: "databases"
package: "mongodb-mcp-server"
transport: "stdio"
canonical: "https://mcp-codex.com/servers/mongodb"
source: "MCP Codex (https://mcp-codex.com)"
dateModified: "2026-09-28"
---

# MongoDB MCP Server

> Connect AI agents to MongoDB for document queries and collection management.

## Overview
Enables AI agents to interact with MongoDB databases: list collections, query documents, aggregate pipelines, and inspect schemas. Supports both local MongoDB instances and Atlas cloud deployments.

## Quick Install
```bash
npx -y mongodb-mcp-server@3.0.5
```

## Environment Variables

| Variable | Description | Required |
| :--- | :--- | :--- |
| `MONGODB_URI` | MongoDB connection string | **Yes** |

## Client Configurations

### Claude Desktop (`claude_desktop_config.json`)
```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-mongodb"
      ],
      "env": {
        "MONGODB_URI": "mongodb://localhost:27017/mydb"
      }
    }
  }
}
```

### Cursor (`mcp.json`)
```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-mongodb"
      ],
      "env": {
        "MONGODB_URI": "mongodb://localhost:27017/mydb"
      }
    }
  }
}
```

### OpenAI Codex CLI (`~/.codex/config.toml`)
```toml
[mcp_servers.mongodb]
command = "npx"
args = ["-y", "mcp-server-mongodb"]

[mcp_servers.mongodb.env]
MONGODB_URI = "mongodb://localhost:27017/mydb"
```

## Available Tools (6)

- `find`
- `aggregate`
- `insertOne`
- `updateOne`
- `deleteOne`
- `listCollections`

## Documentation & Links
- Canonical Web Page: https://mcp-codex.com/servers/mongodb
- Weekly Protocol Changelog: https://mcp-codex.com#newsletter
- GitHub Repository: https://github.com/mongodb-js/mongodb-mcp-server
- Setup Tutorial Guide: https://mcp-codex.com/articles/mongodb-mcp-server-guide

