legacy-mongodb-mcp
Provides read-only tools to interact with legacy MongoDB databases (versions < 4.0), including querying, aggregation, schema inference, index inspection, and data export.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@legacy-mongodb-mcplist all databases"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Legacy MongoDB MCP Server
A Model Context Protocol (MCP) server specifically designed for legacy MongoDB instances (versions < 4.0).
Overview
Modern MongoDB tools often drop support for older versions of the database. This project aims to bridge that gap by providing an MCP interface for legacy MongoDB deployments, allowing AI models to interact with historical data stored in older systems.
Related MCP server: MongoDB MCP Server
Current Status
Focus: Strictly read-only operations.
This project enforces read-only access to ensure data safety when inspecting legacy production systems.
🔒 Read-Only Enforcement
No
connecttool exposed - Connection is established at startup via environment variableNo write operations - All tools are read-only by design
Aggregation restrictions -
$outand$mergestages are blockedIndex check mode - Optional enforcement to reject queries without index usage
Response limits - Configurable limits on documents and bytes per query
Available Tools
Tool | Description |
| List all databases in the MongoDB instance |
| List all collections in a database |
| Run a find query against a collection |
| Count documents in a collection with optional filter |
| Run an aggregation pipeline (read-only stages only) |
| Describe indexes for a collection |
| Infer schema from sampled documents |
| Get storage size statistics for a collection |
| Get database statistics |
| Get query execution plan for find/aggregate/count |
| Export query/aggregation results to EJSON file |
| Retrieve recent mongod log entries |
| Get current server configuration (redacted) |
Tool Usage Examples
explain
Returns query execution plan statistics:
# Format: ["method_name", {"arguments"}]
explain(
database="testdb",
collection="products",
method=["find", {"filter": {"status": "active"}, "limit": 10}],
verbosity="executionStats"
)export_data
Exports query results to a JSON file:
# Format: ["target_name", {"arguments"}]
export_data(
database="testdb",
collection="products",
exportTitle="active_products",
exportTarget=["find", {"filter": {"status": "active"}, "limit": 100}],
jsonExportFormat="relaxed" # or "canonical"
)Configuration
The server is configured via environment variables:
Variable | Required | Default | Description |
| Yes | - | MongoDB connection string (mongodb:// or mongodb+srv://) |
| No |
| Enable read-only mode (always true for this server) |
| No |
| Reject queries that don't use an index |
| No |
| Maximum documents per query |
| No |
| Maximum response bytes (16MB) |
| No |
| Logging level (DEBUG, INFO, WARNING, ERROR) |
🔒 Security Recommendation: Always use environment variables for the connection string. Never pass credentials as command-line arguments.
Installation
Prerequisites
Python 3.10+ (for local installation)
Docker (for containerized usage)
Access to a MongoDB instance (version 2.6 - 3.6 recommended)
Option 1: Docker (Recommended)
Pull and run the pre-built Docker image:
docker run --rm -i \
--network=host \
-e MDB_MCP_CONNECTION_STRING="mongodb://user:password@localhost:27017/mydb?authSource=admin" \
-e MDB_MCP_READ_ONLY=true \
ghcr.io/webxspark/legacy-mongodb-mcp:latestOr build locally:
# Clone the repository
git clone https://github.com/Webxspark/legacy-mongodb-mcp.git
cd legacy-mongodb-mcp
# Build the image
docker build -t legacy-mongodb-mcp .
# Run the container
docker run --rm -i \
--network=host \
-e MDB_MCP_CONNECTION_STRING="mongodb://user:password@localhost:27017" \
legacy-mongodb-mcpOption 2: Local Installation
# Clone the repository
git clone https://github.com/Webxspark/legacy-mongodb-mcp.git
cd legacy-mongodb-mcp
# Install dependencies
pip install -r requirements.txtUsage
With VS Code / Cursor (Docker)
Add to your .vscode/mcp.json:
{
"servers": {
"legacy-mongodb": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"--network=host",
"-e", "MDB_MCP_CONNECTION_STRING",
"-e", "MDB_MCP_READ_ONLY",
"ghcr.io/webxspark/legacy-mongodb-mcp:latest"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://user:password@localhost:27017/mydb?authSource=admin",
"MDB_MCP_READ_ONLY": "true"
}
}
}
}With VS Code / Cursor (Local Python)
Add to your .vscode/mcp.json:
{
"servers": {
"legacy-mongodb": {
"command": "python",
"args": ["src/server.py"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://user:password@localhost:27017",
"MDB_MCP_READ_ONLY": "true",
"MDB_MCP_INDEX_CHECK": "false"
}
}
}
}Or with uv:
{
"servers": {
"legacy-mongodb": {
"command": "uv",
"args": ["run", "--with", "mcp", "--with", "pymongo", "python", "src/server.py"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://user:password@localhost:27017"
}
}
}
}Dry Run Mode
Test your configuration without starting the server:
# Local
export MDB_MCP_CONNECTION_STRING="mongodb://localhost:27017"
python src/server.py --dry-run
# Docker
docker run --rm -i \
-e MDB_MCP_CONNECTION_STRING="mongodb://localhost:27017" \
ghcr.io/webxspark/legacy-mongodb-mcp:latest --dry-runTesting with Docker Compose
A Docker Compose configuration is provided for testing with MongoDB 3.6:
A Docker Compose configuration is provided for testing with MongoDB 3.6:
# Start the test MongoDB instance
docker compose up -d
# The connection string will be:
# mongodb://admin:secret_password@localhost:27017Roadmap
Future development will expand functionality based on user needs:
Write operations (safeguarded, opt-in)
User/Role management
Backup utilities
License
This server cannot be deployed
Maintenance
Related MCP Connectors
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Read-only MCP for AI usage profiles, leaderboards, stats, and docs; no writes or private data.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- AlicenseAqualityDmaintenanceA Model Context Protocol server that provides read-only access to MongoDB databases, enabling AI assistants to directly query and analyze MongoDB data while maintaining data safety.1424 npm9MIT
- FlicenseNot gradedqualityFmaintenanceProvides read-only access to MongoDB databases for LLMs to inspect collection schemas and execute aggregation pipelines.5 npm27-
- FlicenseNot gradedqualityDmaintenanceProvides a standardized interface for AI assistants to interact with MongoDB databases, enabling CRUD operations, schema analysis, and database management through the Model Context Protocol.1-
- AlicenseNot gradedqualityBmaintenanceA secure, read-only MCP server that enables AI agents to connect to MongoDB, perform queries and aggregations, and manage connections.186 npmMIT