persistent-memory

persistent-memory

A self-hostable MCP server that provides permanent memory for AI agents using Postgres + pgvector for semantic search and Markdown file sync.

Category
Visit Server

README

persistent-memory

Give any AI agent a permanent memory.

Most AI assistants forget everything the moment a conversation ends. This is the infrastructure that fixes that — a self-hostable memory layer any Claude (or other LLM) client can read from and write to, over the Model Context Protocol. Your notes, decisions, and project state live in a Postgres + pgvector store, stay searchable by meaning (not just keywords), and mirror to plain Markdown files you own.

Built and used in production as the memory behind a personal knowledge vault. Extracted here as a clean, reusable starting point.


What you get

Piece What it does
MCP server (server/) A Cloudflare Worker exposing five tools — search_vault, read_file, write_page, append_to_page, delete_page — over MCP HTTP transport. Point any Claude client at it and the model gains long-term memory.
Vector store (migrations/) Postgres schema for pages + chunks with pgvector (halfvec) embeddings and a search_chunks similarity RPC. Runs on any Postgres with the vector extension (Supabase, Neon, plain PG).
Bulk embedder (src/embed.ts) Reads a folder of Markdown, chunks it (~500 tokens), embeds it, and upserts to the store. One command to load your whole knowledge base.
File-sync mirror (src/sync.ts) Watches a local folder and keeps files ⇄ database in sync both ways, so you can edit in any editor and the memory stays current.

How it works

  Any LLM client ──MCP──▶  Worker (5 memory tools)  ──▶  Postgres + pgvector
        ▲                                                      │
        └───────────  semantic search results  ◀──────────────┘

  Your Markdown folder  ⇄  file-sync  ⇄  same database   (edit anywhere, stays in sync)

The database is the source of truth; the Markdown files are a backup mirror you can read, grep, and edit offline. Every write re-embeds only what changed, so ongoing cost is pennies.

Quick start

  1. Provision a Postgres with pgvector (Supabase is easiest — the vector extension is one click). Run the SQL in migrations/ in order.
  2. Configure secrets (never commit these):
    • SUPABASE_URL — set in server/wrangler.toml [vars] (replace YOUR_SUPABASE_PROJECT_REF)
    • SUPABASE_SERVICE_ROLE_KEY, OPENAI_API_KEY, AUTH_TOKENwrangler secret put each
  3. Bulk-load your notes: npm install && npm run embed
  4. Deploy the memory server: cd server && npx wrangler deploy
  5. Connect a client — add the worker URL as an MCP connector. Auth is via URL path (POST /mcp/<AUTH_TOKEN>) because some clients don't send Bearer headers.

Design notes

  • Embeddings: OpenAI text-embedding-3 by default; swap the provider in src/embed.ts.
  • Auth: single shared AUTH_TOKEN in the URL path. For multi-tenant use, issue one token per agent and validate against a table.
  • Cost: one-time bulk embed is a few dollars for a large vault; ongoing sync is pennies/day.

How this pairs with Mothership long-session memory

These solve different amnesia problems:

Problem Layer Where
“The chat forgot what we decided three hours ago when the window rolled over” Conversation continuity — Persistent State ledger + verbatim tail + exact recall over the transcript archive Mothership (docs/long-session-memory.md)
“The model doesn’t know my projects, rules, or past work across any chat” Long-term knowledge — searchable Markdown vault + embeddings This repo

Use both. Mothership keeps a single long thread coherent; persistent-memory keeps your wiki available to every agent. Neither should store secrets as pasted values — point at env files / secret stores.

See also docs/memory-layers.md.

License

MIT — see LICENSE. Use it, fork it, build your own memory on it.


<sub>Built by lennymadethat.</sub>

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured