---
title: "Build a Persistent AI Memory System on Cloudflare"
canonical_url: "https://techvoyage.dev/article/use-cloudflare-as-ai-memory"
last_updated: "2026-10-20T09:53:39.815Z"
meta:
  description: "Learn how to build a persistent, self-hosted AI memory system on Cloudflare using Second Brain and MCP. Share context across Claude, Gemini, and Obsidian."
  "og:description": "Learn how to build a persistent, self-hosted AI memory system on Cloudflare using Second Brain and MCP. Share context across Claude, Gemini, and Obsidian."
  "og:title": "Build a Persistent AI Memory System on Cloudflare"
  "twitter:description": "Learn how to build a persistent, self-hosted AI memory system on Cloudflare using Second Brain and MCP. Share context across Claude, Gemini, and Obsidian."
  "twitter:title": "Build a Persistent AI Memory System on Cloudflare"
---

[Home](https://techvoyage.dev/)

![A personal self-hosted AI memory system deployed on Cloudflare Workers and Vectorize using the Model Context Protocol (MCP) and Obsidian sync.](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/EN-Use-Cloudflare-as-AI-memory.webp) # **Build a Persistent AI Memory System on Cloudflare**

Learn how to build a persistent, self-hosted AI memory system on Cloudflare using Second Brain and MCP. Share context across Claude, Gemini, and Obsidian.

Aug 7, 2026 -7 MIN READ

[**Cloudflare**](https://techvoyage.dev/category/cloudflare) [**AI & Agents**](https://techvoyage.dev/category/ai-agents)

<details>

<summary>Table of contents</summary>



</details>

## The Importance of Persistent AI Memory for Agents

As AI assistants become integrated into our daily lives, we frequently encounter the blank context issue. The decisions made last week are forgotten, requiring us to input the same tech stack details, and set the user preferences all over again.

Instead of starting from scratch every time, we need to build a memory system that evolves, continuously understands a user's decisions and eliminates the need to repeat context.

## Self-Hosted vs. Built-In AI Memory Systems

Many AI agents come with built-in memory, but we don't just use one agent for all purposes. We use Claude for architecting and designing a project; Kimi for coding; and ChatGPT for research. The context is not shared among these agents; it remains siloed per agent.

From a software engineering point of view, we don't trust black boxes. We need AI memory system that is observable, auditable, and under our control. The open sourced project, [**Second Brain**](https://github.com/Tech-Voyage-Dev/second-brain-cloudflare/tree/main), forked from [**https://github.com/rahilp/second-brain-cloudflare**](https://github.com/rahilp/second-brain-cloudflare), provides a persistent and self-hosted memory system with Model Context Protocol (MCP) support. Any compatible AI agents such as Claude, ChatGPT, Kimi Code can share the same context.

## How to Build a Second Brain AI Memory on Cloudflare

The Second Brain memory system is deployed on **Cloudflare Workers**, which provides globally distributed, low-latency execution server infrastructure. This allows the memory recall and other operations to execute with minimal latency to the AI’s reasoning loop.

The **Workers AI** embedding model is used for generating the embeddings. These embeddings are stored in **Cloudflare Vectorize**, which is a globally distributed vector database. The **Cloudflare Vectorize** performs the cosine similarity search for semantically related memories.

Duplication detection and smart merging mechanisms are implemented in Second Brain. Content with less than 85% similarity is stored, otherwise it is blocked or marked as a duplicate candidate. Text exceeding 1,600 characters is split at sentence or line-break boundaries with 200-character overlap to prevent loss of context. Then each chunk is embedded as a vector which allows precise matching.

The following tools are exposed as MCP interfaces to be used in AI agents: - `**remember**`: Store ideas, decisions, preferences, and project context - `**append**`: Add an update to an existing memory - `**update**`: Replace an existing memory - `**recall**`: Find memories by meaning rather than exact wording - `**list_recent**`: Browse recently saved memories - `**forget**`: Permanently delete a memory - `link/connections``: Connect related memories (v2 graph feature) ### Setup Second Brain on Cloudflare 1. Click on `**Deploy to Cloudflare**` at the [**Github repo**](https://github.com/Tech-Voyage-Dev/second-brain-cloudflare) page. [[![GitHub page with the Deploy to Cloudflare button highlighted](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/deploy-to-cloudflare-button.webp)]] 2. Fill out the Cloudflare Worker form. ![Cloudflare Workers deployment configuration form](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/cloudflare-worker-deployment-form.webp) 3. Enter '384' for Dimensions; select 'cosine' for Metric; and click the Deploy button. ![Cloudflare Vectorize database creation settings screen](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/cloudflare-vectorize-configuration.webp) 4. The following is the overview of the Second Brain in Cloudflare Worker ![Overview dashboard of the deployed Second Brain worker](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/cloudflare-worker-second-brain-overview.webp) 5. Click on 'Settings', then click edit icon for 'AUTH_TOKEN' for creating a token ![Cloudflare Worker variable settings highlighting AUTH_TOKEN](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/cloudflare-worker-auth-token-settings.webp) 6. Click the 'Rotate' link for entering a new value ![AUTH_TOKEN variable modification and rotation screen](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/cloudflare-worker-auth-token-rotate.webp)![Entering the generated random string into the AUTH_TOKEN value field](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/cloudflare-worker-auth-token-value-input.webp) 7. Run the command `**openssl rand -base64 32**` at macOS terminal to create a random value and paste it in the 'Value' input field. 8. Click the 'Deploy' button to update the new value of 'AUTH_TOKEN'. 9. Open the Second Brain worker url on the web browser ![Second Brain Web UI login screen with Bearer Token input](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/second-brain-web-ui-login.webp) 10. Enter the created 'AUTH_TOKEN' in the `**Bearer token**` input field and click 'Connect' button to login to the Web UI. ### Integrating Claude Desktop via MCP 1. Click on 'Customize' at Claude Desktop. ![Claude Desktop interface pointing to the Customize button](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-customize-button.webp) 2. Click on 'Developer' to manually edit the MCP Servers config file ![Claude Desktop Developer settings menu to access MCP config](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-developer-menu.webp) 3. Add the following code to the `**mcpServers**` section in `**claude_desktop_config.json**`

```
    "second-brain": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://<your-worker-url>/mcp",
        "--header",
        "Authorization: Bearer <your-token>"
      ]
    }
