MongoDB MCP server

Enables MongoDB database operations including querying, indexing, and document management through specialized tools for data access and manipulation
Back to servers
Provider
BootcampToProd
Release date
Mar 26, 2025
Language
Java
Stats
1 star

The Mongo MCP Server integrates with MongoDB to provide database operations as callable tools through the Model Context Protocol. It enables AI assistants to interact with MongoDB data, making it perfect for testing with MCP clients like the Claude desktop app.

Installation Requirements

Before installing the Mongo MCP Server, ensure you have:

  • Java 17 or higher
  • Maven 3.6+
  • MongoDB running locally

Setting Up the Server

Install MongoDB

If you don't have MongoDB installed:

  1. Download and install MongoDB from the official website
  2. Start the MongoDB service according to your operating system instructions

Clone and Build the Project

git clone https://github.com/yourusername/mongo-mcp-server.git
cd mongo-mcp-server
mvn clean install

Configure MongoDB Connection

Open the application.properties file in the src/main/resources directory and update MongoDB connection settings if needed:

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=mcpdb

Start the Server

Run the server using Maven:

mvn spring-boot:run

The server will start on port 8080 by default.

Using the Mongo MCP Server

Connecting via an MCP Client

  1. Open your MCP client (like Claude desktop app)
  2. Configure the client to connect to your server at:
    • URL: http://localhost:8080/mcp/v1
    • No authentication required for local testing

Available MongoDB Operations

The server exposes several MongoDB operations as tools:

  • Create document - Insert new documents into a collection
  • Read document - Retrieve documents based on queries
  • Update document - Modify existing documents
  • Delete document - Remove documents from a collection
  • List collections - Show all collections in the database

Example Usage

Here are examples of how to use the tools through an MCP client:

Creating a Document

{
  "collection": "users",
  "document": {
    "name": "John Doe",
    "email": "[email protected]",
    "age": 30
  }
}

Reading Documents

{
  "collection": "users",
  "query": {
    "age": {"$gt": 25}
  }
}

Updating a Document

{
  "collection": "users",
  "filter": {
    "name": "John Doe"
  },
  "update": {
    "$set": {
      "age": 31
    }
  }
}

Deleting a Document

{
  "collection": "users",
  "filter": {
    "email": "[email protected]"
  }
}

Troubleshooting

Common Issues

  • Connection refused error: Ensure MongoDB is running on the configured host and port
  • Authentication failed: Check your MongoDB credentials in application.properties
  • Tool not found: Verify the tool name and parameters match exactly what the server expects

Checking Server Status

To verify the server is running correctly, visit:

http://localhost:8080/actuator/health

This should return a status indicating the server is "UP" and connected to MongoDB.

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