Skip to main content
Glama

mem0-mcp

MCP 服务器,公开 Mem0 v2 API,供 AI 代理通过标准化的 MCP 协议使用语义搜索来存储、检索和搜索长期记忆。

mem0-mcp MCP server

概述

Mem0-MCP 服务器是一个自托管的 MCP(模型上下文协议)服务器,它将 AI 代理与持久化内存存储连接起来。它利用 Mem0 的 AsyncMemory API 在对话和会话之间实现智能上下文保留。

主要功能:

  • MCP 协议集成 - 通过 MCP 工具公开 Mem0 功能

  • 语义记忆搜索 - 基于相似度的向量搜索记忆检索

  • 多租户隔离 - 用户/代理/会话范围的内存隔离

  • 灵活的传输方式 - 用于本地代理的 stdio,用于远程连接的 SSE

  • 配置管理 - 基于 Pydantic 的验证,支持环境变量

Related MCP server: Amber

文档

章节

描述

API 参考

所有模块和工具的完整 API 文档

模式指南

设计模式文档(单例、存储库等)

使用示例

入门和高级使用指南

部署

Docker Compose 配置和服务详情

架构

系统架构和组件交互

快速入门

安装

# Clone and install
git clone https://github.com/your-org/mem0-mcp.git
cd mem0-mcp
uv sync

# Set environment variables
export OPENAI_API_KEY="your-api-key"

配置

创建 ~/.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"
    }
  }
}

运行服务器

# 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 工具

工具

描述

add_memory

将信息存储到具有语义索引的长期记忆中

search_memories

使用语义相似度搜索记忆

get_memory

通过 ID 检索特定记忆

update_memory

更新现有的记忆内容

delete_memory

从存储中删除记忆

list_memories

列出带有过滤和分页功能的记忆

使用示例

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

架构

AI Agent → FastMCP Server → MemoryManager → Mem0 AsyncMemory → Redis
              │                                  │
              ├── SafeLogger (stdout/stderr)    │
              ├── Transport (stdio/SSE)        │
              └── Config (Pydantic validation)  │

组件:

  • COMP-1: ConfigLoader - 配置加载和验证

  • COMP-2: FastMCP Server - MCP 协议服务器

  • COMP-3: MemoryManager - 具有多租户隔离的内存操作

  • COMP-4: MCP Tools - 工具定义

  • COMP-5: SafeLogger - 输出流分离

配置

参数优先级

配置值的解析顺序如下:

  1. 工具参数(直接)

  2. 环境变量(带有 MCP_ 前缀)

  3. 配置文件值

  4. 硬编码默认值

环境变量

变量

默认值

描述

OPENAI_API_KEY

(必需)

用于 LLM 的 OpenAI API 密钥

MCP_TRANSPORT

sse

传输类型 (stdio, sse)

MCP_HOST

0.0.0.0

服务器绑定地址

MCP_PORT

8080

服务器绑定端口

部署

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

服务:

服务

描述

mem0-mcp

在 8050 端口公开 Mem0 API 的 MCP 服务器

ollama-qwen3-embedding

使用 qwen3-embedding:8b 进行向量嵌入的 Ollama(端口 11434)

ollama-qwen

使用 qwen2.5:7b 进行聊天补全的 Ollama(端口 11435)

详细配置请参阅 部署 → Docker

Kubernetes

# Using Helm chart
helm install mem0-mcp ./charts/mem0-mcp-server

开发

命令

描述

make install

使用 uv 安装依赖

make lint

使用 ruff 进行代码检查

make lint-fix

自动修复代码检查问题

make typecheck

使用 pyright 进行类型检查

make test

运行所有测试

make test-unit

仅运行单元测试

make test-coverage

运行测试并生成覆盖率报告

make build

构建 Docker 镜像

make run

运行开发服务器

运行多个命令:make install && make lint && make typecheck && make test

请参阅 Makefile 获取所有可用命令,包括 Docker 管理(docker-up, docker-down, docker-logs 等)。

项目结构

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

许可证

MIT 许可证

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    B
    maintenance
    Gives your AI persistent memory across conversations. Stores facts automatically, finds them by meaning using hybrid search with query expansion, and organizes everything into topics without manual tagging.
    18
    1
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    MCP server for Statewave, an open-source memory runtime for AI agents. Provides persistent memory, context retrieval, and memory compilation through the Model Context Protocol.
    6
    11
    3
    Apache 2.0
  • A
    license
    Not graded
    quality
    B
    maintenance
    Persistent memory MCP server for AI agents that stores, recalls, and searches conversation history, key-value context, and long-term entries across sessions with semantic search and FIFO queues.
    75
    1
    -