Skip to main content
Glama
ai-memory-hub

ai-memory-hub

๐Ÿง  ai-memory-hub

One memory for every AI agent on every device.
A lightweight, free, private MCP server hosted on Cloudflare Workers and D1 (SQLite + FTS5) with BM25 ranked search, R2 blob attachments, and sub-5ms p95 latency.

License: MIT Cloudflare Workers SQLite FTS5 Zero Runtime Deps


๐Ÿ’ก Why This Exists

If you use multiple AI coding tools and assistants across devices (Claude Code, Cursor, OpenCode, Claude Desktop, ChatGPT):

  • Context Fragmentation: You settle on a Go config layout in one app on your laptop. Later, another app on your phone suggests something that contradicts it.

  • Starting from Zero: You spend an hour debugging a tricky CUDA tensor issue with one agent; a second agent starts from scratch.

  • Lost Knowledge: You remember solving an infrastructure problem last week, but cannot recall which tool or chat thread it was in.

Hosted memory layers like Mem0 charge recurring monthly fees, while cloud storage like Google Drive lacks ranked full-text search, safe concurrent writes, and fast edge round-trips.

ai-memory-hub gives you your own personal, high-speed memory layer that runs entirely on Cloudflare's free edge tier.


Related MCP server: Sovereign Universal Memory MCP

โœจ Highlights

  • โšก Blazing Fast: Native SQLite FTS5 with Okapi BM25 ranking runs queries in 1.5 ms โ€“ 5 ms directly at the edge.

  • ๐ŸŒ Edge Hybrid Search: Combines BM25 keyword precision with Cloudflare Workers AI (@cf/baai/bge-small-en-v1.5) and Cloudflare Vectorize cosine similarity using Reciprocal Rank Fusion (RRF).

  • ๐Ÿ”— Relational Knowledge Graph: Link memories together using related_to to solve cross-session multi-hop reasoning. Linked context is automatically bundled during retrieval.

  • ๐Ÿ”ค Domain Synonym Expansion: Zero-latency query expansion for technical terms (deploy โž” release/ship, build โž” compile, bug โž” error/fail).

  • ๐Ÿ’ธ 100% Free Forever: Operates within Cloudflare's free tier limits (5,000,000 D1 reads/day, 100,000 writes/day, 10,000 Neurons/day, 5 GB storage).

  • ๐Ÿชถ Zero Runtime Dependencies: Pure TypeScript compiled into a tiny 29 KiB script bundle with cold-starts under 1 ms.

  • ๐Ÿ”’ Private & Secure: Single-owner Bearer token authentication stored as a Cloudflare Worker secret. No public APIs, no open CORS, no tracking.

  • ๐Ÿ›ก๏ธ Context & Prompt-Injection Hardened:

    • Every search/recall response is capped at 4 KB to protect LLM context windows.

    • Historical notes are prepended with security warning banners instructing agents never to execute instructions found inside memories.

  • ๐Ÿ“Ž Large Data Support (Pattern B): Store multi-megabyte files, logs, and codebases in Cloudflare R2 ($0 egress) while keeping search summaries instant and compact.


๐Ÿ› ๏ธ The 4 MCP Tools

Tool

Parameters

Description

save_memory

kind, text, project?, supersedes?, blob?, tags?, related_to?

Saves an architectural decision, fact, preference, todo, or handoff note. Pass large files or logs in blob to store in R2. Link memories with related_to.

search

query, project?, kind?, limit?, offset?

Searches memories using hybrid BM25 + Vectorize ranking, synonym expansion, and relational link traversal. Displays ๐Ÿ“Ž BLOB badge if an attachment exists.

recall

project?, kind?, limit?, offset?

Recalls newest non-superseded memories at session start in reverse chronological order with pagination support.

read_blob

id, max_bytes?

Fetches the full raw file or log content stored in Cloudflare R2 for a memory ID on demand.

Valid memory categories (kind): decision | fact | preference | todo | handoff.


๐Ÿš€ Quickstart (5 Minutes)

1. Clone & Install

git clone https://github.com/favourthemaster/ai-memory-hub.git
cd ai-memory-hub
npm install

2. Create Cloudflare D1 Database & R2 Bucket

Make sure you are logged into Wrangler (npx wrangler login):

# Create the D1 database
npx wrangler d1 create ai-memory-hub-db

