Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ explicitly under **Changed**, with what to do about it.

## [Unreleased]

### Added

- **Connect your brain in Claude on the web and on your phone.** `brain mcp --http`
serves one person's brain over HTTPS, `brain mcp-router` gives a company one address
and sends each person to their own brain, and a new `brain_capture` tool saves a note
into the person's Inbox. Sign-in is handled by an identity edge in front (Cloudflare
Access is documented); brainkit only checks the signed identity it attaches. Saved
notes wait in a per-person spool, and `brain cycle --spool-root DIR` files them into
the Inbox. It needs the optional extra `brainkit[remote]`; nothing changes for a
deployment that doesn't use it. See [Remote Access](https://brainkit-docs.vercel.app/guides/remote-access).

### Fixed

- `brain-liveness.sh` no longer reports systemd template units (such as
`brain-mcp@.service`) as down, and now checks their running instances. Its
`HEALTHCHECK_URL` error message no longer breaks the script under macOS's `sh`.

## [0.8.0] - 2026-10-05

### Added
Expand Down
8 changes: 6 additions & 2 deletions deploy/brain-box/brain-liveness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
# /usr/local/sbin/brain-liveness.sh >> /var/log/brain-liveness.log 2>&1
set -eu

: "${HEALTHCHECK_URL:?set HEALTHCHECK_URL (hc-ping.com check for this box's services)}"
: "${HEALTHCHECK_URL:?set HEALTHCHECK_URL (hc-ping.com check for this box services)}"

units="$(systemctl list-unit-files 'brain-*.service' --state=enabled --no-legend | awk '{print $1}')"
# Unit files list templates (brain-mcp@.service), which are never "active";
# check the running instances of a template instead.
files="$(systemctl list-unit-files 'brain-*.service' --state=enabled --no-legend)"
live="$(systemctl list-units 'brain-*@*.service' --all --no-legend --plain)"
units="$(printf '%s\n%s\n' "$files" "$live" | awk '$1 != "" && $1 !~ /@[.]service$/ {print $1}')"

down=""
for u in $units ${EXTRA_UNITS:-}; do
Expand Down
34 changes: 34 additions & 0 deletions deploy/brain-box/brain-mcp-router.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# systemd unit: the company's remote-MCP router (`brain mcp-router`).
# Verifies the edge's identity and forwards each person to their own
# brain-mcp@<id>. It holds no vault and can see nothing under /srv/brain.
#
# Needs brainkit[remote], /etc/brain/mcp.env (as brain-mcp@.service) and
# /etc/brain/mcp-routes.yaml:
# version: 1
# routes:
# alice@acme.com: 8901
# The router reloads the routes file when it changes; no restart needed.
# Point the edge tunnel (cloudflared) at http://127.0.0.1:8900.

[Unit]
Description=brainkit remote MCP router
Documentation=https://github.com/joedanz/brainkit
After=network-online.target
Wants=network-online.target

[Service]
User=brain
EnvironmentFile=/etc/brain/mcp.env
ExecStart=/usr/local/bin/brain mcp-router --routes /etc/brain/mcp-routes.yaml --port 8900
Restart=on-failure
RestartSec=5

NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=read-only
InaccessiblePaths=/srv/brain
PrivateTmp=true
MemoryMax=256M

[Install]
WantedBy=multi-user.target
43 changes: 43 additions & 0 deletions deploy/brain-box/brain-mcp@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# systemd template: one person's remote MCP server (`brain mcp --http`).
# Instance = person id: brain-mcp@alice serves /srv/brain/compiled/alice.
#
# Needs:
# - brainkit installed with the remote extra: uv tool install 'brainkit[remote] @ ...'
# - /etc/brain/mcp.env BRAIN_MCP_ISSUER, BRAIN_MCP_JWKS_URL, BRAIN_MCP_AUDIENCE
# - /etc/brain/mcp.d/<id>.env BRAIN_MCP_PORT, BRAIN_MCP_EMAIL (the person's sign-in email)
# - /srv/brain/spool/<id>/ a directory owned by User= (captures queue here;
# run the cycle with --spool-root /srv/brain/spool)
# - brain-mcp-router in front, and an identity-asserting edge (Cloudflare
# Access) in front of that. See docs/guides/remote-access.
# Adjust User= (and add the embedding EnvironmentFile) for your install, e.g.
# with a drop-in, then: systemctl enable --now brain-mcp@alice
#
# Why ReadWritePaths covers all of /srv/brain/compiled: each compile swaps the
# vault directory (a bind on the old one goes stale) and SQLite writes the WAL
# -shm file even for read-only opens. This is the same reach the per-person
# dashboard units have; the process itself serves only its one --vault.

[Unit]
Description=brainkit remote MCP for %i
Documentation=https://github.com/joedanz/brainkit
After=network-online.target
Wants=network-online.target

