Skip to main content
Glama

MCP MongoDB Server

by Dwhyte

MCP MongoDB Server

An MCP (Model Context Protocol) server that provides tools to interact with MongoDB databases, specifically designed to query user collections.

Features

  • Query Users: Search and filter users with MongoDB queries
  • Get User by ID: Retrieve specific users by their ID
  • Count Users: Get total count of users with optional filtering
  • Flexible Filtering: Support for MongoDB query operators
  • Sorting and Projection: Advanced query capabilities

Prerequisites

  • Node.js 18+
  • MongoDB instance (local or cloud)
  • TypeScript knowledge

Installation

  1. Install dependencies:
    npm install
  2. Set up environment variables:
    cp .env.example .env
    Edit .env with your MongoDB connection details:
    MONGODB_URI=mongodb://localhost:27017 MONGODB_DB_NAME=your_database_name
  3. Build the project:
    npm run build

Usage

Starting the Server

npm start

Or for development with auto-reload:

npm run dev

Available Tools

1. query_users

Query users with optional filters, sorting, and projection.

Parameters:

  • filter (object, optional): MongoDB filter object
  • limit (number, optional): Maximum results (default: 10)
  • sort (object, optional): Sort criteria
  • projection (object, optional): Fields to include/exclude

Example:

{ "filter": {"age": {"$gte": 25}}, "limit": 5, "sort": {"name": 1}, "projection": {"_id": 1, "name": 1, "email": 1} }
2. get_user_by_id

Retrieve a specific user by their ID.

Parameters:

  • userId (string, required): The user ID to search for

Example:

{ "userId": "507f1f77bcf86cd799439011" }
3. count_users

Count total users with optional filtering.

Parameters:

  • filter (object, optional): MongoDB filter object

Example:

{ "filter": {"status": "active"} }

MongoDB Connection

The server supports various MongoDB connection types:

Local MongoDB

MONGODB_URI=mongodb://localhost:27017 MONGODB_DB_NAME=myapp

MongoDB with Authentication

MONGODB_URI=mongodb://username:password@localhost:27017/myapp MONGODB_DB_NAME=myapp

MongoDB Atlas

MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/myapp MONGODB_DB_NAME=myapp

Development

Project Structure

├─
-
security - not tested
F
license - not found
-
quality - not tested

An MCP server that provides tools to query and interact with MongoDB user collections, supporting filtering, sorting, and retrieval operations.

  1. Features
    1. Prerequisites
      1. Installation
        1. Usage
          1. Starting the Server
          2. Available Tools
        2. MongoDB Connection
          1. Local MongoDB
          2. MongoDB with Authentication
          3. MongoDB Atlas
        3. Development
          1. Project Structure

        Related MCP Servers

        • -
          security
          A
          license
          -
          quality
          Full featured MCP Server for MongoDB database analysis.
          Last updated -
          334
          108
          JavaScript
          MIT License
          • Apple
        • -
          security
          A
          license
          -
          quality
          An MCP server that enables users to create and manage MongoDB Atlas clusters, users, and network access through natural language commands.
          Last updated -
          74
          10
          JavaScript
          MIT License
          • Apple
          • Linux
        • -
          security
          A
          license
          -
          quality
          An MCP server that enables large language models to interact directly with MongoDB databases, allowing them to query collections, inspect schemas, and manage data through natural language.
          Last updated -
          1,734
          MIT License
          • Apple
        • -
          security
          F
          license
          -
          quality
          Allows interaction with MongoDB collections and documents through standardized MCP requests, supporting operations like listing collections, reading documents with filtering, and executing structured queries.
          Last updated -
          JavaScript

        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/Dwhyte/mcp-mongodb'

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