Cockroach Memory Agent
Provides persistent, globally-distributed memory for AI agents using CockroachDB's MCP Server and AWS S3 backups, with session isolation, audit trails, and full-text search.
README
Cockroach Memory Agent
An AI agent with persistent, globally-distributed memory backed by CockroachDB's MCP Server and AWS S3 — built for the CockroachDB × AWS Hackathon.
Live demo: https://cockroach-memory-agent.vercel.app GitHub: https://github.com/0xConsole/cockroach-memory-agent
The Problem
AI agents are amnesiac. Every conversation starts from scratch. Every process restart loses context. Every scale-out creates new instances that don't share memory. This makes agents unreliable for production:
- A DevOps agent that monitored incidents yesterday can't reference them today
- A code review agent that learned your codebase patterns forgets on restart
- A trading agent that tracked market conditions loses its history on redeploy
- Multi-region deployments can't share a consistent memory store
The Solution
Cockroach Memory Agent gives agents a persistent, globally-distributed memory backed by CockroachDB's distributed SQL database. It uses CockroachDB's MCP Server for all database operations, ensuring every memory is stored, retrieved, and audited through a standardized protocol — with automatic AWS S3 backups for disaster recovery.
Key Features
- Persistent Memory — memories survive process restarts, failures, and redeployments
- MCP Protocol — all DB operations go through CockroachDB's MCP Server (15 tools: 10 read + 5 write)
- AWS S3 Backup — periodic gzip-compressed memory snapshots with restore capability
- Audit Trail — every MCP tool call is logged with input/output for compliance
- Session Isolation — multi-session support with session-scoped memory recall
- Multi-Region Topology — CockroachDB's global distribution for low-latency memory access
- Full-Text Search — search memories by content (SQLite FTS5 demo / CockroachDB ILIKE)
- Works without a cluster — mock transport simulates the full MCP server so the demo runs anywhere
Unique Angle
Unlike ephemeral agent memory (Redis, in-process dicts), Cockroach Memory Agent uses CockroachDB's MCP Server for persistent, globally-distributed, audited memory that survives restarts and scales across regions — with automatic AWS S3 backups for disaster recovery.
How It Uses CockroachDB (≥2 tools requirement)
- CockroachDB MCP Server — all memory operations (create table, insert, select, delete, cluster info, cluster nodes) go through the MCP Server's 15 tools (10 read + 5 write). The MCP client wraps every operation as a tool call with full audit logging. Compatible with Claude Code, Cursor, and VS Code.
- LangChain CockroachDB Integration — the architecture is compatible with
langchain-cockroachdbfor LangChain-native memory backends, enabling drop-in use with LangChain agents.
The 15 CockroachDB MCP Server Tools
Read (10): list_databases, list_tables, get_table_schema, get_cluster, list_sql_users, list_cluster_nodes, show_running_queries, select_query, explain_query, show_statement
Write (5): create_database, create_table, insert_rows, update_rows, delete_rows
How It Uses AWS (≥1 service requirement)
- AWS S3 — periodic gzip-compressed memory snapshots with backup/restore/list operations. Free tier compatible (5 GB storage, 2,000 PUT, 20,000 GET requests/month). Mock fallback for demo mode when no AWS credentials are set.
Architecture
┌─────────────┐ ┌─────────────────┐ ┌──────────────────────────┐
│ AI Agent │────▶│ MCP Protocol │────▶│ CockroachDB MCP Server │
│ (chat/CLI) │ │ (tools/call) │ │ (15 tools: 10R + 5W) │
└─────────────┘ └─────────────────┘ └────────────┬─────────────┘
│
┌───────────────────────────┴────────────┐
│ │
┌─────────▼──────────┐ ┌──────────────▼──────────┐
│ CockroachDB │ │ AWS S3 │
│ (multi-region, │ │ (gzip backup │
│ ACID, survivable)│ │ snapshots) │
└────────────────────┘ └─────────────────────────┘
▲
│ (demo fallback)
┌─────────┴──────────┐
│ SQLite + FTS5 │
│ (no-cluster demo) │
└────────────────────┘
Memory Schema (mirrors CockroachDB DDL)
CREATE TABLE memories (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id STRING NOT NULL,
kind STRING NOT NULL DEFAULT 'message', -- observation|reflection|plan|message
role STRING NOT NULL, -- user|assistant|system
content STRING NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}'::JSONB,
importance FLOAT NOT NULL DEFAULT 0.5,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_memories_session ON memories(session_id);
CREATE INDEX idx_memories_session_created ON memories(session_id, created_at);
CREATE INVERTED INDEX idx_memories_metadata ON memories(metadata);
Demo (the 3-minute judge flow)
- Open the live demo → see the chat UI.
- Type
Hi, I'm Alice→ agent responds "Nice to meet you, Alice!" (stored via MCPinsert_rows). - Click "🔄 Simulate Restart" → memory persists across the restart.
- Type
What's my name?→ agent responds "Your name is Alice — I remember from our conversation." (recalled via MCPselect_query). - Click the "MCP Tools" tab → see all 23 MCP tools (8 agent + 15 CockroachDB).
- Click the "Audit Trail" tab → see every MCP tool call logged with input/output/timestamp.
- Click the "AWS S3 Backup" tab → create a gzip-compressed memory snapshot.
- Click "▶ Run Auto-Demo" → runs the full 7-phase demo automatically.
The 7-Phase Automated Demo
- Store messages via MCP
insert_rows - Simulate process restart → recall (persistence verified)
- Ask "What's my name?" → recall works
- Search memories for "Python"
- AWS S3 backup (gzip compressed)
- CockroachDB cluster topology (3 regions)
- Full MCP audit trail (100% success rate)
Tech Stack
- Python 3.11 + FastAPI
- CockroachDB MCP Server (15 tools: 10 read + 5 write)
- AWS S3 (boto3, gzip-compressed backups, free tier)
- SQLite FTS5 for demo search (mirrors CockroachDB ILIKE)
- Vercel serverless (free tier)
- Static HTML/CSS/JS UI (no framework, fast load)
Setup (<5 commands)
Run locally
git clone https://github.com/0xConsole/cockroach-memory-agent.git && cd cockroach-memory-agent
pip install -r requirements.txt
uvicorn app.main:app --reload
# Open http://localhost:8000
Run the automated demo
curl -X POST http://localhost:8000/api/demo | python -m json.tool
Connect a real CockroachDB cluster
export CRDB_DATABASE_URL="postgresql://user:pass@cluster.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full"
export AWS_S3_BUCKET="my-agent-backups"
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
uvicorn app.main:app --reload
API Endpoints
| Method | Path | Description |
|---|---|---|
GET |
/ |
Interactive chat UI |
GET |
/health |
Health check |
POST |
/api/chat |
Send a message to the agent |
GET |
/api/recall/{session_id} |
Recall all memories for a session |
GET |
/api/search/{session_id}?q=... |
Full-text search over memories |
DELETE |
/api/forget/{session_id} |
Delete all memories for a session |
GET |
/api/cluster |
CockroachDB cluster info + topology |
POST |
/api/backup |
Back up memories to AWS S3 |
GET |
/api/audit |
Full MCP audit trail |
POST |
/api/demo |
Run the 7-phase automated demo |
GET |
/mcp/tools |
List MCP tools (MCP tools/list) |
POST |
/mcp/call |
Call an MCP tool (MCP tools/call) |
What's Real vs Mocked
| Component | Demo (no cluster) | Production (with cluster) |
|---|---|---|
| CockroachDB MCP Server | Mock transport (simulates all 15 tools) | Real MCP server via stdio/HTTP |
| Memory storage | SQLite (file-based, persists across restarts) | CockroachDB (distributed ACID) |
| Full-text search | SQLite FTS5 | CockroachDB ILIKE |
| AWS S3 backup | In-memory mock | Real S3 with boto3 |
| Agent response generation | Rule-based (no LLM key needed) | LLM (GPT-4, Claude) with memory context |
The mock transport is not a fake — it faithfully implements the full MCP tool surface so the agent exercises the real MCP integration path. Swapping to a real cluster is a one-line config change (CRDB_DATABASE_URL).
Real-World Usefulness
Production AI agents (DevOps automation, code review, trading, customer support) need persistent memory that:
- Survives restarts (process crashes, deploys, scaling)
- Scales globally (multi-region, low-latency access)
- Provides audit trails (compliance, debugging)
- Backs up automatically (disaster recovery)
- Integrates with frameworks (LangChain, MCP clients)
A platform team would deploy Cockroach Memory Agent as the memory backend for their agent fleet.
License
Apache 2.0
Links
- Live demo: https://cockroach-memory-agent.vercel.app
- GitHub: https://github.com/0xConsole/cockroach-memory-agent
- CockroachDB MCP Server: https://github.com/cockroachdb/cockroachdb-mcp-server
- MCP Protocol: https://modelcontextprotocol.io
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.
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.
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.
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.