[Service]
User=brain
EnvironmentFile=/etc/brain/mcp.env
EnvironmentFile=/etc/brain/mcp.d/%i.env
ExecStart=/usr/local/bin/brain mcp --http --vault /srv/brain/compiled/%i --person %i --person-email ${BRAIN_MCP_EMAIL} --port ${BRAIN_MCP_PORT} --spool /srv/brain/spool/%i
Restart=on-failure
RestartSec=5

NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=/srv/brain/compiled /srv/brain/spool/%i
InaccessiblePaths=-/srv/brain/master
PrivateTmp=true
MemoryMax=512M

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"getting-started",
"guides/onboarding",
"guides/per-employee-setup",
"guides/remote-access",
"guides/graph-view",
"guides/pages",
"guides/getting-things-in",
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/deployment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ The tenant wall in this system is *physical*: it holds only where a personal age

The compiler guarantees that a person's *vault* contains only what they may see. That guarantee is about what gets written to disk. It says nothing about what a process running as your OS user can `open()` elsewhere on that disk. Keeping agents to one-vault-per-host (device or container mount) is what preserves the boundary at runtime.

<Callout type="info">
[Remote access](/guides/remote-access) does not change this rule. `brain mcp-router` is not
a personal agent and holds no vault; each `brain mcp --http` process serves exactly one
person's compiled vault and answers only to that person.
</Callout>

## Server-side jobs are different

The **server assistant** agent is *supposed* to have full master access — it ingests transcripts, routes knowledge, and maintains dashboards across all spaces. Run it with master access, on cron and on Inbox drops. The deployment rule above is about *personal* agents, which must never see more than their one slice.
Expand Down
187 changes: 187 additions & 0 deletions docs/guides/remote-access.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
---
title: Remote Access
description: Connect each person's brain to Claude on the web and on their phone.
icon: plug
---

`brain mcp` over stdio only works for tools that can start a program on your own computer, like Claude Code. Claude on the web and in the phone app can only reach a server over HTTPS. Remote access gives each person a private address that Claude can reach, so they can search, read and save notes in their own brain from anywhere.

One connector, one address per company. Everyone clicks **Connect** and signs in with their work email.

## How it fits together

```
Claude (web, phone, Code)
│ HTTPS, signed in through your identity edge
▼
Cloudflare Access runs the sign-in (OAuth) and signs each request
│
▼
brain mcp-router checks the signature, finds that person's port
│ (holds no vault)
├─▶ brain mcp --http (alice) reads compiled/alice only
│ saves to spool/alice only
└─▶ brain mcp --http (bob) reads compiled/bob only
saves to spool/bob only
```

brainkit does not run the sign-in. An identity edge in front of it does, and brainkit only checks the signed note the edge attaches to each request. Cloudflare Access is what this guide describes; the check is generic, so another edge that signs requests the same way works with a settings change.

<Callout type="info">
**The tenant wall still holds.** Each `brain mcp --http` process is given exactly one
compiled vault and answers only to that person's email. The router never opens a vault.
Three separate checks stand between a request and a vault: the edge's list of allowed
emails, the router's route table, and the vault process's own pinned email. A wrong route
is refused, never served. See the [deployment rule](/guides/deployment).
</Callout>

## Connect in Claude

<Steps>
<Step title="Add the connector once">
On a Claude Team or Enterprise plan, an owner goes to **Settings → Connectors → Add
custom connector** and pastes the company address your admin gave you
(for example `https://mcp-acme.example.com/mcp`). Everyone in the organization then
sees it. On other plans, each person adds the same address themselves.
</Step>

<Step title="Each person clicks Connect">
Claude opens a sign-in page. Sign in with your work email. The first time, you'll be
asked to allow Claude to use your brain.
</Step>

<Step title="Ask about your brain">
Try "what changed in my brain this week?" or "save a note: Ana prefers aisle seats."
Notes you save appear in your Inbox after the next sync, usually within a few
minutes.
</Step>
</Steps>

<Callout type="info">
If the sign-in page says **Invalid nonce**, it just waited too long. Click **Connect**
again.
</Callout>

<Callout type="info">
Claude remembers a connector's tool list from when it was first connected. If you
connected before saving notes was available, **Disconnect** and **Connect** the connector
once and `brain_capture` will appear.
</Callout>

## What Claude can do

The same six read tools as `brain mcp` (`brain_search`, `brain_read`, `brain_links`,
`brain_graph`, `brain_recent`, `brain_facts`), plus **`brain_capture`**, which saves a note
into your Inbox. Claude cannot edit or delete existing notes this way.

## Set it up by hand

If you run brainkit without Fleet, here is every piece. You need a Cloudflare account with
Zero Trust, and `brainkit[remote]` installed on the brain box:

