MongoDB Database MCP server

Provides a bridge between MongoDB databases and natural language, enabling collection listing, document querying, record manipulation, and aggregate operations without writing complex queries.
Back to servers
Provider
Manpreet Singh
Release date
Mar 24, 2025
Language
TypeScript

The MCP Database Server allows Large Language Models (LLMs) to interact with various databases through natural language. It currently supports MongoDB with plans to expand to PostgreSQL, CockroachDB, Redis, and others, enabling you to perform database operations simply by describing what you want in plain English.

Prerequisites

  • Node.js v20.12.2 or higher
  • Database (currently MongoDB)
  • Claude Desktop Application

Installation

  1. Clone the repository:
git clone https://github.com/manpreet2000/mcp-database-server.git
cd mcp-database-server
  1. Install dependencies:
npm install
  1. Build the TypeScript code:
npm run build

Configuration

You need to configure your database connection in your Claude Desktop configuration file:

MacOS

~/Library/Application\ Support/Claude/claude_desktop_config.json

Windows

%APPDATA%/Claude/claude_desktop_config.json

Add the following configuration to your claude_desktop_config.json:

{
  "mcpServers": {
    "database": {
      "command": "/path/to/node",
      "args": ["/path/to/mcp-database/dist/index.js"],
      "env": {
        "MONGODB_URI": "your-mongodb-connection-string"
      }
    }
  }
}

Be sure to replace:

  • /path/to/node with your Node.js executable path or just use node
  • /path/to/mcp-database with the absolute path to this repository
  • your-mongodb-connection-string with your MongoDB connection URL

Usage Examples

Querying Your Database

You can interact with your database by asking Claude questions in natural language:

  1. List all collections in your database:
Can you show me all the collections in my database?
  1. Get specific records from a collection:
Give me 2 records from the chargers collection
  1. Query with filters:
Show me all documents in the users collection where status is active
  1. Insert a document:
Add a new user to the users collection with name John and email [email protected]
  1. Delete a document:
Remove the user with email [email protected] from the users collection
  1. Aggregate data:
Show me the total count of users by status in the users collection

Available Tools

MongoDB Operations

The server supports these MongoDB operations:

  • getCollections: Lists all collections in the connected database
  • getCollection: Retrieves documents with filtering and projection options
  • insertOne: Adds a new document to a collection
  • deleteOne: Removes a document from a collection
  • aggregate: Executes aggregation pipelines

Query Parameters

When retrieving documents, you can specify:

  • Collection name
  • Document limit (default: 10, max: 1000)
  • Query filters
  • Field projections to include/exclude specific fields

Aggregation

For data analysis, you can run aggregation pipelines with:

  • Collection name
  • Pipeline stages
  • Optional aggregation options

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later