Hooks or MCP? #
An agent reaches a brain in three ways. Hooks bring the brain in without being asked: your client fires them, so the brief and the matching memories arrive whether or not the model thinks to look. Shell commands and MCP are how the agent asks the brain and writes to it. An agent with a shell types os-brain commands; MCP gives the same commands as tools, which is the only way in for an agent that cannot run a shell. All three run the same code against the same memory. Choose by what your client can do.
| Hooks and the CLI | MCP | |
|---|---|---|
| Who fires it | Your client, at session start, on every prompt and at the end. Nothing relies on the model remembering. | The model, when it decides to call a tool. The agent only gets what it asks for. |
| Needs | A client with hooks and a shell. The agents page lists them. | A client that speaks MCP, including ones with no shell. |
| Context cost | The brief once, then only what each prompt matches. | Every tool's schema in every session, used or not. |
| Flags | Whatever the agent types. A wrong flag gets a refusal that says the fix. | Typed inputs built from the same flags. The model cannot make one up. |
| Set up with | os-brain init | claude mcp add, or the same settings in your client's own config file |
One machine and an agent with a shell: use hooks and nothing else. That is what the install page sets up and it covers most people. An agent with no shell (the Claude app, a hosted agent, an IDE that runs no hooks) has MCP as its only choice. Use stdio when the client can start os-brain mcp on this machine and HTTP when it cannot. Either way, the model now decides when to read.
Both at once is fine and sometimes the right call: hooks for the brief up front, MCP for typed inputs. Just do not drop the hooks because MCP is connected. What you lose with MCP explains why.
Which transport to use #
stdio if the brain is on the same machine as the agent. Your client starts os-brain mcp itself: no port, nothing to keep running, nothing to log in to. This is the usual case.
Streamable HTTP if your client cannot start os-brain mcp itself.
$ os-brain mcp # stdio, started by the client $ os-brain mcp --http 127.0.0.1:7801 # HTTP, endpoint /mcp, bearer token required [brain] MCP on http://127.0.0.1:7801/mcp 127.0.0.1:7801 (loopback only) · 58 tools · protocol 2025-06-18 [brain] no --token given, so this process minted one: it is in /home/you/.claude/os-brain/mcp-7801.token (mode 600) and every request needs "Authorization: Bearer <it>"
The HTTP endpoint is /mcp. The root answers 404.
stdio with Claude Code #
$ cd ~/src/yours $ claude mcp add brain -s local \ -e OS_BRAIN_HOME=/home/you/src/yours/brain \ -e OS_BRAIN_PROJECT=yours \ -- os-brain mcp
OS_BRAIN_HOME is the brain directory, the one that holds brain.json. Without it the server looks for the brain from whatever directory it was started in. Your client makes no promise about which one that is. OS_BRAIN_PROJECT names the project, which the next section explains. -s local keeps the entry in your own config rather than a .mcp.json committed to the repository: for anyone on the repository without os-brain, a committed entry is a server that fails to start in every session.
Other clients take the same things in their own config file: the command os-brain mcp, the two environment variables and a name. The syntax differs and the content is the same.
Name the project or it refuses #
MCP does not tell the server which directory your client is in. When the server fronts a shared store that holds several projects, it cannot work out which one you mean. So it does not guess:
this server fronts a shared brain, so it cannot tell which project you are working in: pass _project. already here: billing-api, ops-runbooks, orchard, orchard-web Use the name this project calls itself. A project new to this brain simply names itself, and its first write creates it. A client can also declare it once in its own config, with an X-Brain-Project header, instead of passing it every call.
That refusal is what you want. Without it the server would use its own name and every project's memories would end up filed under that one name, with no warning. There are three ways to answer it:
| Where | How | When |
|---|---|---|
| Config, stdio | OS_BRAIN_PROJECT=yours in the server's env | Always, for stdio |
| Config, HTTP | X-Brain-Project: yours header | Always, for HTTP |
| Per call | _project argument on any tool | When you mean to reach another project |
Put it in config. Config cannot forget and a model can. A brain with only one project needs none of this: it already knows which project it is. A private project is never offered by name in the list.
HTTP, for a client with no shell #
# serve the brain $ OS_BRAIN_HOME=/home/you/src/yours/brain OS_BRAIN_MCP_TOKEN="$TOKEN" \ os-brain mcp --http 127.0.0.1:7801 # point the client at it, through a proxy that terminates TLS $ claude mcp add brain -s user -t http https://brain.example.com/mcp \ -H "Authorization: Bearer $TOKEN" \ -H "X-Brain-Project: yours"
The token can come from --token or from OS_BRAIN_MCP_TOKEN. The variable keeps it off the command line, where any user on the machine can read it with ps. A flag wins.
Bind to loopback and put a proxy with TLS in front. If the proxy passes its public name through as Host, name it with --allow-host brain.example.com; any other Host is refused. Or let the binary serve TLS itself:
$ OS_BRAIN_MCP_TOKEN="$TOKEN" os-brain mcp --http 0.0.0.0:7801 \
--tls-cert /etc/os-brain/cert.pem --tls-key /etc/os-brain/key.pem
TLS 1.2 is the minimum. On any address other than loopback the binary will not start without both a certificate and a token. No flag overrides that:
$ os-brain mcp --http 0.0.0.0:7801
refusing to listen on 0.0.0.0:7801 without TLS.
Off loopback this endpoint would send the token and every memory in the brain in cleartext. Pass --tls-cert and --tls-key, or bind 127.0.0.1 behind a proxy that terminates TLS
A firewall decides who can reach a port. It does nothing about who can read what passes through it, which is why an IP allow-list is no substitute for TLS. An empty host such as :7801 binds every interface and is treated as off loopback.
OAuth for hosted clients #
A hosted client that cannot be given a bearer token (above all the Claude app's custom connectors) needs OAuth instead. --public-url mounts a small authorization server inside the binary: discovery documents, dynamic client registration, PKCE with S256, tokens bound to this server's URL and rotated refresh tokens. The token you pass becomes the password on its login page and stops working as a bearer at /mcp, so it can only be tried where wrong guesses are counted.
$ os-brain mcp --http 127.0.0.1:7801 \
--public-url https://laptop.your-tailnet.ts.net \
--oauth-redirect-host claude.ai --token "$TOKEN"
[brain] OAuth for hosted clients at https://laptop.your-tailnet.ts.net: add https://laptop.your-tailnet.ts.net/mcp as a connector and type the token on the login page. /mcp takes only the tokens that login issues, not --token itself
--public-url refuses a plain http URL and refuses to run without a token. --oauth-redirect-host is refused without --public-url, since it would do nothing. The phone page walks through the whole setup.
What the server checks #
All of this follows the security section of the MCP transport spec. None of it can be switched off.
- Host and Origin are checked. Each is parsed and compared in full against the loopback names, so a web page cannot drive a server on localhost, by DNS rebinding or any other way. A request that sends an Origin must match:
--originreplaces the loopback default with a comma-separated list, or*. Host is checked on a loopback bind and whenever--allow-hostor--public-urlnames a host. Either refusal is a 403. - A POST must be
Content-Type: application/json, which a web page cannot send to another site without asking first. Anything else is a 415. - Every request needs a bearer token, loopback included. It goes in
Authorization: Bearer <token>and is compared in constant time. Without--tokena loopback server mints a new one each time it starts and writes it tomcp-<port>.token(mode 600) beside the shared store, usually~/.claude/os-brain/. Loopback keeps out other machines, not the other users and processes on this one. - Wrong tokens are counted per source address. After five, that address waits: a minute at first, doubling up to an hour, with 429 and a
Retry-Afteruntil then. While it waits nothing is compared, so a lockout cannot be used to test guesses. A separate ceiling across all addresses (100 failures in 15 minutes) stops a guess spread over many of them; one address cannot reach it alone. Behind a proxy on loopback, the last address inX-Forwarded-Foris the source. - Off loopback, TLS or nothing.
- Sessions. The initialize response returns an
Mcp-Session-Idand every later request carries it. An id the server does not know gets 404 with "session not found; re-initialize", which you see after a restart because sessions live in memory; a client that follows the spec initializes again by itself. A request with no id gets 400 once any session exists. DELETE ends a session. - GET returns 405. Nothing here runs long or streams, so an idle stream would serve no purpose.
- Protocol 2025-06-18, with 2025-03-26 also accepted. An
MCP-Protocol-Versionheader naming anything else gets 400. - Request bodies are capped at 16MB.
The tools #
Each command becomes a tool called brain_<command>, with hyphens turned into underscores, so hook-stop is brain_hook_stop. The list is generated from the CLI at startup. This build serves 58:
brain_absorb brain_axiom brain_backup brain_bootstrap brain_brief brain_capture brain_context brain_coverage brain_describe brain_dm brain_doctor brain_env brain_events brain_export brain_forget brain_get brain_global brain_help brain_history brain_hook_stop brain_import brain_init brain_kind brain_ladder brain_lead brain_log brain_map brain_measure brain_note brain_object brain_open brain_prefer brain_private brain_promote brain_prune brain_publish brain_recall brain_reindex brain_relabel brain_release brain_remember brain_restore brain_review brain_scope brain_sessions brain_share brain_snapshot brain_standard brain_stats brain_task brain_uninstall brain_update brain_utterances brain_vacuum brain_verify brain_version brain_wakeup brain_whoami
A few commands are left out on purpose. mcp, ui and channel each start a server and run until killed, so an agent that called one would hang its own session. hook-recall, hook-tool, hook-end and plugin-hook read their input from stdin. Over stdio, stdin is the channel MCP itself runs on: calling one as a tool deadlocked the connection instead of failing. hook-stop reads no stdin, so it stays. outstanding and status are other names for open; a model picking from a list does not need the same tool three times.
A tool call builds the same command line you would type and runs it through the normal CLI code, so guards, refusals and output are that code, not a copy. A refusal comes back as a tool error the model can read rather than a protocol fault. Every tool that can remove or overwrite something (forget, prune, import, restore, absorb, vacuum, relabel, update, task, share, private, whoami and uninstall) is marked destructive in its annotations. It is marked by its worst case even when the default is a dry run, so a client can ask a human first; its own guards stay just as strict either way. wakeup is marked open-world, because it runs commands the project declared.
Every tool has three extra inputs #
| Input | What it carries |
|---|---|
| args | Positional arguments as one string, exactly as they would follow the command in a shell: a recall query, an id, a subcommand such as add or list. An array is refused rather than flattened into text. |
| _project | The project this session is working in. It wins over the header and the environment. |
| _session | Who is calling, separate from which project. Each memory records the session that saved it. It defaults to the MCP connection, so two unnamed clients are still told apart. The header version is X-Brain-Session. |
Everything else is the command's own flags, named as on the CLI. json: true returns the machine-readable envelope instead of the text meant for people. For recall that matters: a miss returns nothing rather than the whole scope, so anything acting on the results has to check matched first.
What only a person can do #
Some calls are refused over MCP whatever you pass, because a person should make them at a terminal. Each refusal names the command for the person to run:
| Refused | Why |
|---|---|
axiom and standard add, edit, rm | Every project reads an axiom as a house rule. |
| release | It is announced in every project's brief. |
| wakeup trust | Approving a probe approves code to run on this machine. |
| wakeup add, rm (over HTTP) | Probes are commands this machine runs. A remote caller does not get to edit them. |
| dm --accept | It releases another person's instruction into this session. |
| relabel --claim, backup --whole-store | Not in the schemas at all: one hands a project's name to a directory, the other writes every project in a shared store. |
| --body - | A body cannot come from stdin over MCP. Pass the text itself. |
wakeup trust is refused over MCP: approving a probe approves code to run on this machine, a person's decision made at a terminal. Ask the person to run `os-brain wakeup trust` themselves
A file the server would read (--body-file, import, absorb, backup --restore) must resolve inside the project over MCP, because the caller may not be on this machine.
What you lose with MCP #
os-brain init wires session hooks. One fires before your first turn and puts the brief in front of the agent. Another matches each prompt against the brain and adds what it finds. Neither waits for the agent to decide to look.
MCP has nothing like that. When a client connects, the server hands it a short set of instructions (read the brain before searching files, write to it before finishing, check matched on a recall) and says where the brain is: which file, which machine and which project. After that the model decides whether to read it. Anything that relies on being remembered will one day be forgotten. So use both where you can: hooks for the brief, MCP for reach.
When it does not work #
| What you see | What it means |
|---|---|
| 404 on every request | The endpoint is /mcp. Nothing is served at the root. |
| 401 | No token or the wrong one. Without --token, read the minted one from the file named on stderr. |
| "this server fronts a shared brain" | No project set. Set OS_BRAIN_PROJECT or the header. |
| Memories under the wrong project | A project was set with the wrong name. os-brain relabel claims rows filed under another label. |
memories=0 from a brain you know has some | Right server, wrong store. brain_stats prints the database path on its second line. A project with its own file is invisible to a server running on the shared store. |
| "missing Mcp-Session-Id" | The client did not send back the session id it got from initialize. |
| 404 "session not found; re-initialize" | The server restarted and lost its sessions. |
| 403 "host not allowed" | A proxy passes a public Host the server does not know. Name it with --allow-host. |
| "this server cannot tell which brain you mean" from Cline | Cline starts every MCP server from one shared process. Set OS_BRAIN_HOME (and OS_BRAIN_PROJECT on a shared store) in the server's env. |
| Refused to start on 0.0.0.0 | No certificate or no token. Pass --tls-cert, --tls-key and --token, or bind loopback behind a proxy that handles TLS. |
| 429 on every request | Too many wrong tokens from this address. Fix the token and wait for the time in Retry-After. |