MCP Agent Memory
A production-ready MCP server that enables multiple AI agents to collaborate through a shared, concurrency-safe memory space. It supports advanced search, full CRUD operations, and automatic backups to facilitate asynchronous communication between agents.
README
MCP Agent Memory - v2.0
Production-ready MCP server providing shared memory for multi-agent collaboration.
Overview
MCP Agent Memory is an enhanced Model Context Protocol (MCP) server that enables multiple AI agents (like Claude Code instances) to communicate asynchronously through a shared memory space. Think of it as a sophisticated shared notepad where AI agents can leave messages, search for information, and coordinate their work.
Key Features
- 🔒 Concurrency Safe - File locking for shared environments
- 📝 Full CRUD - Create, Read, Update, Delete operations
- 🔍 Advanced Search - Full-text search across all fields
- 🏷️ Organization - Tags, priority levels, metadata
- 📊 Analytics - Comprehensive memory statistics
- 💾 Reliable - Automatic backups and corruption recovery
- 📋 Structured Logging - Complete operation visibility
- 🛡️ Health Monitoring - Built-in health check system
Quick Start
Installation
- Clone or download this repository
- Install dependencies:
pip install mcp pydantic - Run the server:
python3 shared_memory_mcp.py
Basic Usage
# Add a memory entry
await add_memory(
agent_name="claude-alpha",
content="Analysis complete. Found 3 key insights.",
tags=["analysis", "complete"],
priority="high"
)
# Search for entries
results = await search_memory(query="analysis")
# Get statistics
stats = await get_memory_stats()
Configuration
Add to your Claude Code config (~/.claudeCode/config.json):
{
"mcpServers": {
"shared-memory": {
"command": "python3",
"args": ["/path/to/shared_memory_mcp.py"]
}
}
}
What's New in v2.0
New Tools (6 total)
- ✅
update_memory- Modify existing entries - ✅
delete_memory- Remove specific entries - ✅
get_memory- Retrieve single entry by ID - ✅
search_memory- Full-text search - ✅
get_memory_stats- Memory analytics - ✅
health_check- System health monitoring
Enhanced Tools
- ⚡
add_memory- Now supports tags, priority, metadata - ⚡
read_memory- Advanced filtering and sorting - ⚡
clear_memory- Auto-backup before clearing
Core Improvements
- 🔒 Thread-safe file locking
- 💾 Automatic backups (keeps 10)
- 📝 Structured logging
- 🔄 Auto-rotation at 1000 entries
- 🛡️ Corruption recovery
- 🆔 Unique entry IDs (UUID)
Zero breaking changes! All v1 code works without modification.
Architecture
MCP Agent Memory v2.0
├── shared_memory_mcp.py # Main server (9 MCP tools)
├── utils/
│ ├── file_lock.py # Concurrency safety
│ └── logger.py # Structured logging
├── tests/
│ ├── test_memory_operations.py
│ └── test_concurrency.py
└── docs/
├── API_REFERENCE_V2.md # Complete API docs
├── CHANGELOG_V2.md # Version history
├── UPGRADE_GUIDE.md # v1→v2 migration
└── IMPLEMENTATION_SUMMARY.md
Storage
~/.shared_memory_mcp/
├── memory.json # Main storage
├── mcp_memory.log # Rotating logs
└── backups/ # Auto-backups (10 kept)
└── memory_backup_*.json
Documentation
Getting Started
- 📖 SHARED_MEMORY_README.md - Full user guide
- 🚀 Quick Start Guide - 5-minute setup
Reference
- 📚 API Reference - Complete API documentation
- 📋 Changelog - Version 2.0 changes
- ⬆️ Upgrade Guide - Migrate from v1 to v2
Developer
- 🔧 Implementation Summary - Technical details
- 🧪 Testing Guide - How to run tests
- 🏗️ Architecture Details - System design
API Overview
Memory Operations
| Tool | Description | Type |
|---|---|---|
add_memory |
Create new entry with tags/priority | Write |
read_memory |
Read with advanced filtering | Read |
update_memory |
Modify existing entry | Write |
delete_memory |
Remove specific entry | Write |
get_memory |
Retrieve single entry by ID | Read |
search_memory |
Full-text search | Read |
get_memory_stats |
Memory analytics | Read |
clear_memory |
Clear all entries | Write |
health_check |
System health status | Read |
See API Reference for detailed documentation.
Testing
Run Basic Tests
python3 run_basic_tests.py
Run Full Test Suite (requires pytest)
pip install pytest pytest-cov
pytest tests/ -v --cov
Test Coverage
- ✅ 70+ test cases
- ✅ Unit tests (operations, filtering, search)
- ✅ Concurrency tests (locking, atomic writes)
- ✅ Integration tests
Development
Setup Development Environment
# Install dev dependencies
pip install -r requirements-dev.txt
# Install pre-commit hooks
pre-commit install
# Run tests
python3 run_basic_tests.py
# Type checking
mypy shared_memory_mcp.py
# Linting
ruff check .
Code Quality Tools
- ✅ pytest - Testing framework
- ✅ mypy - Type checking
- ✅ ruff - Linting and formatting
- ✅ pre-commit - Git hooks
Performance
Typical Operations
- Add entry: 5-15ms (includes backup)
- Read entries: 2-10ms
- Search (100 entries): 1-5ms
- Update/Delete: 5-15ms (includes backup)
Limits
- Max words per entry: 200
- Max tags per entry: 10
- Max entries before rotation: 1000
- File lock timeout: 10 seconds
- Backup retention: 10 backups
Use Cases
Multi-Agent Collaboration
# Agent A: Data collector
await add_memory(
agent_name="data-collector",
content="Collected 10,000 data points",
tags=["data", "ready-for-analysis"],
priority="high"
)
# Agent B: Analyzer picks up work
pending = await read_memory(tags=["ready-for-analysis"])
Task Tracking
# Start task
result = await add_memory(
agent_name="worker",
content="Starting analysis...",
tags=["analysis", "in-progress"],
priority="high"
)
# Update on completion
await update_memory(
entry_id=result.entry_id,
tags=["analysis", "complete"],
priority="low"
)
Knowledge Base
# Search for information
results = await search_memory(
query="user behavior insights",
limit=10
)
# Get statistics
stats = await get_memory_stats()
print(f"Total knowledge: {stats.total_entries} entries")
FAQ
Q: Is v2 compatible with v1 code? A: Yes! 100% backward compatible. All v1 code works without changes.
Q: How does migration work? A: Automatic. v2 detects v1 format and migrates on first write.
Q: Can multiple agents write simultaneously? A: Yes! File locking ensures safe concurrent access.
Q: What happens if storage gets corrupted? A: Automatic recovery from the most recent valid backup.
Q: How much disk space does it use? A: ~500-1000 bytes per entry. 1000 entries ≈ 500KB-1MB.
Q: Can I use it for production? A: Yes! v2 is production-ready with reliability features.
See UPGRADE_GUIDE.md for more details.
Troubleshooting
Common Issues
File lock timeout
# Check for other running instances
ps aux | grep shared_memory_mcp
# Increase timeout in code if needed
JSON parse error
# Restore from backup
cp ~/.shared_memory_mcp/backups/memory_backup_*.json \
~/.shared_memory_mcp/memory.json
Check system health
health = await health_check({})
print(health.message) # "All systems operational"
Logs
# View logs
tail -f ~/.shared_memory_mcp/mcp_memory.log
# Check for errors
grep ERROR ~/.shared_memory_mcp/mcp_memory.log
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
Code Style
- Use type hints
- Follow existing patterns
- Add docstrings
- Run pre-commit hooks
License
MIT License - See LICENSE file for details
Changelog
v2.0.0 (2025-10-30)
- ✅ Added concurrency safety (file locking)
- ✅ Added structured logging
- ✅ Added 6 new MCP tools
- ✅ Enhanced data model (tags, priority, metadata)
- ✅ Added automatic backups and recovery
- ✅ Added comprehensive test suite (70+ tests)
- ✅ Added complete documentation
- ✅ Zero breaking changes
See CHANGELOG_V2.md for detailed history.
Acknowledgments
Built on the Model Context Protocol (MCP) by Anthropic.
Enhanced with production-ready features while maintaining the simplicity and elegance of the original design.
Links
- Documentation: ./docs/
- Tests: ./tests/
- API Reference: API_REFERENCE_V2.md
- MCP Protocol: https://modelcontextprotocol.io/
Made with ❤️ for multi-agent collaboration
Version 2.0.0 - Production Ready 🚀
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。