|
| 1 | +# Local Brain (No MCP) |
| 2 | + |
| 3 | +Self-hosted Open Brain on a single LAN host: the official Supabase docker-compose stack plus an Ollama sidecar for local embeddings and two Edge Functions (`capture`, `search`) wired up for OB1's `thoughts` schema. Reached from each dev host through `curl`, via the companion [`ob1-local-http`](../../skills/ob1-local-http/) skill -- no MCP transport involved. |
| 4 | + |
| 5 | +## Why this exists (deliberate exception to canonical OB1) |
| 6 | + |
| 7 | +The canonical OB1 architecture assumes (a) Claude Code can call a remote Supabase MCP server and (b) Supabase Cloud is reachable. This recipe is intentionally for environments where neither is true: |
| 8 | + |
| 9 | +- **No third-party cloud reachable** -- the host can only talk to other LAN hosts. Supabase Cloud is off the table; everything runs on a single Linux box in the office. |
| 10 | +- **MCP feature disabled in Claude Code** -- corporate policy or a locked-down build blocks Claude Code from speaking MCP at all (stdio or remote). The canonical capture/search tools therefore can't run. |
| 11 | + |
| 12 | +So this recipe diverges from `CLAUDE.md`'s rule "MCP servers must be remote Supabase Edge Functions." It still uses Edge Functions, but exposes them as plain HTTPS endpoints -- not as MCP -- because the network won't let MCP through. The skill on each dev host calls those endpoints with `curl`. Cloud-shaped OB1 recipes that target PostgREST/Edge Functions still work locally with a base-URL swap; only the MCP transport is gone. |
| 13 | + |
| 14 | +If your environment does NOT have these constraints, use the canonical cloud OB1 instead -- this recipe trades roughly 30 minutes of setup, ~3 GB RAM, and operational complexity for the air-gapped/no-MCP property. |
| 15 | + |
| 16 | +## What you get |
| 17 | + |
| 18 | +After setup, on one office Linux host: |
| 19 | + |
| 20 | +- Postgres 15 with `pgvector` (HNSW index on a configurable embedding dim, default 768) |
| 21 | +- The full Supabase stack (Kong gateway, PostgREST, GoTrue, Realtime, Storage, Studio, Edge Functions runtime, Logflare) -- canonical, unmodified, just self-hosted |
| 22 | +- An `ollama` sidecar that the Edge Functions call for embedding generation -- dev hosts never need Ollama |
| 23 | +- A `thoughts` table that mirrors the canonical OB1 schema exactly, plus `match_thoughts(...)` and `upsert_thought(...)` RPCs with the same signatures as cloud |
| 24 | +- Three Edge Functions reachable through Kong: |
| 25 | + - `POST /functions/v1/capture` -- embed and store |
| 26 | + - `POST /functions/v1/search` -- embed query and run match_thoughts |
| 27 | + - `GET /functions/v1/list` -- recent thoughts for browsing or downstream digest skills |
| 28 | +- Supabase Studio at `http://<brain-host>:3000` -- your day-one read-only dashboard, free |
| 29 | +- A `BRAIN_URL` + `BRAIN_ANON_KEY` pair that you paste into each dev host's environment for the [`ob1-local-http`](../../skills/ob1-local-http/) skill |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +On the **brain host** (one Linux box on the office network): |
| 34 | + |
| 35 | +- Docker 24+ with Compose v2.20+ (`include:` directive required) |
| 36 | +- `git`, `openssl`, `python3` (stdlib only -- no `pip install`) |
| 37 | +- ~8 GB RAM available, ~5 GB disk for images and the embedding model |
| 38 | +- Outbound HTTPS to GitHub and to the configured Docker registry, *one-time*, for the clone and image pulls |
| 39 | +- A stable hostname or IP reachable from every dev host (e.g., `brain.local`) |
| 40 | + |
| 41 | +On each **dev host**: |
| 42 | + |
| 43 | +- `curl` |
| 44 | +- Claude Code (or any skill-aware AI tool that reads `~/.claude/skills/`) |
| 45 | + |
| 46 | +## Setup |
| 47 | + |
| 48 | +> Run all of these on the **brain host**, from this directory (`recipes/local-brain-no-mcp/`). |
| 49 | +
|
| 50 | +1. Copy `.env.example` to `.env` and edit the overlay values if you want non-defaults. The important one is `EMBED_DIM` -- see the one-way door warning below before you change it. |
| 51 | + |
| 52 | + ```sh |
| 53 | + cp .env.example .env |
| 54 | + $EDITOR .env |
| 55 | + ``` |
| 56 | + |
| 57 | +2. Run the one-time setup. It clones `supabase/supabase`, generates secrets (POSTGRES_PASSWORD, JWT_SECRET, ANON_KEY, SERVICE_ROLE_KEY, dashboard password, vault key, logflare tokens), writes them to `supabase-docker/docker/.env`, symlinks the Edge Functions into the supabase volume, and installs the SQL init scripts. |
| 58 | + |
| 59 | + ```sh |
| 60 | + ./setup.sh |
| 61 | + ``` |
| 62 | + |
| 63 | + `setup.sh` is idempotent. Re-running preserves an existing `.env` so already-captured data stays accessible. |
| 64 | + |
| 65 | +3. Bring up the stack. |
| 66 | + |
| 67 | + ```sh |
| 68 | + docker compose up -d |
| 69 | + docker compose ps |
| 70 | + ``` |
| 71 | + |
| 72 | + First boot pulls ~3 GB of images and runs the Postgres init scripts (creating the `thoughts` table, indexes, RPCs). |
| 73 | + |
| 74 | +4. Pull the embedding model into Ollama (one-time, model size depends on choice): |
| 75 | + |
| 76 | + ```sh |
| 77 | + docker compose exec ollama ollama pull "$(grep ^EMBED_MODEL supabase-docker/docker/.env | cut -d= -f2-)" |
| 78 | + ``` |
| 79 | + |
| 80 | +5. Verify reachability from the brain host itself: |
| 81 | + |
| 82 | + ```sh |
| 83 | + ANON_KEY="$(grep ^ANON_KEY supabase-docker/docker/.env | cut -d= -f2-)" |
| 84 | + curl -fsS -X POST "http://localhost:8000/functions/v1/capture" \ |
| 85 | + -H "apikey: $ANON_KEY" \ |
| 86 | + -H "Authorization: Bearer $ANON_KEY" \ |
| 87 | + -H "Content-Type: application/json" \ |
| 88 | + -d '{"content":"first thought from setup.sh smoke test","metadata":{"source":"smoke-test"}}' |
| 89 | + ``` |
| 90 | + |
| 91 | + Expected: HTTP 200 with `{"ok":true,"id":"...","fingerprint":"..."}`. |
| 92 | + |
| 93 | +6. On each dev host, install [`ob1-local-http`](../../skills/ob1-local-http/) and export the two env vars `setup.sh` printed at the end. The skill takes over from there. |
| 94 | + |
| 95 | +## Expected outcome |
| 96 | + |
| 97 | +- Claude Code on any dev host can capture and search thoughts by asking in natural language ("remember X", "what did I note about Y") and the skill translates that into `curl` against the brain. |
| 98 | +- The brain accumulates thoughts in `public.thoughts`, vector-indexed for similarity search. |
| 99 | +- Supabase Studio at `http://<brain-host>:3000` lets you browse, edit, or delete rows manually. |
| 100 | +- Nothing leaves the LAN. |
| 101 | + |
| 102 | +## The embedding model is a one-way door |
| 103 | + |
| 104 | +The `EMBED_DIM` env var is baked into the `embedding vector(N)` column when the Postgres volume is initialized. pgvector enforces this at insert time -- once the volume exists, **you cannot change `EMBED_DIM` without wiping the volume and losing all captured thoughts.** |
| 105 | + |
| 106 | +What this means in practice: |
| 107 | + |
| 108 | +- Pick `EMBED_MODEL` / `EMBED_DIM` once before first boot. |
| 109 | +- If you must change them later: |
| 110 | + 1. `docker compose down` |
| 111 | + 2. Back up first (see below) if you want to migrate data |
| 112 | + 3. `docker volume rm` the Postgres data volume (find it with `docker volume ls | grep db`) |
| 113 | + 4. Edit `supabase-docker/docker/.env` to the new dim |
| 114 | + 5. `docker compose up -d` -- Postgres re-runs the init scripts with the new dim |
| 115 | + 6. Re-embed your backed-up content via the new model |
| 116 | + |
| 117 | +The `embed.ts` helper does a dim check on every call and returns a clear error (`embedding-dim mismatch...`) if the model and the column disagree. |
| 118 | + |
| 119 | +## Backup and restore |
| 120 | + |
| 121 | +Stop the stack first, then snapshot the data volumes: |
| 122 | + |
| 123 | +```sh |
| 124 | +docker compose stop db |
| 125 | +docker run --rm \ |
| 126 | + -v "$(docker volume ls -q | grep _db-config):/from" \ |
| 127 | + -v "$(pwd)/backups:/to" \ |
| 128 | + alpine tar czf "/to/db-$(date +%F).tar.gz" -C /from . |
| 129 | +docker compose start db |
| 130 | +``` |
| 131 | + |
| 132 | +To restore: `docker compose down`, `docker volume rm` the db volume, recreate empty, untar into it, `docker compose up -d`. |
| 133 | + |
| 134 | +## Troubleshooting |
| 135 | + |
| 136 | +- **`docker compose` fails with `unknown field "include"`**: you're on Compose < 2.20. Upgrade Docker Desktop or install a current `docker compose` plugin. |
| 137 | +- **`functions` service exits with module-resolution errors against `_shared/*.ts`**: the symlinks didn't take. Check `ls -la supabase-docker/docker/volumes/functions/` -- you should see `capture`, `search`, `list`, `_shared` as symlinks pointing back at this recipe. Re-run `./setup.sh`. |
| 138 | +- **`embed.ts: did you 'ollama pull <model>'?`**: you skipped step 4. Run the `ollama pull` line. |
| 139 | +- **`embed.ts: embedding-dim mismatch`**: someone changed `EMBED_DIM` in `.env` after the volume was initialized. Either revert the env or follow the one-way-door procedure above. |
| 140 | +- **HTTP 401 from Kong**: `ANON_KEY` in `.env` and the one your dev host is using are out of sync. Re-export from `supabase-docker/docker/.env`. |
| 141 | +- **Dev host can't reach `http://<brain-host>:8000`**: confirm the brain host's firewall allows `KONG_HTTP_PORT` inbound on the office network and that the hostname resolves. |
| 142 | + |
| 143 | +## Related |
| 144 | + |
| 145 | +- [`skills/ob1-local-http`](../../skills/ob1-local-http/) -- the companion skill pack that runs on each dev host |
| 146 | +- [`docs/drafts/agent-memory-staging-base.sql`](../../docs/drafts/agent-memory-staging-base.sql) -- the canonical thoughts schema this recipe mirrors |
| 147 | +- [`server/index.ts`](../../server/index.ts) -- the canonical MCP server this recipe deliberately does NOT use as a transport |
0 commit comments