mongodb-mcp-legacy
A Model Context Protocol (MCP) server for old MongoDB versions (3.2+) that the official MongoDB MCP Server does not support. Works with Claude Code, Codex, Cursor, and any MCP-compatible client.
Why This Project?
The official mongodb-mcp-server uses a modern MongoDB Node.js driver that does not work with MongoDB 3.x or 4.x. If you're running a legacy MongoDB instance (3.2 -- 4.x) and want to connect it to AI tools like Claude Code or Cursor via MCP, you're stuck.
mongodb-mcp-legacy solves this by using the mongodb@3.7.4 driver, which supports MongoDB 3.2 and above.
| mongodb-mcp-legacy | Official mongodb-mcp-server | |
|---|---|---|
| MongoDB version | 3.2+ | 6.0+ (modern driver) |
| Node.js version | >= 16 | >= 20.19 |
| Operations | Read-only | Read / Write / Atlas API |
| Setup complexity | Zero config | Multiple config options |
Features
- Legacy MongoDB support -- works with MongoDB 3.2, 3.4, 3.6, 4.0, 4.2, 4.4, and above
- Read-only operations -- safe by design, no write/update/delete tools
- MCP compatible -- works with any MCP client (Claude Code, Codex, Cursor, Windsurf, VS Code, etc.)
- Zero config -- just provide a
MONGODB_URIand go - Lightweight -- single file, minimal dependencies
Quick Start
Prerequisites
- Node.js >= 16.0.0
- A MongoDB instance (version 3.2 or above)
Installation
Run directly with npx (no install needed):
npx mongodb-mcp-legacy
Or install globally:
npm install -g mongodb-mcp-legacy
Configuration
The server reads the MONGODB_URI environment variable to connect. If not set, it defaults to mongodb://localhost:27017.
Claude Code
Add to your Claude Code config (~/.claude.json):
{
"mcpServers": {
"mongodb-legacy": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mongodb-mcp-legacy"],
"env": {
"MONGODB_URI": "mongodb://username:password@host:port/database"
}
}
}
}
Codex
Add to your Codex MCP config:
{
"mcpServers": {
"mongodb-legacy": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mongodb-mcp-legacy"],
"env": {
"MONGODB_URI": "mongodb://username:password@host:port/database"
}
}
}
}
Cursor
Add to your Cursor MCP settings:
{
"mcpServers": {
"mongodb-legacy": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mongodb-mcp-legacy"],
"env": {
"MONGODB_URI": "mongodb://username:password@host:port/database"
}
}
}
}
Other MCP Clients
Any MCP client that supports stdio transport will work. Set the command to npx -y mongodb-mcp-legacy and pass MONGODB_URI as an environment variable.
Local Development
MONGODB_URI="mongodb://localhost:27017/mydb" node index.js
Available Tools
| Tool | Description | Parameters |
|---|---|---|
list_databases | List databases (falls back to current database without admin perms) | (none) |
list_collections | List all collections in a database | database (optional) |
execute_query | Execute a read-only find query | database (optional), collection (required), query (optional JSON string), limit (optional, default 10) |
count_documents | Count documents matching a filter | database (optional), collection (required), query (optional JSON string) |
Examples
list_databases()
list_collections({ database: "mydb" })
execute_query({ collection: "users", query: '{"status": "active"}', limit: 5 })
count_documents({ collection: "orders", query: '{"total": {"$gt": 100}}' })
Development
git clone https://github.com/maximuszeng/mongodb-mcp-legacy.git
cd mongodb-mcp-legacy
pnpm install
Note: Running the server only requires Node.js >= 16, but development and testing require Node.js >= 18 (due to pnpm and vitest).
Run the server locally:
MONGODB_URI="mongodb://localhost:27017/mydb" pnpm start
Lint and format:
pnpm run lint
pnpm run format
Run tests:
pnpm test
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.