A persistent long-term memory system for AI clients
š§ Digital Brain MCP
A Second Brain powered by Model Context Protocol (MCP), Google Gemini Embedding 2, and Supabase pgvector ā deployed on Vercel.
Connect any MCP-compatible AI client (Claude, Cursor, OpenCode, Copilot, etc.) and give it persistent long-term memory. Store text, images, PDFs, audio, and video ā all embedded in a unified vector space for cross-modal semantic search.
Architecture
AI Client (Claude / Cursor / OpenCode / Copilot)
ā
ā¼ MCP Protocol (Streamable HTTP + SSE)
ā Authorization: Bearer <api-key>
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Vercel (Next.js) ā
ā /api/mcp/[transport] ā
ā ā
ā āāā Auth Middleware āāā ā
ā ā Bearer token check ā ā
ā āāāāāāāāāāāāāāāāāāāāāāā ā
ā ā
ā Tools: ā
ā ⢠store_memory (text) ā
ā ⢠store_file (base64 upload) ā
ā ⢠store_file_from_url (URL fetch) ā
ā ⢠search_memory (cross-modal) ā
ā ⢠get_file_url (signed download) ā
ā ⢠list_memories ā
ā ⢠update_memory ā
ā ⢠delete_memory ā
ā ⢠get_stats ā
ā ā
ā REST Endpoint: ā
ā ⢠POST /api/upload (direct file) ā
āāāāāāāāāāāā¬āāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāā
ā ā
āāāāāāā“āāāāāā āāāāā“āāāāāāāāāāāāāāā
ā¼ ā¼ ā¼ ā¼
āāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāā
ā Gemini ā ā Supabase ā ā Supabase ā
ā Embed 2 ā ā PostgreSQL ā ā Storage ā
ā API ā ā + pgvector ā ā (files) ā
ā ā ā vector(768) ā ā ā
āāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāā
Multimodal Embedding
Gemini Embedding 2 maps all modalities into the same 768-dimension vector space. This means:
- A text query like "architecture diagram" can find a stored PNG image
- Searching for "meeting notes" can return an audio recording of a meeting
- A PDF of a research paper and a text summary live side by side in the same search space
Supported File Types
| Modality | MIME Types | Limits |
|---|---|---|
| Image | image/png, image/jpeg, image/webp, image/gif |
Up to 6 per request |
application/pdf |
Up to 6 pages | |
| Audio | audio/mpeg, audio/wav, audio/ogg, audio/mp3, audio/aac, audio/flac |
ā |
| Video | video/mp4, video/quicktime, video/webm |
Up to 120 seconds |
Interleaved Embedding
When you provide a description alongside a file, the system creates an interleaved embedding ā a single vector that captures both the visual/audio content AND your text description. This produces significantly richer search results compared to embedding the file alone.
How It Works
- You say (in Claude/Cursor/etc): "Remember that the EBR system uses Azure Functions for the API layer"
- MCP client calls your Digital Brain's
store_memorytool - Gemini Embedding 2 converts the text into a 768-dimension vector
- Supabase stores the text + vector in PostgreSQL with pgvector
- Later, you ask: "What tech does the EBR system use?"
search_memoryembeds your query, runs cosine similarity search, returns the matching memory
For files, the flow is the same ā except the file bytes are sent to Gemini for multimodal embedding, and the raw file is stored in Supabase Storage with a signed download URL generated on retrieval.
Security Model
The server uses Bearer token authentication on every request:
- Fail-closed: If no API keys are configured, ALL requests are rejected
- Multi-key support: Set multiple comma-separated keys in
DIGITAL_BRAIN_API_KEYSso each client gets its own key (and you can rotate independently) - Row Level Security (RLS): Enabled on the Supabase
memoriestable ā onlyservice_rolecan access data. The anon key has zero access. - Service Role Key: Only stored server-side in Vercel env vars, never exposed to clients
- Private Storage: The
brain-filesbucket is private ā files are only accessible via time-limited signed URLs (1 hour expiry)
Generating API Keys
# Generate a strong 256-bit key
openssl rand -hex 32
Tech Stack
| Component | Technology | Purpose |
|---|---|---|
| Embeddings | Gemini Embedding 2 (gemini-embedding-2-preview) |
Multimodal embeddings ā text, images, audio, video, PDF all in one vector space |
| Vector DB | Supabase + pgvector | PostgreSQL with vector similarity se |
Tools (9)
store_memoryStores text-based memory in the vector database.store_fileStores a file using base64 encoding.store_file_from_urlFetches and stores a file from a provided URL.search_memoryPerforms cross-modal semantic search across stored memories and files.get_file_urlGenerates a signed download URL for a stored file.list_memoriesLists stored memories.update_memoryUpdates an existing memory entry.delete_memoryDeletes a memory entry.get_statsRetrieves statistics about the stored memory.Environment Variables
DIGITAL_BRAIN_API_KEYSrequiredComma-separated API keys for authentication.SUPABASE_URLrequiredThe URL of your Supabase project.SUPABASE_SERVICE_ROLE_KEYrequiredThe service role key for Supabase database access.GOOGLE_API_KEYrequiredAPI key for Google Gemini Embedding 2.Configuration
{"mcpServers": {"digital-brain": {"command": "npx", "args": ["-y", "@dswillden/digital-brain-mcp"], "env": {"DIGITAL_BRAIN_API_KEYS": "your-secret-key", "SUPABASE_URL": "your-url", "SUPABASE_SERVICE_ROLE_KEY": "your-key", "GOOGLE_API_KEY": "your-key"}}}}