```bash
uv tool install 'brainkit[remote] @ git+https://github.com/joedanz/brainkit@<release tag>'
```

The shipped units run `/usr/local/bin/brain`. `uv tool install` puts the program in the installing user's own folder, so link it once (`ln -s ~/.local/bin/brain /usr/local/bin/brain`), or change `ExecStart=` in both unit files to the real path (`which brain`).

<Steps>
<Step title="Create the Cloudflare pieces">
1. A tunnel that sends one hostname (say `mcp-acme.example.com`) to
`http://127.0.0.1:8900`.
2. A **self-hosted Access application** on that hostname with **Managed OAuth** turned
on: dynamic client registration enabled, allowed redirect addresses
`https://claude.ai/api/mcp/auth_callback` and
`https://claude.com/api/mcp/auth_callback`, and localhost and loopback allowed (for
Claude Code).
3. An **allow** policy listing your staff's work emails.
4. Note the application's **AUD tag** and your team's address
(`https://<team>.cloudflareaccess.com`).
</Step>

<Step title="Write the shared settings">
`/etc/brain/mcp.env` (no secrets in it):

```bash
BRAIN_MCP_ISSUER=https://<team>.cloudflareaccess.com
BRAIN_MCP_JWKS_URL=https://<team>.cloudflareaccess.com/cdn-cgi/access/certs
BRAIN_MCP_AUDIENCE=<the application's AUD tag>
```
</Step>

<Step title="Add each person">
For each person (`alice` here), a settings file `/etc/brain/mcp.d/alice.env`:

```bash
BRAIN_MCP_PORT=8901
BRAIN_MCP_EMAIL=alice@acme.com
```

a spool folder for saved notes, owned by the user the service runs as:

```bash
install -d -o brain -m 0700 /srv/brain/spool/alice
```

