
mem0-mcp-server
MCP server exposing Mem0 v2 API for AI agents to store, retrieve, and search long-term memories using semantic search through the standardized MCP protocol.
Overview
Mem0-MCP Server is a self-hosted MCP (Model Context Protocol) server that bridges AI agents with persistent memory storage. It enables intelligent context retention across conversations and sessions using Mem0's AsyncMemory API.
Key Features:
- MCP Protocol Integration - Exposes Mem0 functionality via MCP tools
- Semantic Memory Search - Similarity-based memory retrieval with vector search
- Multi-Tenant Isolation - User/Agent/Session scoped memory isolation
- Flexible Transport - stdio for local agents, SSE for remote connections
- Configuration Management - Pydantic-based validation with environment variable support
Documentation
| Section | Description |
|---|---|
| API Reference | Complete API documentation for all modules and tools |
| Pattern Guides | Design pattern documentation (Singleton, Repository, etc.) |
| Usage Examples | Getting started and advanced usage guides |
| Deployment | Docker Compose configuration and service details |
| Architecture | System architecture and component interactions |
MCP Tools
| Tool | Description |
|---|---|
add_memory | Store information in long-term memory with semantic indexing |
search_memories | Search memories using semantic similarity |
get_memory | Retrieve specific memory by ID |
update_memory | Update existing memory content |
delete_memory | Remove memory from storage |
list_memories | List memories with filtering and pagination |
Architecture
AI Agent β FastMCP Server β MemoryManager β Mem0 AsyncMemory β Redis
β β
βββ SafeLogger (stdout/stderr) β
βββ Transport (stdio/SSE) β
βββ Config (Pydantic validation) βComponents:
- COMP-1: ConfigLoader - Configuration loading and validation
- COMP-2: FastMCP Server - MCP protocol server
- COMP-3: MemoryManager - Memory operations with multi-tenant isolation
- COMP-4: MCP Tools - Tool definitions
- COMP-5: SafeLogger - Output stream separation
Development
| Command | Description |
|---|---|
make install | Install dependencies with uv |
make lint | Lint code with ruff |
make lint-fix | Auto-fix linting issues |
make typecheck | Type check with pyright |
make test | Run all tests |
make test-unit | Run unit tests only |
make test-coverage | Run tests with coverage report |
make build | Build Docker image |
make run | Run development server |
Run multiple commands: make install && make lint && make typecheck && make test
See Makefile for all available commands including Docker management (docker-up, docker-down, docker-logs, etc.).
Project Structure
mem0-mcp/
βββ src/mcp_server/
β βββ __init__.py # FastMCP singleton
β βββ lifespan.py # Resource lifecycle
β βββ transport.py # Transport selection
β βββ memory/
β β βββ manager.py # MemoryManager
β β βββ lifespan.py # AsyncMemory lifecycle
β βββ config/
β β βββ settings.py # Pydantic models
β β βββ loader.py # Config file loading
β βββ tools/
β β βββ add_memory.py
β β βββ search_memories.py
β β βββ ...
β βββ utils/
β βββ safe_logger.py # Output separation
βββ doc/
β βββ api/ # API reference
β βββ patterns/ # Pattern guides
β βββ examples/ # Usage examples
β βββ architecture/ # Architecture docs
βββ tests/
βββ Makefile
βββ Dockerfile
βββ docker-compose.ymlLicense
MIT License
# Clone and install
git clone https://github.com/your-org/mem0-mcp-server.git
cd mem0-mcp-server
uv sync
# Set environment variables
export OPENAI_API_KEY="your-api-key"Before it works, you'll need: OPENAI_API_KEY
Quick Start
Installation
# Clone and install
git clone https://github.com/your-org/mem0-mcp-server.git
cd mem0-mcp-server
uv sync
# Set environment variables
export OPENAI_API_KEY="your-api-key"Configuration
Create ~/.config/mem0-mcp-server/settings.json:
{
"vector_store": {
"provider": "redis",
"config": {
"redis_url": "redis://localhost:6379"
}
},
"llm": {
"provider": "openai",
"config": {
"model": "gpt-4o"
}
},
"embedder": {
"provider": "openai",
"config": {
"model": "text-embedding-3-small"
}
}
}Running the Server
# SSE Transport (remote connections)
uv run python -m mcp_server.main
# stdio Transport (local AI agents)
export MCP_TRANSPORT=stdio
uv run python -m mcp_server.mainOpenCode Configuration
In ~/config/opencode/opencode.json
OpenCode Configuration
In ~/config/opencode/opencode.json
"mcp": {
"mem0": {
"type": "remote",
"enabled": true,
"url": "http://localhost:8050/sse"
}
}
Usage Example
# Add memory
result = await client.call_tool("add_memory", {
"messages": [{"role": "user", "content": "I prefer dark mode"}],
"user_id": "alice"
})
# Search memories
result = await client.call_tool("search_memories", {
"query": "theme preferences",
"filters": {"user_id": "alice"},
"limit": 5
})Configuration
Parameter Precedence
Configuration values are resolved in order:
- Tool parameters (direct)
- Environment variables (with MCP_ prefix)
- Config file values
- Hardcoded defaults
Environment Variables
| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY | (required) | OpenAI API key for LLM |
MCP_TRANSPORT | sse | Transport type (stdio, sse) |
MCP_HOST | 0.0.0.0 | Server bind address |
MCP_PORT | 8080 | Server bind port |
Deployment
Docker
# Using docker-compose
docker-compose up -d
# Using Makefile
make docker-up # Start services with docker compose
make docker-down # Stop services
make docker-logs # Show logsServices:
| Service | Description |
|---|---|
mem0-mcp | MCP server exposing Mem0 API on port 8050 |
ollama-qwen3-embedding | Ollama with qwen3-embedding:8b for vector embeddings (port 11434) |
ollama-qwen | Ollama with qwen2.5:7b for chat completions (port 11435) |
See Deployment β Docker for detailed configuration.
Kubernetes
# Using Helm chart
helm install mem0-mcp ./charts/mem0-mcp-serverNo common issues documented yet. If you hit a problem, the repository's GitHub Issues page is the best place to look.