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 ๐
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.