Home / MCP / Database MCP Server

Database MCP Server

Provides natural language access to MongoDB via an MCP server with CRUD and aggregation capabilities.

typescript
Installation
Add the following to your MCP client configuration file.

Configuration

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

You have an MCP server that enables large language models to interact with MongoDB using natural language, with the ability to list collections, query and modify documents, and run aggregations. This makes it easy to ask your model to perform common database tasks without writing SQL or MongoDB queries directly.

How to use

You connect your MCP client to the database server to enable natural language interactions with MongoDB. You can perform the following operations through simple, human language prompts:

How to install

Prerequisites and environment setup ensure you can run the MCP server locally and connect to MongoDB.

Step 1: Install prerequisites and verify versions - Node.js v20.12.2 or higher - MongoDB instance accessible to the MCP server - Claude Desktop Application (for configuration and workflow integration)

Step 2: Clone the project and install dependencies
```
git clone https://github.com/manpreet2000/mcp-database-server.git
cd mcp-database-server
npm install
Step 3: Build the TypeScript sources
```
npm run build

Configuration

Configure your Claude Desktop client to run the MCP server locally and connect to MongoDB. Use the following example configuration snippet to set up the server integration.

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

Security and best practices

Never expose your MongoDB connection string publicly. Use environment variables for sensitive information and follow database-specific security best practices.

Notes and troubleshooting

If you encounter connection issues, verify that the MongoDB URI is correct and that the MongoDB instance allows connections from the MCP server host. Check that the server process has the necessary permissions to access the specified dist/index.js and that Node.js is available at the path you configured.

Available tools

getCollections

Lists all collections in the connected database.

getCollection

Retrieves documents from a specific collection with optional query, limit, and projection parameters.

insertOne

Inserts a single document into a specified collection.

deleteOne

Deletes a single document from a collection based on a query.

aggregate

Executes an aggregation pipeline on a collection with optional options.