agent-memory
MCP server providing persistent memory management for AI agents using SQLite and FTS5, enabling storage, full-text search, and recall of memories with namespace isolation.
README
<div align="center">
<img src="https://raw.githubusercontent.com/khaled1174/agent-memory/main/assets/banner.svg" alt="agent-memory banner" width="900"/>
Agent Memory System
Persistent memory for AI agents using SQLite + FTS5.
Single-file core ยท Zero dependencies ยท Optional MCP server and Obsidian sync.
</div>
โจ Features
| Feature | Description |
|---|---|
| ๐๏ธ Persistent | SQLite database survives process restarts |
| ๐ Full-text search | FTS5 engine with ranked results |
| ๐ Agent isolation | Each agent gets its own namespace automatically |
| ๐ ๏ธ MCP Server | 12 tools for Claude Code / Claude Desktop |
| ๐ Obsidian sync | Optional two-way Markdown bridge |
| ๐ค CLAUDE.md generator | Auto-inject context into every session |
| ๐ Cross-platform | macOS, Linux, WSL, Windows |
| โก Zero dependencies | Core uses only Python standard library |
๐๏ธ Architecture
graph TB
subgraph Clients["๐ฅ๏ธ Clients"]
CLI["๐ป CLI\n(memory.py)"]
MCP["๐ MCP Server\n(memory_mcp.py)"]
HERMES["๐ Hermes Bridge\n(hermes/bridge.py)"]
end
subgraph Core["โ๏ธ Core Engine"]
STORE["๐ฅ Store\nmemory_store()"]
SEARCH["๐ Search\nFTS5 Engine"]
ISO["๐ Isolation\nNamespace Handler"]
CTX["๐ Context\nCLAUDE.md Gen"]
end
subgraph Storage["๐พ Storage"]
DB[("๐๏ธ SQLite DB\nmemory.db")]
FTS[("๐ FTS5 Index")]
end
subgraph External["๐ Integrations"]
OBS["๐ Obsidian Vault\n(Markdown)"]
N8N["โ๏ธ n8n Workflow"]
TG["๐ฑ Telegram Bot"]
end
CLI --> STORE
CLI --> SEARCH
MCP --> STORE
MCP --> SEARCH
HERMES --> STORE
HERMES --> SEARCH
STORE --> ISO
SEARCH --> ISO
ISO --> DB
DB --> FTS
FTS --> SEARCH
STORE --> OBS
OBS --> STORE
N8N --> HERMES
TG --> HERMES
CTX --> DB
style Clients fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
style Core fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
style Storage fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
style External fill:#3a2d1f,stroke:#d29922,color:#cdd9e5
๐ Memory Lifecycle
sequenceDiagram
actor Agent as ๐ค AI Agent
participant CLI as ๐ป CLI / MCP
participant ISO as ๐ Namespace
participant DB as ๐๏ธ SQLite
participant FTS as ๐ FTS5 Index
participant OBS as ๐ Obsidian
Agent->>CLI: memory store --type semantic --content "..."
CLI->>ISO: Resolve agent namespace (AGENT_NAME)
ISO-->>CLI: agent_id = "health" (or global)
CLI->>DB: INSERT INTO memories (agent_id, type, content, ...)
DB->>FTS: Auto-index content
DB-->>CLI: memory_id = 42
CLI-->>Agent: โ
Stored (id=42)
Agent->>CLI: memory search --query "rate limit"
CLI->>ISO: Resolve agent namespace
ISO-->>CLI: agent_id
CLI->>FTS: SELECT * FROM memories_fts WHERE content MATCH "rate limit"
FTS-->>CLI: Ranked results
CLI-->>Agent: ๐ Results (ranked by relevance)
Note over DB,OBS: Optional Obsidian Sync
DB->>OBS: Sync to Markdown vault
OBS->>DB: Sync from Markdown vault
๐ง Memory Types
mindmap
root((๐ง Memory Types))
๐
episodic
Events and decisions
Switched to Postgres
Deployed v2 on Monday
๐ semantic
Facts and knowledge
Rate limit 1000 req/min
Max upload 50 MB
โ๏ธ procedural
Workflows and how-tos
Steps build test deploy
Auth flow OAuth2 JWT
๐ Quick Start
Option 1: CLI (zero dependencies)
cp memory.py /usr/local/bin/memory
chmod +x /usr/local/bin/memory
# Store a memory
memory store --type semantic --content "Max upload: 50 MB" --project api --importance 5
# Search memories
memory search --query "upload"
# List recent
memory list --project api --recent 10
# View stats
memory stats
Option 2: MCP Server (Claude Code / Claude Desktop)
pip install mcp
Add to ~/.claude/settings.json (Claude Code):
{
"mcpServers": {
"agent-memory": {
"command": "python",
"args": ["/path/to/memory_mcp.py"]
}
}
}
Claude Desktop paths:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json- Windows:
%APPDATA%\Claude\claude_desktop_config.json
Restart and you'll see 12 tools available.
๐ ๏ธ MCP Tools
graph LR
subgraph Session["๐ Session"]
T1["memory_brief\nLoad context"]
T2["memory_who\nAgent identity"]
T3["memory_stats\nDB statistics"]
end
subgraph CRUD["โ๏ธ CRUD"]
T4["memory_store\nSave memory"]
T5["memory_update\nPatch memory"]
T6["memory_delete\nRemove by ID"]
end
subgraph Query["๐ Query & Export"]
T7["memory_search\nFTS5 full-text"]
T8["memory_list\nFilter and sort"]
T9["memory_export\nExport to JSON"]
T10["memory_generate_context\nBuild CLAUDE.md"]
end
subgraph Sync["๐ Sync"]
T11["memory_sync_to_vault\nSQLite to Obsidian"]
T12["memory_sync_from_vault\nObsidian to SQLite"]
end
style Session fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
style CRUD fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
style Query fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
style Sync fill:#3a2d1f,stroke:#d29922,color:#cdd9e5
๐ Agent Isolation
graph TD
ENV["๐ AGENT_NAME env var"]
ENV -->|"= 'health'"| HEALTH["๐ฅ health namespace\nWrite: own only\nRead: own + global"]
ENV -->|"= 'orchestrator'"| ORCH["๐ฏ orchestrator\nWrite: anywhere\nRead: everything"]
ENV -->|"not set"| GLOBAL["๐ global\nWrite: anywhere\nRead: everything"]
HEALTH --> DB1[("health::memories")]
HEALTH -.->|read only| DB2[("global::memories")]
ORCH --> DB1
ORCH --> DB2
ORCH --> DB3[("other::memories")]
GLOBAL --> DB2
style ENV fill:#21262d,stroke:#58a6ff,color:#cdd9e5
style HEALTH fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
style ORCH fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
style GLOBAL fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
export AGENT_NAME=health # Linux / macOS / WSL
$env:AGENT_NAME = "health" # Windows PowerShell
| Role | Write Access | Read Access |
|---|---|---|
| Regular agent | Own namespace only | Own + global |
orchestrator |
Anywhere | Everything |
| Not set | Anywhere | Everything |
๐ Hermes โ Cross-Platform Memory
Two agents collaborate on Slack. You ask on Telegram. The memory carries.
flowchart LR
SLACK["๐ฌ Slack Agent"] -->|POST| N8N["โ๏ธ n8n"]
N8N -->|HTTP| BRIDGE["๐ Hermes Bridge\nbridge.py :8765"]
BRIDGE <-->|SQLite| DB[("๐๏ธ memory.db")]
TG["๐ฑ Telegram Bot"] <-->|HTTP| BRIDGE
MCP["๐ MCP Server"] <-->|SQLite| DB
CLI["๐ป CLI"] <-->|SQLite| DB
style SLACK fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
style N8N fill:#3a2d1f,stroke:#d29922,color:#cdd9e5
style BRIDGE fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
style DB fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
style TG fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
style MCP fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
style CLI fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
# 1. Start the bridge
python hermes/bridge.py
# 2. Import hermes/n8n_workflow.json into your n8n instance
# 3. Start the Telegram bot
TELEGRAM_TOKEN=xxx HERMES_URL=http://your-server:8765 python hermes/telegram_bot.py
See hermes/README.md for full setup, API reference, and VPS deployment.
๐ฆ Obsidian Integration (Optional)
export OBSIDIAN_VAULT=/path/to/your/vault
# Auto-mirrors every store/update/delete to Markdown
memory store --type semantic --content "API uses JWT" --project api
# Bulk sync
memory sync-to-vault # SQLite โ Markdown
memory sync-from-vault # Markdown โ SQLite
๐ CLAUDE.md Generator
memory generate-context --output CLAUDE.md
Creates a Markdown file from your most important memories. Place it in your project root and Claude Code reads it automatically every session.
๐ File Structure
agent-memory/
โโโ memory.py # Core: CLI + library (1282 lines)
โโโ memory_mcp.py # MCP server (645 lines, requires: pip install mcp)
โโโ assets/
โ โโโ banner.svg # Repository banner image
โโโ hermes/ # Cross-platform memory layer
โ โโโ bridge.py # HTTP gateway (zero new deps)
โ โโโ telegram_bot.py # Telegram recall bot (requires: requests)
โ โโโ n8n_workflow.json # Ready-to-import Slack โ memory workflow
โ โโโ README.md # Hermes setup guide
โโโ README.md
โโโ LICENSE
โโโ .gitignore
โโโ requirements.txt # Runtime: empty (stdlib only)
โโโ requirements-dev.txt # Dev: pytest, black, mypy, ruff
โโโ tests/
โโโ __init__.py
โโโ test_memory.py # 58 tests across 8 classes
๐๏ธ Database Location
| Platform | Default Path |
|---|---|
| macOS / Linux | ~/.claude/memory/memory.db |
| Windows | %APPDATA%\\claude\\memory\\memory.db |
Override: export AGENT_MEMORY_DIR=/custom/path
๐งช Testing
pip install -r requirements-dev.txt
python -m pytest tests/test_memory.py -v # 58 tests
python -m pytest tests/test_memory.py -v --cov=memory
๐ License
MIT ยฉ khaled1174
<div align="center"> <sub>Built with โค๏ธ for AI agents that need to remember.</sub> </div>
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
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
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.