MCP Connector

Connect LLMs to MongoDB Databases

MongoDB MCP Server lets LLMs inspect schemas and run MongoDB queries, with read-only mode and smart ObjectId handling.


90
Spark score
out of 100
Updated 6 months ago
Version 2.0.2
Models
universal

Add to Favorites

Why it matters

Enable Large Language Models to interact with MongoDB databases, allowing for schema analysis and data operations through a standardized interface.

Outcomes

What it gets done

01

Execute MongoDB queries and aggregation pipelines

02

Analyze collection schemas and retrieve server information

03

Perform data manipulation tasks like updates and inserts

04

Facilitate LLM-driven data exploration and analysis

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-mongodb | bash

Capabilities

Tools your agent gets

query

Execute MongoDB queries with optional execution plan analysis

aggregate

Run aggregation pipelines with optional query planning

count

Count documents matching criteria

update

Modify documents in collections

insert

Add new documents to collections

createIndex

Create collection indexes

serverInfo

Retrieve MongoDB server details and debugging information

Overview

MongoDB MCP Server

MongoDB MCP Server gives an LLM schema inference and query/aggregation access to MongoDB, with optional write operations and a read-only safety mode. Use it when an LLM needs to inspect a MongoDB database's schema or run queries, with read-only mode for safer exploratory use.

What it does

MongoDB MCP Server is an MCP server that lets an LLM interact with MongoDB databases through a standardized interface, inspecting collection schemas and executing MongoDB operations, queries, aggregations, and, when not restricted, writes, directly against a live database.

When to use - and when NOT to

Use it when you want an LLM to explore a MongoDB database's structure and run queries or aggregation pipelines against it, with optional write access for inserts, updates, and index creation. It infers collection schemas automatically from document samples rather than requiring a predefined schema, and it can convert string IDs to MongoDB ObjectIds automatically, never, or on-demand depending on configuration. For safer exploratory use, connect with --read-only, or MCP_MONGODB_READONLY=true, to block write operations entirely and query using a secondary read preference, rather than trusting the LLM with write access by default.

Capabilities

Schema inference automatically detects a collection's structure from sampled documents, so there's no need to hand-maintain a schema definition. Query and aggregation support covers full MongoDB query syntax and aggregation pipelines, with optional explain plans for understanding query execution. Smart ObjectId handling offers configurable auto, none, or force modes for converting string values to ObjectIds. Write operations, insert, update, and index creation, are available unless read-only mode is active, which blocks them outright. Collection name completion helps an LLM auto-complete collection names during interaction.

How to install

Run it directly with npx, pointing at your MongoDB connection URI:

npx -y mcp-mongo-server mongodb://localhost:27017/database

Add --read-only to restrict it to read operations:

npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read-only

Configuration can also go through environment variables: MCP_MONGODB_URI for the connection string, and MCP_MONGODB_READONLY set to "true" for read-only mode. The project's own documentation covers integration with Claude Desktop, Windsurf, Cursor, and Docker, plus a full list of available tools, separately from this overview.

Who it's for

Developers who want an LLM to inspect and query a MongoDB database's structure and data directly, with the option to lock it to read-only access for safer exploratory use. It is released under the MIT License, distributed as the mcp-mongo-server npm package, and its own documentation includes dedicated guides for integration, the full tool list, and local development setup.

Source README

MCP MongoDB Server


NPM Version
NPM Downloads
NPM License
smithery badge
Verified on MseeP

A Model Context Protocol server that enables LLMs to interact with MongoDB databases. This server provides capabilities for inspecting collection schemas and executing MongoDB operations through a standardized interface.

Demo

MCP MongoDB Server Demo | Claude Desktop

Key Features

  • Smart ObjectId Handling - Configurable auto/none/force modes for string-to-ObjectId conversion
  • Read-Only Mode - Protection against write operations, uses secondary read preference
  • Schema Inference - Automatic collection schema detection from document samples
  • Query & Aggregation - Full MongoDB query and aggregation pipeline support with optional explain plans
  • Write Operations - Insert, update, and index creation (when not in read-only mode)
  • Collection Completions - Auto-complete collection names for LLM integration

Installation

npx -y mcp-mongo-server mongodb://localhost:27017/database

Usage

# Start server with MongoDB URI
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database

# Connect in read-only mode
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read-only

Environment Variables

Variable Description
MCP_MONGODB_URI MongoDB connection URI
MCP_MONGODB_READONLY Enable read-only mode ("true")

Documentation

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.