mem0-mcp

mem0-mcp

MCP protocol server exposing Mem0 AsyncMemory API for AI agent context retention

Category
访问服务器

README

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

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.main

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

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
})

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

Configuration

Parameter Precedence

Configuration values are resolved in order:

  1. Tool parameters (direct)
  2. Environment variables (with MCP_ prefix)
  3. Config file values
  4. 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 logs

Services:

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-server

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.yml

License

MIT License

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选