Memory MCP
An advanced cognitive memory agent for AI chatbots that provides long-term, autonomous memory using a four-agent system for monitoring, extraction, reconciliation, and consolidation.
README
Memory MCP - Advanced Cognitive Memory Agent 🧠✨
Memory MCP is a professional-grade Model Context Protocol (MCP) server that provides long-term, autonomous cognitive memory for AI chatbots. Unlike simple memory tools, it uses a sophisticated four-agent architecture to monitor, extract, reconcile, and consolidate knowledge in real-time.
🚀 Key Features
- 🤖 Autonomous Four-Agent System:
- Monitor Agent: Classifies messages and assigns Importance Scores (0.0 to 1.0) to filter chitchat from core knowledge.
- Extraction Agent: Transforms raw text into structured JSON facts with entities and metadata.
- Reflector Agent: Performs "Memory Sleep" cycles to consolidate fragmented memories and prune outdated info.
- Grounding Agent: Automatically injects relevant context into your queries using hierarchical retrieval.
- ⚖️ Automated Conflict Resolution: Automatically detects when new info contradicts existing knowledge and uses an LLM to reconcile the two into a single, accurate fact.
- ⚡ Dual-Storage Engine:
- Semantic Memory (Fact Sheet): High-importance, stable facts (preferences, bio, tech stacks).
- Episodic Memory (Vector DB): Time-indexed experiential logs with temporal metadata.
- 🌍 Hybrid Model Support:
- Google Gemini (Recommended): Ultra-fast, high-accuracy extraction using Gemini 1.5/2.0 Flash (Free Tier).
- Local Ollama: 100% private, offline inference using Llama 3.2/3.1.
- 🔒 Security & Privacy:
- Supports
.envfiles for safe API key management. - 100% Local data storage in
~/.memory_mcp/.
- Supports
🏗️ Architecture: The Cognitive Pipeline
The system operates as an intelligent "Cognitive OS" layer between you and your LLM.
flowchart TD
A["User Message"] --> B["Monitor Agent"]
B -- "Important" --> C["Extraction Agent"]
B -- "Chitchat" --> D["Ignore"]
C --> E["Conflict Detection"]
E -- "Conflict Found" --> F["Conflict Resolver"]
E -- "No Conflict" --> G["MemoryStore"]
F --> G
G --> H["Semantic Fact Sheet"]
G --> I["Episodic Vector DB"]
J["Reflection Phase"] --> K["Reflector Agent"]
K -- "Consolidate" --> H
K -- "Prune" --> I
L["User Query"] --> M["Grounding Agent"]
M --> H
M --> I
M -- "Enriched Context" --> N["Final LLM Prompt"]
🛠️ Available Tools
| Tool | Type | Description |
|---|---|---|
process_message |
Cognitive | Primary Tool. Runs Monitor -> Extract -> Reconcile -> Store. |
ground_query |
Grounding | Enriches a query with relevant context before the chatbot answers. |
reflect_and_consolidate |
Maintenance | Merges similar memories into facts and cleans up old, low-value data. |
update_fact |
Manual | Force-update a specific subject in the Semantic memory. |
get_fact_sheet |
Resource | View the entire structured knowledge base. |
🧠 Deep Dive: How the Agents "Think"
1. The Monitor Agent & Importance Scoring
Every message is scored to determine its "Shelf Life":
- 0.9-1.0 (Critical): Permanent User Preferences ("I am vegan", "Call me Alex").
- 0.7-0.8 (Stable): Technical or Bio Facts ("I use React", "I live in NYC").
- 0.4-0.6 (Transitory): Current project details ("The deadline is Friday").
- <0.3 (Ephemeral): Small talk or greetings (Discarded).
2. The Extraction Agent & Conflict Resolution
When new information arrives that contradicts existing knowledge, the Conflict Resolver is triggered. Example: If you previously said you use React, but now say "I've switched to Vue," the system will reconcile these into a single updated fact rather than creating duplicates.
3. Automated Maintenance (New!)
The server is now fully autonomous and manages its own "Mind" via configurable triggers:
- Turn-based Trigger: Automatically runs a reflection cycle after every 20 important messages (Configurable).
- Background Loop: Can periodically run maintenance (e.g., every 30 mins) while idle. Disabled by default to save resources.
# config.yaml settings
reflector:
message_threshold: 20 # Run reflection every 20 important messages
enable_background_loop: false # Set to true to enable background timer
interval_seconds: 1800 # 30 minute interval
📥 Installation & Setup
# 1. Clone & Install
git clone https://github.com/yourusername/memory_MCP.git
cd memory_MCP
pip install -e .
# 2. Key Setup
cp .env.example .env
# Add your GOOGLE_API_KEY to .env (No key needed for local Ollama)
🔌 Connecting to MCP Clients
1. Claude Desktop (Mac/Windows)
Claude Desktop is the flagship client for MCP. It allows you to use your Cognitive Memory directly in your chats.
Config Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Configuration:
Add the following to your mcpServers object:
{
"mcpServers": {
"memory": {
"command": "python3",
"args": ["/Users/YOUR_USER/memory_MCP/src/memory_mcp/server.py"],
"env": {
"PYTHONPATH": "/Users/YOUR_USER/memory_MCP"
}
}
}
}
[!IMPORTANT] Replace
/Users/YOUR_USER/memory_MCPwith the absolute path to your project directory.
2. VS Code (Roo Code / Cline)
These extensions turn VS Code into a powerful AI IDE with memory.
- Open VS Code and navigate to the Roo Code or Cline settings.
- Find the MCP Servers section.
- Click Edit Settings (JSON) or add a new server via the UI.
- Use the same JSON configuration as shown for Claude Desktop above. Roo Code often shares the same
claude_desktop_config.jsonor uses its ownmcp_settings.jsonin~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/.
3. Goose (Desktop AI Agent)
Goose provides a powerful CLI and UI for agentic workflows.
- Open your Goose configuration (
~/.config/goose/config.yamlor via the UI). - Add a new extension:
extensions:
memory:
name: memory
command: python3
args:
- /Users/YOUR_USER/memory_MCP/src/memory_mcp/server.py
env:
PYTHONPATH: /Users/YOUR_USER/memory_MCP
4. Cursor (AI Editor)
Cursor allows you to add MCP servers in its settings.
- Go to Cursor Settings -> General -> Features.
- Find MCP Servers and click + Add New MCP Server.
- Name:
Memory - Type:
command - Command:
python3 /Users/YOUR_USER/memory_MCP/src/memory_mcp/server.py
💡 Tips for Pro Users
To get the most out of your Cognitive Memory, try these prompts:
- "Remember that I prefer dark mode for all my projects." (Direct store)
- "What did we decide about the API architecture yesterday?" (Triggers grounding)
- "Reflect on our recent work and update my tech stack preferences." (Manual maintenance)
📊 Comparison: Memory MCP vs. Mem0
| Feature | Memory MCP (Cognitive) | Mem0 (Standard) |
|---|---|---|
| Logic Engine | Four-Agent System: Monitors, extracts, reconciles, and reflects autonomously. | Uses a simpler extract-and-graph approach. |
| Maintenance | Self-Reflective: Automated "Mind Cycles" consolidate and prune data without user input. | Pruning and consolidation are usually batch processes or manual. |
| Protocol | MCP Standard: Plug-and-play with Claude Desktop and any MCP client. | Custom SDK/API integration required. |
| Privacy | 100% Local First: Data stays on your disk. Works with local Ollama. | Primarily cloud-based SaaS, though open-source options exist. |
| Conflict Resolution | Agentic Reconcile: Uses LLM reasoning to merge contradictory info into "Unified Facts." | Can lead to duplicates or requires manual metadata logic. |
| Setup Cost | Free / Local: Zero-cost with Gemini Flash or local Llama. | Tiered SaaS pricing for cloud features. |
📚 Research & Inspirations
Memory MCP is built upon the foundational principles of state-of-the-art AI memory research. Key inspirations include:
- MemGPT: Towards LLMs as Operating Systems. Packer et al., 2023.
- Generative Agents: Interactive Simulacra of Human Behavior. Park et al., 2023.
- AIOS: LLM Agent Operating System. Mei et al., 2024.
- CogMem: A Cognitive Memory Architecture for Sustained Multi-Turn Reasoning. Zhang et al., 2025.
🔒 Security Best Practices
- Local Everything: All your memories are stored in
~/.memory_mcp/. No data ever leaves your machine unless you use a cloud LLM provider (Google Gemini). - Key Management: Use the
.envfile to keep your API keys out of your source code. - Control: You can manually edit
~/.memory_mcp/fact_sheet.jsonif you ever need to "hard-reset" a specific fact.
📝 License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。