The MongoDB MCP Server enables Claude Code to access and manage MongoDB databases through natural language commands. It provides:
Core Database Operations:
User Management: Find master users by platform ID, email, account ID, or user ID with case-insensitive search
Invoice Management: Search and retrieve invoices by account ID or invoice ID
Connection Health: Check MongoDB connection status and health
Key Features:
Flexible configuration via command-line arguments, environment variables, config files, or .mcp.json
Graceful error handling when database is unavailable
Cross-platform compatibility with local and remote MongoDB instances
Multiple installation options (mcp add, npm, GitHub, or local clone)
Provides basic connectivity and health check capabilities for MongoDB databases, allowing verification of database connection status, version, and uptime
MongoDB MCP Server
A Model Context Protocol (MCP) server that provides MongoDB database access for Claude Code. This server allows you to query MongoDB databases directly from Claude with configurable connection parameters.
Features
Master User Management: Find users by platform ID, email, account ID, or user ID
Invoice Management: Search and retrieve invoices by account ID or invoice ID
Connection Health: Check MongoDB connection status and health
Flexible Configuration: Support for command-line arguments, environment variables, and config files
Error Handling: Graceful fallback when database is unavailable
Installation
Option 1: Using mcp add (Recommended)
Then edit the generated .mcp.json
to add your connection parameters:
Option 2: Install from npm (coming soon)
Option 3: Install from GitHub
Option 4: Clone and install locally
Usage
Method 1: Configure via .mcp.json (Recommended)
Add the server to your .mcp.json
file in any project directory:
Or with environment variables:
Method 2: Install locally in project
Clone this repo into your project or install as dependency
Create a
settings.json
file in the project root:
Add to your
.mcp.json
:
Configuration Priority
The server accepts configuration in the following priority order:
Command-line arguments (highest priority)
# Full format mongo-mcp-server --mongo-uri mongodb://localhost:27017 --database mydb # Short format mongo-mcp-server --uri mongodb://localhost:27017 --db mydb # Single URI format (with database in path) mongo-mcp-server mongodb://localhost:27017/mydbEnvironment variables
export MONGODB_URI="mongodb://localhost:27017" export MONGODB_DATABASE="mydb" mongo-mcp-serversettings.json file
{ "mongodb": { "uri": "mongodb://localhost:27017", "database": "mydb" } }Default values (lowest priority)
URI:
mongodb://localhost:27017
Database:
mcpserver
Available Tools
Connection Management
check_connection
: Check if MongoDB connection is active and healthy
Master User Tools
find-master-user-by-platform-id
: Find master user by platform ID (case-insensitive search)Parameters:
platformId
(string),limit
(number, default: 10)
find-master-user-by-email
: Find master user by email (case-insensitive search)Parameters:
email
(string),limit
(number, default: 10)
find-master-user-by-id
: Find a specific master user by their IDParameters:
id
(string)
find-master-user-by-account-id
: Find master user by account ID (case-insensitive search)Parameters:
accountId
(string),limit
(number, default: 10)
Invoice Tools
find-invoices-by-account-id
: Find invoices by account ID (case-insensitive search)Parameters:
accountId
(string),limit
(number, default: 10)
find-invoice-by-id
: Find a specific invoice by its IDParameters:
id
(string)
Quick Start with mcp add
Navigate to any directory where you want to use MongoDB tools:
cd C:\AI\mongo_testAdd the MongoDB MCP server:
mcp add https://github.com/sergei-tofu-fedorov/mongo_mcp.gitEdit the generated
.mcp.json
file to add your MongoDB connection:{ "mcpServers": { "mongo_mcp": { "command": "npx", "args": [ "mongo-mcp-server", "mongodb://your-host:27017/your-database" ] } } }Start Claude Code:
claude-codeUse MongoDB tools directly in Claude:
find master user by email john@example.com find invoices by account 2djcl2neh9-0f9f3bd0e check mongodb connection status
Example Usage in Claude Code
Once configured, you can use these tools directly in Claude Code:
Development
Requirements
Node.js >= 18.0.0
MongoDB instance (local or remote)
Running in Development
Testing with Different Configurations
Troubleshooting
Connection Issues
Verify MongoDB is running and accessible
Check firewall settings and network connectivity
Ensure the URI format is correct:
mongodb://host:port
ormongodb+srv://cluster.example.com
Validate database name and permissions
Permission Issues
Ensure the MongoDB user has read permissions on the target database
Check that the user can access the required collections
MCP Server Issues
Verify Claude Code can find the server executable
Check the
.mcp.json
configuration syntaxLook for error messages in Claude Code's output
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Tools
Enables interaction with MongoDB databases through the Model Context Protocol. Provides basic database connectivity checking and status monitoring capabilities.