# Create the R2 bucket for large blob attachments
npx wrangler r2 bucket create ai-memory-hub-blobs

Copy the returned database_id and paste it into wrangler.toml:

[[d1_databases]]
binding = "DB"
database_name = "ai-memory-hub-db"
database_id = "<PASTE_YOUR_DATABASE_ID_HERE>"
migrations_dir = "migrations"

3. Apply SQL Migrations to Remote D1

yes | npx wrangler d1 migrations apply ai-memory-hub-db --remote

4. Set Your Secret Bearer Token

Generate a random secret token and set it in Cloudflare Workers:

# Example: generate a 32-byte hex token
node -e 'console.log("amh_live_" + require("crypto").randomBytes(24).toString("hex"))'

# Save the token as a Worker secret
npx wrangler secret put AUTH_TOKEN

5. Deploy

npm run deploy

Your MCP server is now live at: https://ai-memory-hub.<your-subdomain>.workers.dev


๐Ÿ”Œ Connecting Your AI Clients

Claude Code CLI (~/.claude.json)

Run this single command:

claude mcp add --transport http ai-memory-hub https://ai-memory-hub.<your-subdomain>.workers.dev --header "Authorization: Bearer <YOUR_AUTH_TOKEN>"

Or paste directly into ~/.claude.json:

{
  "mcpServers": {
    "ai-memory-hub": {
      "type": "http",
      "url": "https://ai-memory-hub.<your-subdomain>.workers.dev",
      "headers": {
        "Authorization": "Bearer <YOUR_AUTH_TOKEN>"
      }
    }
  }
}

OpenCode (~/.config/opencode/opencode.jsonc)

{
  "mcp": {
    "ai-memory-hub": {
      "enabled": true,
      "type": "remote",
      "url": "https://ai-memory-hub.<your-subdomain>.workers.dev",
      "headers": {
        "Authorization": "Bearer <YOUR_AUTH_TOKEN>"
      }
    }
  }
}

Cursor (.cursor/mcp.json or Settings > MCP)

{
  "mcpServers": {
    "ai-memory-hub": {
      "url": "https://ai-memory-hub.<your-subdomain>.workers.dev",
      "headers": {
        "Authorization": "Bearer <YOUR_AUTH_TOKEN>"
      }
    }
  }
}

Claude Desktop (claude_desktop_config.json)

Claude Desktop connects to local stdio bridges. Use mcp-remote:

{
  "mcpServers": {
    "ai-memory-hub": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://ai-memory-hub.<your-subdomain>.workers.dev",
        "--header",
        "Authorization: Bearer <YOUR_AUTH_TOKEN>"
      ]
    }
  }
}

๐Ÿ“Š Benchmarks (10,000 Memories)

Evaluated with 10,000 realistic engineering memories and 100 queries testing single-word, multi-word, project-scoped, and hostile inputs:

Metric

Result

Target

Min Latency

0.20 ms

-

p50 (Median) Latency

3.74 ms

-

p95 Latency

5.68 ms

< 150 ms โœ…

p99 Latency

7.31 ms

-

Max Latency

7.31 ms

-

Run the benchmark locally:

npm run benchmark

Run the relevance test suite:

npm run test:relevance

๐Ÿงช Testing

# Run all 31 unit, relevance, and integration tests
npm test

# Typecheck TypeScript
npm run check

๐Ÿ“„ License

MIT ยฉ favourthemaster

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides AI agents with persistent, searchable memory that survives across conversations using semantic search, temporal versioning, and smart organization. Enables long-term context retention and cross-session continuity for AI assistants.
    14
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides a persistent, vendor-neutral memory layer that allows AI tools and agents to share context and knowledge across different platforms while maintaining local data ownership. It enables users to store, recall, and manage structured memories through hybrid semantic search and automated context assembly.
    19 npm
    Apache 2.0
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to persistently store and retrieve memories across sessions, workspaces, and context limits so prior decisions, patterns, and knowledge remain available in future conversations.
    24 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to share a persistent, self-improving memory by ingesting, classifying, synthesizing, and retrieving knowledge from sources like Obsidian vaults, code, and transcripts through MCP and REST APIs. Provides token-optimized, tiered retrieval with full-text and semantic search so every agent session builds on accumulated context.
    5 npm
    MIT