Skip to main content
Glama

MongoDB MCP Server

by jonfreeland

MongoDB MCP Server

A Model Context Protocol server that provides read-only access to MongoDB databases through standardized MCP tools and resources.

Overview

This MongoDB MCP server enables AI assistants to directly query and analyze MongoDB databases without write access, maintaining data safety while providing powerful data exploration capabilities.

Features

MongoDB Operations

  • Database Exploration: List databases and collections
  • Schema Discovery: Infer collection schemas from sample documents
  • Querying: Execute MongoDB queries with filtering, projection, sorting, and limiting
  • Aggregation: Run read-only aggregation pipelines with safety validation
  • Text Search: Perform full-text search on collections with text indexes
  • Geospatial Queries: Find locations near points, within polygons, or intersecting geometries
  • Document Operations: Count documents, sample random documents, find documents by IDs
  • Data Analysis: Get collection statistics, index information, and query execution plans
  • Performance Insights: Examine query execution plans to optimize performance
  • Data Exploration: Get distinct values, field distributions, and data samples
  • Format Conversion: Export query results as JSON or CSV formats

Enhanced Capabilities

  • Schema Inference: Automatically detect data types and structure from documents
  • Visualization Hints: Intelligent suggestions for data visualization based on result content
  • Safety Validation: Prevents write operations in aggregation pipelines
  • Example-Rich Documentation: Each tool includes detailed examples in its description

Requirements

Environment Variables

  • MONGODB_URI (required): MongoDB connection string with authentication if needed
  • MONGODB_DEFAULT_DATABASE (optional): Default database name when not specified in queries

Prerequisites

  • Network access to MongoDB server
  • Authentication credentials if required by MongoDB instance
  • Appropriate read permissions on target databases

Installation

Building from Source

Install dependencies:

npm install

Build the server:

npm run build

For development with auto-rebuild:

npm run watch

Integration with Claude Desktop

To use with Claude Desktop, add the server configuration:

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

{ "mcpServers": { "mongodb": { "command": "/path/to/mongodb-server/build/index.js", "env": { "MONGODB_URI": "mongodb://username:password@hostname:port/database", "MONGODB_DEFAULT_DATABASE": "your_default_db" } } } }

Integration with Claude Web

For Claude Web via the MCP Chrome extension, add configuration to Cline MCP settings:

{ "mcpServers": { "mongodb": { "command": "node", "args": ["/path/to/mongodb-server/build/index.js"], "env": { "MONGODB_URI": "mongodb://username:password@hostname:port/database", "MONGODB_DEFAULT_DATABASE": "your_default_db" } } } }

Integration with Claude Code

To use with Claude Code, use the following commands:

cd /path/to/my/project claude mcp add mongo-server /path/to/mongodb-mcp/build/index.js -e "MONGODB_URI=mongodb://user@password:27017/dbname?authSource=authDbName" -e MONGO_DEFAULT_DATABASE=dbname

Make sure to replace the placeholders with your actual MongoDB connection string and default database name.

If configured correctly, you should see the following when you run claude:

╭───────────────────────────────────────────────────────╮ │ ✻ Welcome to Claude Code research preview! │ │ │ │ /help for help │ │ │ │ cwd: <path-to-project-directory> │ │ │ │ ─────────────────────────────────────────────────── │ │ │ │ MCP Servers: │ │ │ │ • mongo-server connected │ ╰───────────────────────────────────────────────────────╯

If you run into issues, see the Claude Code documentation.

Security Considerations

  • This server provides read-only access by design
  • Connection strings may contain sensitive authentication information
  • Store connection strings securely in environment variables
  • Use a MongoDB user with read-only permissions

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector, which is available as a package script:

npm run inspector

The Inspector will provide a URL to access debugging tools in your browser.

Deploy Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

提供对 MongoDB 数据库的只读访问的模型上下文协议服务器,使 AI 助手能够直接查询和分析 MongoDB 数据,同时保证数据安全。

  1. 概述
    1. 特征
      1. MongoDB 操作
      2. 增强功能
    2. 要求
      1. 环境变量
      2. 先决条件
    3. 安装
      1. 从源代码构建
      2. 与 Claude Desktop 集成
      3. 与 Claude Web 集成
      4. 与 Claude Code 集成
    4. 安全注意事项
      1. 调试

        Related MCP Servers

        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute read-only queries.
          Last updated -
          8
          391
          262
          MIT License
          • Apple
        • -
          security
          A
          license
          -
          quality
          A Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.
          Last updated -
          181
          1
          MIT License
          • Apple
        • -
          security
          A
          license
          -
          quality
          A Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.
          Last updated -
          181
          MIT License
          • Apple
        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol server that enables AI models to interact with both MySQL and MongoDB databases through a standardized interface, supporting comprehensive database operations including queries, schema management, and CRUD operations.
          Last updated -
          14
          6
          MIT License

        View all related MCP servers

        MCP directory API

        We provide all the information about MCP servers via our MCP API.

        curl -X GET 'https://glama.ai/api/mcp/v1/servers/jonfreeland/mongodb-mcp'

        If you have feedback or need assistance with the MCP directory API, please join our Discord server