MongoDB Memory MCP Server
A production-grade MCP server that provides persistent long-term memory for AI agents using MongoDB, enabling them to store, search, update, delete, retrieve, and summarize structured project memories across developer workflows.
README
MongoDB Memory MCP Server
A production-grade, collaborative MongoDB Memory Model Context Protocol (MCP) Server built using Node.js (ES Modules), MongoDB 7.0, and the official @modelcontextprotocol/sdk.
Acts as a persistent long-term memory engine for AI agents (Claude Desktop, Cursor, Antigravity, Gemini CLI, or custom AI agents), enabling them to store, search, update, delete, retrieve, and summarize structured project memories across developer workflows.
📋 Table of Contents
- Features
- Tech Stack
- Folder Structure
- Prerequisites
- Installation
- Environment Variables
- Running Locally
- Production Build & Docker
- Package Scripts
- API Reference
- Client Configuration
- Troubleshooting
- Security
- Roadmap
- Contributing
- Code Style
- License
- Acknowledgements
✨ Features
- 2026-07-28 MCP Specification Compliant: Mandatory
server/discoverRPC, stateless_metaparsing,"resultType": "complete",ttlMs/cacheScopeindicators, Streamable HTTP headers (Mcp-Method,Mcp-Name), and deterministic tool sorting. - 15 Modular MCP Tools: Standardized CRUD operations, score-weighted full-text search, tag filtering, type filtering, recency listing, project context summarization, and Atlas Vector Search readiness.
- 6 Dynamic Context Resources (
memory://): Exposes live readable project context URIs (memory://project/{projectId},memory://decision/{projectId},memory://bugs/{projectId}, etc.). - 6 Reusable AI Prompt Templates: Automated prompt generators for architecture reviews, code reviews, documentation generation, and sprint summaries.
- Developer Onboarding REST APIs: Management endpoints for projects (
/api/projects), developers (/api/developers), project-bound API keys (/api/keys), and signed JWT tokens (/api/tokens). - Dynamic Scope Isolation: Automatically binds
req.auth.projectIdvia MongoDB API key lookup to enforce tenant memory isolation. - Dual Transport Modes: Local desktop IDEs via Stdio (
npm start) and remote network agents via Streamable HTTP (npm run start:http) athttp://localhost:3000/messages. - Auto-Generated Postman Collection: Live downloadable Postman collection v2.1.0 available at
GET /postman.json. - Case-Insensitive Searching: Case-insensitive regex matching ensuring
TodoNative,todonative, andTODONATIVEmatch 100% reliably. - Comprehensive Test Suite: 99 unit & integration tests passing across 21 test suites (
vitest+mongodb-memory-server).
🛠️ Tech Stack
- Runtime: Node.js 20+ LTS (ES Modules)
- MCP SDK:
@modelcontextprotocol/sdk(v1.5.0+) - Database: MongoDB 7.0+ (
mongodbNative Node Driver) - Web Server: Express v4.21.2 & Cors v2.8.5
- Schema Validation:
zodv3.24.1 - Security & Auth:
jsonwebtokenv9.0.2 - Logger:
winstonv3.17.0 (Stderr-safe structured JSON logger) - Testing:
vitestv3.0.4 &mongodb-memory-serverv10.1.3 - Containerization: Docker & Docker Compose
📂 Folder Structure
mongodb-mcp/
├── docs/ # Comprehensive documentation suite (11 guides)
├── src/ # Application source code
│ ├── config/ # Environment & config validation
│ ├── database/ # MongoDB connection pool & indexing
│ ├── mcp/ # MCP 2026-07-28 protocol handlers
│ ├── middleware/ # Express auth & protocol middleware
│ ├── models/ # Protocol constants & error hierarchy
│ ├── prompts/ # MCP Prompt Templates Engine
│ ├── repositories/ # MongoDB Data Access Repositories
│ ├── resources/ # MCP Dynamic Resources (`memory://`)
│ ├── schemas/ # Zod validation schemas
│ ├── services/ # Core Business Logic Services
│ ├── tools/ # Modular MCP Tools Registry (15 tools)
│ ├── transports/ # Transport layer (Express HTTP / SSE)
│ ├── utils/ # Logger, errors, Postman generator
│ └── server.js # Main server entrypoint & bootstrap
├── tests/ # Vitest Test Suite (99 tests)
│ ├── unit/ # Unit test files
│ └── integration/ # Integration test files
├── Dockerfile # Multi-stage production Dockerfile
├── docker-compose.yml # Docker Compose deployment stack
├── package.json # Dependencies & npm scripts
└── README.md # Master GitHub README
⚙️ Prerequisites
- Node.js:
>=20.0.0 LTS - npm:
>=10.0.0 - MongoDB:
7.0+(Local instance or Docker container)
📥 Installation
# 1. Clone repository
git clone https://github.com/your-username/mongodb-memory-mcp.git
cd mongodb-memory-mcp
# 2. Install dependencies
npm install
# 3. Create environment configuration
cp .env.example .env
🔑 Environment Variables
| Variable | Default Value | Description |
|---|---|---|
NODE_ENV |
development |
Environment mode (development, production, test) |
TRANSPORT |
stdio |
MCP Transport mode (stdio or http) |
PORT |
3000 |
HTTP port when TRANSPORT=http |
MONGODB_URI |
mongodb://localhost:27017/agent_memory |
MongoDB connection URI |
LOG_LEVEL |
info |
Logging verbosity (error, warn, info, debug) |
ENABLE_AUTH |
false |
Enable/disable authentication middleware |
API_KEY |
your_admin_api_key_here |
Master Admin API key |
JWT_SECRET |
your_jwt_secret_here |
Secret for signing JWT tokens (min 32 chars) |
🚀 Running Locally
# Start MongoDB via Docker Compose
docker-compose up -d mongodb
# Launch in Stdio Mode (Default for local desktop IDEs)
npm start
# Launch in HTTP Network Mode (Port 3000)
npm run start:http
🐳 Production Build & Docker
# Build & run entire container stack
docker-compose up -d --build
# View container logs
docker-compose logs -f mcp-server
📜 Package Scripts
| Script | Command | Purpose |
|---|---|---|
npm start |
node src/server.js |
Launch server in Stdio mode |
npm run start:http |
TRANSPORT=http node src/server.js |
Launch server in HTTP network mode |
npm test |
vitest run |
Execute 99 unit & integration tests |
npm run lint |
eslint . |
Execute ESLint code quality checks |
npm run format |
prettier --write . |
Format codebase with Prettier |
npm run check-connection |
node src/utils/testConnection.js |
Execute connection diagnostics |
npm run generate-auth |
node src/utils/generateAuth.js |
CLI helper to generate API keys & JWTs |
🔌 Client Configuration
Streamable HTTP Mode (Antigravity, Cursor, VS Code, Gemini CLI)
{
"mcpServers": {
"mongodb-memory": {
"url": "http://localhost:3000/messages",
"type": "streamable-http",
"headers": {
"X-API-Key": "mcp-memory-api-key"
}
}
}
}
Stdio Subprocess Mode (Claude Desktop)
{
"mcpServers": {
"mongodb-memory": {
"command": "node",
"args": ["/Users/sahil/Projects/mongodb-mcp/src/server.js"],
"env": {
"TRANSPORT": "stdio",
"MONGODB_URI": "mongodb://localhost:27017/agent_memory"
}
}
}
}
📖 API Documentation
Complete API documentation for REST endpoints, MCP tools, resources, and prompt templates is available in docs/API_REFERENCE.md and docs/USER_GUIDE.md.
🛡️ Security Policy
Please review our SECURITY.md for vulnerability reporting guidelines.
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md and our CODE_OF_CONDUCT.md for guidance.
📄 License
Distributed under the MIT License. See LICENSE for details.
🙏 Acknowledgements
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。