```![Claude Desktop MCP configuration JSON containing the Second Brain server](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-mcp-config-json.webp)4. Restart Claude Desktop and check the 'Local MCP servers'. The status says 'running'![Claude Desktop displaying running status for the Second Brain MCP server](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-mcp-status-running.webp) ### Integrating Claude Code via MCP - Run the following command to add the MCP```
claude mcp add --transport http second-brain https://<your-worker-url>/mcp
```- Claude Code detects that the endpoint requires OAuth and will open the login page at the web browser for entering `**AUTH_TOKEN**`- Create the `**CLAUDE.md**` file in `**~/.claude**` folder with the instructions from  [**CLAUDE_INSTRUCTIONS.md**](https://github.com/rahilp/second-brain-cloudflare/blob/main/AI_Instructions/CLAUDE_INSTRUCTIONS.md). ### Integrating Gemini CLI via MCP 1. Add the following MCP server settings to './.gemini/settings.json'```
    "second-brain": {
      "httpUrl": "https://<your-worker-url>/mcp",
      "oauth": {
        "enabled": true
      }
    }
```1. Start the Gemini CLI ### Test Second Brain in AI Agents 1. Started with a simple brand palette settings in '**Claude Desktop**', the Second Brain is not called. ![First test in Claude Desktop without the Second Brain memory layer active](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-first-run-brand-palette.webp) 2. Tried with the keyword, 'remember', only `**memory_user-edits**` tools in '**Claude Desktop**' are used but not Second Brain. ![Claude Desktop falling back to local built-in user edits instead of Second Brain](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-remember-built-in-tool-fallback.webp) 3. Tried the the following prompt in '**Claude Code**', Second Brain was called.```
Remember Our brand palette uses \`#1a1a2e\` as primary, \`#16213e\` as secondary, and \`#e94560\` as accent. Never use pure black."
```![Claude Code terminal window showing successful trigger of the Second Brain MCP](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-code-second-brain-mcp-called.webp)4. Verified the colour settings in the **Second Brain at Cloudflare**![Verifying the saved brand color codes in the Second Brain database Web UI](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/second-brain-web-ui-color-verification.webp) - _The reason Claude Code worked was because the CLAUDE_INSTRUCTIONS.md contains the 'Second Brain' keywords._ 5. Included 'Second Brain' as keywords in '**Claude Desktop**', need to be explicitly specified to store to and retrieve from the Second Brain memory layer. ![Triggering Second Brain in Claude Desktop by explicitly mentioning keywords](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/claude-desktop-second-brain-explicit-trigger.webp) 6. The keywords, 'Second Brain', need to be mentioned in the **Gemini CLI** to trigger the Second Brain MCP. ![Gemini CLI terminal window demonstrating successful Second Brain MCP calls](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/gemini-cli-second-brain-trigger.webp) - _Adding similar instructions to GEMINI.md like what has been done in CLAUDE_INSTRUCTIONS.md will trigger the Second Brain without mentioning the keywords._### Web Browser Extensions - Extensions are available for Chrome, Firefox and Microsoft Edge web browsers. - The extensions are for  - **Capture the current page** — saves the title and URL to the Second Brain  - **Capture highlighted text** — select any text on a page before clicking capture; the excerpt is saved alongside the title and URL  - **Add a note** — type context or  `**#hashtags**` in the popup before saving; hashtags are automatically extracted as tags ### Syncing Personal Knowledge with the Obsidian Plugin - Obsidian plugin is available to sync the notes from the Obsidian Vault to Second Brain at Cloudflare. - Notes can be tagged for syncing to the Second Brain #### Install Obsidian Plugin 1. Open Obsidian → Settings → Community Plugins ![Obsidian settings panel navigating to the Community Plugins section](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-settings-community-plugins.webp) 2. Click on 'Browse' button ![Obsidian community plugins search page showing the Browse button](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-community-plugins-browse.webp) 3. Search for 'Second Brain Sync' ![Searching for Second Brain Sync plugin in Obsidian marketplace](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-community-plugins-search-second-brain.webp) 4. Click 'Install' button then 'Enable' button ![Installing and enabling the Second Brain Sync plugin in Obsidian](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-plugin-install-and-enable.webp) #### Configure Obsidian Plugin 1. Open Obsidian → Settings → Second Brain Sync 2. Enter the 'URL' and 'Auth token' ![Entering Worker URL and Auth Token in Obsidian plugin settings](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-plugin-configuration-credentials.webp) 3. Click 'Test' button to verify it is connected. ![Obsidian plugin connection test showing successful verification](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-plugin-connection-test-success.webp) 4. Configure the sync behaviours. Set the 'Sync tag' and enable 'Auto-sync on save'. ![Configuring Sync Tag and enabling Auto-sync on save in Obsidian](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-plugin-sync-behavior-settings.webp) 5. Create a note in Obsidian with the tag, 'second-brain', as it was configured as the 'Sync tag'. ![Creating a new Obsidian note tagged with second-brain for synchronization](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/obsidian-note-with-sync-tag.webp) 6. The note has been saved and synced to the Second Brain deployed at Cloudflare. ![Verifying the successfully synchronized Obsidian note in Second Brain Web UI](https://inimages.techvoyage.dev/articles/Use%20Cloudflare%20as%20AI%20memory/second-brain-web-ui-synced-note-verification.webp) ## Conclusion Second Brain provides an open-source solution to one of the most frustrating issues in AI: persistent memory. By combining it with Cloudflare infrastructure, it delivers a fully self-hosted memory layer that is globally distributed with low latency. The MCP tools built into Second Brain make this memory portable across all AI agents. The Obsidian plugin extends the Second Brain into personal knowledge management. Notes in an Obsidian vault can be selectively synchronised to Second Brain, transforming raw notes into structured context that AI agents can semantically understand and retrieve. By combining self-hosting, semantic search, and standards-based MCP integration; Second Brain proves to be more than just a memory layer but a practical foundation for building an AI ecosystem. ## Reference: - [**https://www.thesecondbrain.dev/**](https://www.thesecondbrain.dev/) - [**https://github.com/rahilp/second-brain-cloudflare/wiki/How-It-Works**](https://github.com/rahilp/second-brain-cloudflare/wiki/How-It-Works) - [**Connect to AI Clients**](https://github.com/rahilp/second-brain-cloudflare/wiki/Connect-to-AI-Clients) - [**Second Brain Obsidian Plugin**](https://github.com/rahilp/second-brain-cloudflare/wiki/Obsidian-Plugin) - [**https://github.com/rahilp/second-brain-obsidian-plugin**](https://github.com/rahilp/second-brain-obsidian-plugin) [Share](https://api.whatsapp.com/send?text=https%3A%2F%2Ftechvoyage.dev%2Farticle%2Fuse-cloudflare-as-ai-memory) [Share](https://www.reddit.com/submit?url=https%3A%2F%2Ftechvoyage.dev%2Farticle%2Fuse-cloudflare-as-ai-memory) [Share](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftechvoyage.dev%2Farticle%2Fuse-cloudflare-as-ai-memory) [Share](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Ftechvoyage.dev%2Farticle%2Fuse-cloudflare-as-ai-memory) [Share](https://x.com/intent/post?url=https%3A%2F%2Ftechvoyage.dev%2Farticle%2Fuse-cloudflare-as-ai-memory) ## **Related Articles**[![A premium minimalist 3D illustration of the TREK self-hosted travel planner dashboard on a warm parchment background.](https://inimages.techvoyage.dev/articles/Self%20hosted%20travel%20planner%20TREK/EN-Self-hosted-travel-planner-TREK.webp)**Travel**<h3>**Self-Host Your Travel Itineraries with TREK and Docker**</h3>Learn how to deploy TREK using Docker, secure it via Cloudflare R2 and Caddy, and leverage AI agents with MCP for seamless travel planning.**22 MIN READ **](https://techvoyage.dev/article/self-hosted-travel-planner-trek) [![A premium 16:9 technology card with deep blue and orange accents illustrating how to self-host Block's Buzz relay on an Ubuntu VPS, featuring a clean glassmorphic panel with centered typography.](https://inimages.techvoyage.dev/articles/Self-Hosting%20Buzz%20As%20The%20Workspace%20Where%20AI%20Agents%20Become%20Colleagues/EN-Self-Hosting-Buzz-As-The-Workspace-Where-AI-Agents-Become-Colleagues.webp)**Collaboration**<h3>**Self-Host Block's Buzz: Shared AI Agent Workspace**</h3>Learn how to self-host Block's Buzz on a Linux VPS behind Cloudflare DNS. Run a secure, Nostr-powered workspace where humans and AI agents collaborate.**16 MIN READ **](https://techvoyage.dev/article/self-hosting-buzz-as-the-workspace-where-ai-agents-become-colleagues) [![Nuxt Scaffolding on Cloudflare: Scripts vs AI Skills - Comparing shell scripts and intelligent AI agent skills for scaffolding Nuxt applications.](https://inimages.techvoyage.dev/articles/How%20AI%20Agent%20Skills%20Replace%20Nuxt%20App%20Scaffolding%20Scripts/EN-How-AI-Agent-Skills-Replace-Nuxt-App-Scaffolding-Scripts.webp)**AI & Agents**<h3>**How AI Agent Skills Replace Nuxt App Scaffolding Scripts**</h3>Scaffold Nuxt on Cloudflare Workers easily. Learn why we replaced brittle shell scripts with AI agent skills and how to install them with npx skills.**4 MIN READ **](https://techvoyage.dev/article/how-ai-agent-skills-replace-nuxt-app-scaffolding-scripts) [![Configure Multiple Cloudflare WARP Profiles on macOS](https://inimages.techvoyage.dev/articles/Switch%20Between%20Multiple%20Cloudflare%20WARP%20Orgs%20on%20Mac/EN-Switch-Between-Multiple-Cloudflare-WARP-Orgs-on-Mac.webp)](https://techvoyage.dev/article/switch-between-multiple-cloudflare-warp-orgs-on-mac) [![Nuxt Scaffolding on Cloudflare: Scripts vs AI Skills - Comparing shell scripts and intelligent AI agent skills for scaffolding Nuxt applications.](https://inimages.techvoyage.dev/articles/How%20AI%20Agent%20Skills%20Replace%20Nuxt%20App%20Scaffolding%20Scripts/EN-How-AI-Agent-Skills-Replace-Nuxt-App-Scaffolding-Scripts.webp)](https://techvoyage.dev/article/how-ai-agent-skills-replace-nuxt-app-scaffolding-scripts)