Docs / Connect / OpenCode

Connect ModelBrain to OpenCode

OpenCode keeps MCP servers under an mcp key in its opencode.json, so connecting ModelBrain means adding one entry to that file.

OpenCode merges its config files instead of replacing them, so a project file can quietly override a global one. Put ModelBrain in the global file so it follows you everywhere, and remember that the same name in a project file wins.

Where the program lives

This client needs the full path to ModelBrain's mcp_server program. The commands and snippets on this page show the macOS path; on Windows or Linux, put the path for your system in the same place. Write the full path rather than a variable such as %LOCALAPPDATA% or ~, because a client may not expand it.

macOS

/Applications/ModelBrain.app/Contents/MacOS/mcp_server

Windows

C:\Users\you\AppData\Local\Programs\ModelBrain\mcp_server.exe (that is %LOCALAPPDATA%\Programs\ModelBrain\mcp_server.exe, with your own user name). Inside JSON, TOML or a quoted YAML string, double each backslash.

Linux

/home/you/.local/lib/modelbrain/mcp_server, with your own home folder. The install script puts ModelBrain in ~/.local/lib/modelbrain.

Steps
  1. Install ModelBrain if you haven't yet (macOS, Windows or Linux).
  2. Open your global OpenCode config, ~/.config/opencode/opencode.json. Create it if it does not exist. If the file already has content, keep it and add to it.
  3. Add ModelBrain under the mcp key. Unlike most clients, OpenCode wants command as a list, and a type of local. If you already have an mcp object, add only the modelbrain entry inside it, with a comma after the entry before it.
    {
      "mcp": {
        "modelbrain": {
          "type": "local",
          "command": ["/Applications/ModelBrain.app/Contents/MacOS/mcp_server"],
          "enabled": true
        }
      }
    }
  4. Start a new OpenCode session. ModelBrain's tools appear with the server name in front of them, such as modelbrain_recall.
  5. Check it is connected. Ask OpenCode to remember something, then recall it in a new session.
Questions

Does OpenCode ask before using ModelBrain's tools?

Its MCP page describes no approval prompt: once a server is added, its tools are available to the model alongside the built-in ones. If you want to switch ModelBrain's tools off for one agent, OpenCode lets you disable tools by name, with the server name as a prefix.

What if I also have an opencode.json in a project?

OpenCode merges the global and project files. A modelbrain entry in the project file overrides the global one, so if ModelBrain behaves differently in one project, look there first.

My file is opencode.jsonc. Does that matter?

No. OpenCode reads either name, and the .jsonc one allows comments. Put the same entry in whichever file you already use.

How do I undo it?

Remove the modelbrain entry, or set enabled to false to keep it without using it. Your memories are not stored in that file.

Has this been tested?

We have tested this configuration against sample files and the ModelBrain setup code, but not yet by hand on a real install of OpenCode. If ModelBrain does not appear in OpenCode after you follow these steps, tell us through the Support page and we will fix this guide.

Not installed yet?

Start with the install guide.

Install ModelBrain →
Then

A 10-minute walkthrough: add a folder, ask something that needs two notes, see the citation.

Quickstart →