lennymadethat

Second Brain

Community lennymadethat
Updated

Second Brain — persistent memory for any AI agent. Rulebook + MCP memory server + hosted vector library. Self-hostable, MIT.

Second Brain

Persistent memory for any AI agent.

How Second Brain works: a rulebook at the front, a librarian in the middle that chops and vectorizes every page, and a library at the back that any agent can search

Every assistant forgets the moment the chat ends. Second Brain is the memorythey keep: a folder of Markdown pages you own, held in a hosted database witha vector index so they can be found by meaning, and served to any agent overthe Model Context Protocol. Claude, ChatGPT,Grok, Gemini, Claude Code, Codex, Cursor: if it speaks MCP, it can remember.

Three parts, one product:

Part What it is Where
The rulebook AGENTS.md: how the memory is laid out, when to append versus create, what never to write. Handed to every agent the moment it connects. AGENTS.md
The librarian An MCP memory server with five tools. Chops every page at its headings, vectorizes the pieces, files them, and answers questions. server/
The library A hosted Postgres with pgvector. Two tables: every page whole, and every page in chunks with its vectors. The rolodex is the vector index. migrations/

Plus two tools for the machine that holds your notes: a bulk loader and atwo-way file sync, so you can keep editing in any editor and the memory stayscurrent.

Built and used daily as the memory behind one person's entire working life(every project, every decision, thousands of pages). Extracted here clean.

Quick start

The fastest route is to paste KIT.md into an agent with a shelland let it do the setup. By hand:

  1. Library. A Postgres with pgvector (Supabase is one click). Run the SQLin migrations/ in order.
  2. Config. cp .env.example .env and fill it in. Never commit .env.
  3. Load. npm install && npm run embed reads your notes folder and fillsthe library. A large vault costs a few dollars once.
  4. Serve. cd server, set SUPABASE_URL in wrangler.toml,wrangler secret put the three secrets, npx wrangler deploy.
  5. Connect. Add https://<worker>/mcp/<AUTH_TOKEN> as an MCP connector inany client. The token rides in the URL because some clients cannot send abearer header. Treat the URL as a password.
  6. Sync (optional). npm run sync on the notes machine keeps folder andlibrary mirrored both ways.

The five tools

Tool Does
search_vault(query, limit?) Semantic search across every live page. Returns chunks with their page path, title, kind and heading.
read_file(path) The full page: title, kind, body, metadata, updated_at.
write_page(path, body, metadata?) Create or overwrite a page. Derives kind from the path, extracts headings and [[links]], re-chunks, re-embeds.
append_to_page(path, section, content) Insert under a ## Section, newest at top. Creates the section if missing.
delete_page(path, confirm) Soft-delete. Needs confirm: true. Hidden from search, kept in the database, restorable.

GET / is a liveness probe. GET /rules returns the rulebook. initializereturns the rulebook as MCP instructions, so a client that honours themneeds no extra prompt.

How it works

  Any agent ──MCP──▶ librarian (Worker, 5 tools) ──▶ library (Postgres + pgvector)
      ▲                    │ hands over AGENTS.md            │ pages + chunks
      └──── the right memory comes back ◀───────────────────┘

  Your notes folder ⇄ sync ⇄ the same library     (edit anywhere; you own the files)
  • Pages are chunked at ## headings, about 500 tokens each with 50 ofoverlap, then embedded with text-embedding-3-large (3072 dims, stored ashalfvec). Search embeds the question and asks the search_chunks RPC forthe nearest chunks.
  • The database is the source of truth. The folder is a mirror you can read,grep and edit offline. Every write re-embeds only the page that changed, sorunning cost is pennies.
  • Kind is derived from the path (wiki/projects/ → project, and so on), sothe folder map in AGENTS.md is also the schema.

What is in the box

AGENTS.md            the rulebook (also served on connect and at /rules)
KIT.md               paste-prompt: an agent sets the whole thing up for you
server/              Cloudflare Worker, MCP HTTP transport, 5 tools
migrations/          pages + chunks schema, search RPC, soft delete
src/embed.ts         bulk loader: folder → chunks → vectors → library
src/sync.ts          two-way mirror between the folder and the library
src/parse.ts         path → kind, title, headings, wikilinks
reconcile.mjs        repairs drift between folder and library
docs/                the explainer image and the memory-layers note
.env.example         what the local tools need

Design notes

  • Embeddings: OpenAI by default; swap the provider in one function insrc/embed.ts and one in server/src/index.ts.
  • Auth: one shared token per server. For several people, issue a token peragent and check it against a table; the compare is already constant-time.
  • Local-only mode (local Postgres + local embedder, no cloud) is not builtyet. The hosted version is the product.

Pairs with Mothership

Second Brain solves "the model does not know my projects, rules or past workacross any chat". A different amnesia, "this long session forgot what wedecided three hours ago", is solved byMothership's state ledger,transcript tail and exact recall. Use both. Seedocs/memory-layers.md.

License

MIT. Use it, fork it, build your own memory on it.

Made by lennymadethat.

MCP Server · Populars

MCP Server · New

    SylphxAI

    anymd

    Any file → clean Markdown for AI agents: PDF, Word, PowerPoint, Excel, EPUB, HTML and web pages, images (OCR), audio and video (metadata, subtitles, transcripts). A fast Rust MCP server and CLI that runs on your machine. No API key.

    Community SylphxAI
    nokia-steward

    Redfish MCP Server

    MCP Server

    Community nokia-steward
    getsentry

    mobilebuildmcp

    A Model Context Protocol (MCP) server and CLI that provides tools for agent use when working on iOS and macOS projects.

    Community getsentry
    feder-cr

    invisible_playwright_mcp

    Your AI agent browses the web without captchas: self-hosted Python MCP server on undetected anti-detect stealth Firefox, for browser automation, scraping, computer use.

    Community feder-cr
    odds-api

    odds-api/odds-api

    OpenAPI sports betting odds API for coding agents with REST examples, SDKs, MCP, mock mode, arbitrage, positive EV, and bookmaker comparison.

    Community odds-api