Production-ready MCP server providing shared memory for multi-agent collaboration.
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.
- π 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
- Clone or download this repository
- Install dependencies:
pip install mcp pydantic
- Run the server:
python3 shared_memory_mcp.py
# 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()Add to your Claude Code config (~/.claudeCode/config.json):
{
"mcpServers": {
"shared-memory": {
"command": "python3",
"args": ["/path/to/shared_memory_mcp.py"]
}
}
}- β
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
- β‘
add_memory- Now supports tags, priority, metadata - β‘
read_memory- Advanced filtering and sorting - β‘
clear_memory- Auto-backup before clearing
- π 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.
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
~/.shared_memory_mcp/
βββ memory.json # Main storage
βββ mcp_memory.log # Rotating logs
βββ backups/ # Auto-backups (10 kept)
βββ memory_backup_*.json
- π SHARED_MEMORY_README.md - Full user guide
- π Quick Start Guide - 5-minute setup
- π API Reference - Complete API documentation
- π Changelog - Version 2.0 changes
- β¬οΈ Upgrade Guide - Migrate from v1 to v2
- π§ Implementation Summary - Technical details
- π§ͺ Testing Guide - How to run tests
- ποΈ Architecture Details - System design
| 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.
python3 run_basic_tests.pypip install pytest pytest-cov
pytest tests/ -v --cov- β 70+ test cases
- β Unit tests (operations, filtering, search)
- β Concurrency tests (locking, atomic writes)
- β Integration tests
# 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 .- β pytest - Testing framework
- β mypy - Type checking
- β ruff - Linting and formatting
- β pre-commit - Git hooks
- Add entry: 5-15ms (includes backup)
- Read entries: 2-10ms
- Search (100 entries): 1-5ms
- Update/Delete: 5-15ms (includes backup)
- Max words per entry: 200
- Max tags per entry: 10
- Max entries before rotation: 1000
- File lock timeout: 10 seconds
- Backup retention: 10 backups
# 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"])# 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"
)# 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")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.
File lock timeout
# Check for other running instances
ps aux | grep shared_memory_mcp
# Increase timeout in code if neededJSON parse error
# Restore from backup
cp ~/.shared_memory_mcp/backups/memory_backup_*.json \
~/.shared_memory_mcp/memory.jsonCheck system health
health = await health_check({})
print(health.message) # "All systems operational"# View logs
tail -f ~/.shared_memory_mcp/mcp_memory.log
# Check for errors
grep ERROR ~/.shared_memory_mcp/mcp_memory.logContributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
- Use type hints
- Follow existing patterns
- Add docstrings
- Run pre-commit hooks
MIT License - See LICENSE file for details
- β 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.
Built on the Model Context Protocol (MCP) by Anthropic.
Enhanced with production-ready features while maintaining the simplicity and elegance of the original design.
- 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 π