mem9
Mem9 is an open-source, project-scoped memory service for Codex, Claude, and other MCP-compatible coding agents. It keeps durable project knowledge and CLI session metadata available across tools and conversations.
README
Mem9
Mem9 is an open-source, project-scoped memory service for Codex, Claude, and other MCP-compatible coding agents. It keeps durable project knowledge and CLI session metadata available across tools and conversations without treating memory as a source of current external facts.
Why Mem9
- Resolves projects from the workspace path, Git remote, and branch.
- Stores atomic architecture decisions, conventions, business rules, and TODOs.
- Combines vector and text retrieval with PostgreSQL and pgvector.
- Exposes nine memory and session tools through MCP Streamable HTTP and STDIO.
- Shares one service across Codex, Claude, and compatible CLI clients.
- Includes focused tests and runnable HTTP/MCP smoke checks.
flowchart LR
A[Codex / Claude / MCP client] -->|MCP| B[Mem9]
B --> C[Project resolver]
B --> D[Embedding client]
C --> E[(PostgreSQL + pgvector)]
D --> E
Requirements
- Python 3.11+
- uv
- PostgreSQL with pgvector, such as Supabase Postgres
- An OpenAI API key for vector embeddings; text search remains available when embeddings are not configured
Quick Start
git clone https://github.com/luuhung93/mem9.git
cd mem9
cp .env.example .env
# Add your database credentials and optional OpenAI API key to .env.
set -a
source .env
set +a
psql "$DIRECT_URL" -v ON_ERROR_STOP=1 -f migrations/001_init.sql
uv run --locked --with-editable . memory-service
The HTTP service listens on http://127.0.0.1:8766 by default:
curl -fsS http://127.0.0.1:8766/health
MCP Setup
Mem9 exposes Streamable HTTP at http://127.0.0.1:8766/mcp.
Codex:
codex mcp add memory --url http://127.0.0.1:8766/mcp
codex mcp get memory
Claude:
claude mcp add --transport http --scope user memory \
http://127.0.0.1:8766/mcp
claude mcp get memory
Restart active CLI sessions after changing MCP configuration.
MCP Tools
Memory tools:
memory_searchmemory_storememory_updatememory_deletememory_projects
Session tools:
session_registersession_listsession_getsession_delete
Each CLI should call session_register once at startup with the absolute
workspace root, client name, external resume/session ID, and a short title.
Codex should use CODEX_THREAD_ID as the external session ID.
Example Workflow
Store one durable project fact:
{
"workspace_root": "/path/to/project",
"category": "architecture",
"content": {
"fact": "The API uses repository classes for database access."
}
}
Search before starting related work:
{
"workspace_root": "/path/to/project",
"query": "database access architecture"
}
Do not store secrets, source code, build logs, transient errors, or complete conversations. Store one durable fact per memory.
Running with PM2
pm2 start ecosystem.config.cjs
pm2 save
pm2 status mem9
The PM2 configuration uses the repository directory as its working directory
and reads secrets from .env.
Development
Run the local checks:
set -a
source .env
set +a
uv lock --check
uv run --locked pytest -q
uv run --locked --with-editable . python scripts/self_check.py
uv run --locked python -m compileall -q src scripts tests
With the service running, verify HTTP and MCP transports:
uv run --locked --with-editable . python scripts/http_smoke.py
uv run --locked --with-editable . python scripts/mcp_smoke.py
uv run --locked --with-editable . python scripts/mcp_http_smoke.py
The smoke checks clean up the memory and session records they create.
Architecture
src/memory_service/
app.py FastAPI lifecycle and HTTP routes
database.py asyncpg pool setup
embeddings.py OpenAI embedding client
project_context.py Git and workspace project resolver
repositories/ PostgreSQL memory and session persistence
mcp_tools/ MCP memory and session tool definitions
mcp_server.py STDIO and Streamable HTTP MCP adapter
migrations/ ordered PostgreSQL schema migrations
scripts/ runnable self-checks and smoke tests
tests/ repository and project resolver tests
See ai/ARCHITECTURE.md for implementation details.
Security
Please report vulnerabilities privately as described in
SECURITY.md. Never include credentials, private project data,
or production database contents in a public issue.
License
Mem9 is licensed under the MIT License.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。