<Callout type="warning">
`brain cycle` must run as the same user that owns the spool (the unit's `User=`).
A spool the cycle can't read can't be emptied; the cycle prints a warning naming the
folder, and saved notes pile up until Claude says the queue is full.
</Callout>

and the service:

```bash
install -m 644 deploy/brain-box/brain-mcp@.service /etc/systemd/system/
systemctl enable --now brain-mcp@alice
```
</Step>

<Step title="Start the router">
`/etc/brain/mcp-routes.yaml` maps each email to that person's port:

```yaml
version: 1
routes:
alice@acme.com: 8901
bob@acme.com: 8902
```

```bash
install -m 644 deploy/brain-box/brain-mcp-router.service /etc/systemd/system/
systemctl enable --now brain-mcp-router
```

The router reloads this file when it changes. A broken edit is ignored and the last
good table stays in force.
</Step>

<Step title="Let the cycle file saved notes">
Add `--spool-root /srv/brain/spool` to the [`brain cycle`](/reference/cli#brain-cycle)
line in your cron. Saved notes are filed into each person's Inbox on the next cycle.
</Step>
</Steps>

Adjust `User=` in both unit files for your install, and add an `EnvironmentFile` for your
[embedding settings](/reference/configuration#embeddings) to the per-person unit if you
want semantic search.

## Troubleshooting

Each failed request returns a small JSON body: `{"error": "<code>", "message": "..."}`.

| Code | Status | What it means |
|---|---|---|
| `unauthenticated` | 401 | No signed identity, or it is expired or from the wrong place. Check `BRAIN_MCP_ISSUER` and `BRAIN_MCP_AUDIENCE`. |
| `no_identity` | 403 | The request was signed but names no person (for example a service token). |
| `no_route` | 403 | The email is not in the route table. Add it to `mcp-routes.yaml`. |
| `wrong_person` | 403 | The router sent a request to someone else's process. Check the ports in the route table. |
| `rate_limited` | 429 | Too many requests; retry after the `Retry-After` seconds. |
| `too_large` | 413 | The request was over 1 MB. |
| `unsupported_encoding` | 415 | Compressed request bodies are not accepted. |
| `method_not_allowed` | 405 | Use `POST`. |
| `upstream_unavailable` | 503 | That person's process is down or restarting. |

If a person's brain does not answer, check `journalctl -u brain-mcp@<id>` and
`curl http://127.0.0.1:<port>/healthz`. If saved notes never appear, check that the cycle
runs with `--spool-root` and look in `/srv/brain/spool/<id>/.rejected/`.
33 changes: 31 additions & 2 deletions docs/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ This command manages the *queue and direct revokes*; it doesn't create requests.
Run the whole server-side loop once: write back every person's edits, provision any self-service [client requests](/concepts/spaces-and-permissions#self-service-client-spaces), route pending/auto-applied [share requests](/concepts/spaces-and-permissions#sharing-a-space) and apply any delegated decisions on them, sweep agent drafts into the promotions pending queue, then recompile all vaults.

```bash
brain cycle --master <master> --out <out> [--json] [--index]
brain cycle --master <master> --out <out> [--json] [--index] [--spool-root <dir>]
```

| Flag | Required | Meaning |
Expand All @@ -297,6 +297,7 @@ brain cycle --master <master> --out <out> [--json] [--index]
| `--out` | yes | Compiled-vault root — the same `--out` you pass to `compile`. |
| `--json` | no | Emit a single JSON summary object on stdout instead of human lines. |
| `--index` | no | After recompiling, refresh each vault's search index (see [`brain index`](#brain-index)). Index failures warn but never fail the cycle. |
| `--spool-root` | no | File notes saved over [remote access](/guides/remote-access) (queued under `<dir>/<person>/` by `brain mcp --http --spool`) into each person's Inbox, before write-back and the compile. A saved note that cannot be filed moves to `<dir>/<person>/.rejected/` with a warning. Run the cycle as the user that owns the spool, or the folder is skipped with a warning. A broken spool never stops the rest of the cycle. Without this flag the stage is skipped. |

### The `--json` summary

Expand Down Expand Up @@ -455,7 +456,35 @@ Register it once with a client — for Claude Code:
claude mcp add brain -- brain mcp --vault ~/brain
```

It exposes six read-only tools: `brain_search` (hybrid search, with an optional `center` note for graph-aware ranking), `brain_read` (read one file by relative path, refusing symlinks, `..` escapes, and anything outside a readable space), `brain_links` (a note's backlinks and outgoing wikilinks), `brain_graph` (a note's typed relations, each edge labeled with why it exists), `brain_recent` (recently changed notes, from the vault's git history), and `brain_facts` (time-stamped fact lines, current, as-of, or believed-on a date). It runs on the employee's device against their own vault clone, so it inherits the compiler's boundary. No HTTP, no OAuth — stdio only.
It exposes six read-only tools: `brain_search` (hybrid search, with an optional `center` note for graph-aware ranking), `brain_read` (read one file by relative path, refusing symlinks, `..` escapes, and anything outside a readable space), `brain_links` (a note's backlinks and outgoing wikilinks), `brain_graph` (a note's typed relations, each edge labeled with why it exists), `brain_recent` (recently changed notes, from the vault's git history), and `brain_facts` (time-stamped fact lines, current, as-of, or believed-on a date). It runs on the employee's device against their own vault clone, so it inherits the compiler's boundary. Plain `brain mcp` is stdio only — no HTTP, no OAuth.

### Remote mode: `--http`

For clients that can only reach a server over HTTPS (Claude on the web and on phones), `brain mcp --http` serves one person's compiled vault over HTTP on loopback. It needs the optional extra (`pip install 'brainkit[remote]'`) and sits behind [`brain mcp-router`](#brain-mcp-router) and an edge that signs each request with who it came from. See [Remote Access](/guides/remote-access).

```bash
brain mcp --http --vault <compiled/person> --person <id> --person-email <email> --port <n> [--spool <dir>]
```

| Flag | Meaning |
|---|---|
| `--http` | Serve Streamable HTTP instead of stdio. |
| `--person`, `--person-email` | The vault's owner. The process answers only to a request signed for this email, and refuses to start if the vault's manifest or folder name names someone else. |
| `--port` | Port to listen on (loopback only; `--host` accepts only loopback addresses). |
| `--spool` | Turn on the `brain_capture` tool, which queues saved notes in this folder for `brain cycle --spool-root`. |
| `--auth-issuer`, `--auth-jwks-url`, `--auth-audience`, `--auth-header` | The edge's identity settings. Each falls back to `BRAIN_MCP_ISSUER`, `BRAIN_MCP_JWKS_URL`, `BRAIN_MCP_AUDIENCE`, `BRAIN_MCP_HEADER` ([configuration](/reference/configuration#remote-access)). |

It refuses to start, with exit code 2 and a one-line reason, when the identity settings are missing, the extra is not installed, the signing keys can't be fetched from `--auth-jwks-url`, the bind address is not loopback, the vault is not a compiled vault or its manifest or folder name names someone other than `--person`, or the `--spool` folder is not a directory owned by the user running the process.

## `brain mcp-router`

Route remote requests to each person's `brain mcp --http`. One per company. It checks the edge's signed identity, looks the email up in a route table, and forwards to that person's loopback port. It never opens a vault.

```bash
brain mcp-router --routes /etc/brain/mcp-routes.yaml [--port 8900]
```

The routes file is `version: 1` plus `routes:` mapping each email to a port (1024–65535). The router reloads it when it changes and keeps the last good table if a new one is broken. It takes the same `--auth-*` settings as `brain mcp --http`. Unknown emails get a 403 `no_route`; a person whose process is down gets a 503 with `Retry-After`.

## `brain doctor`

Expand Down
Loading
Loading