Skip to main content
Glama
Mailbrain MCP Server

Mailbrain MCP Server

by OSULZER
README.md
# OSULZER Mailbrain

![OSULZER Mailbrain: your mail, ready for AI agents](docs/images/hero.png)

English | [Deutsch](README.de.md)

Mailbrain fetches your mail over IMAP into a local database and makes every mailbox and every
attachment searchable, by keyword and by meaning. Claude Code, Claude Desktop and other AI agents
connect over MCP and can search, read and write drafts, send, move or forward mail, but only as far as
you allow, and every step shows up in an activity log you can undo from.

A free tool by [OSULZER](https://www.osulzer.at) for Windows, macOS and Linux.

## Features

- **Search across all accounts and attachments:** full-text and semantic search (local embedding
  model), text from PDF, Word, Excel, PowerPoint and text files, newest mail first
- **MCP server for agents:** 22 tools to search, list, read mails, threads and attachments, create
  drafts and replies, send, forward with attachments, move, archive, trash, flag and mark as processed
- **Permission levels per account** (read only, drafts, full) and a list of **allowed recipients**:
  agents never send to anyone else
- **Activity log** with the agent's name for every call; moves, archiving, trash and flags can be
  undone for 7 days
- **Writing style:** a formal and an informal style guide per account, built from your sent mail, so
  agents write like you
- **Instructions for agents**, general and per account, which every agent reads at the start
- Several signatures per account, import from Thunderbird and classic Outlook (Windows)
- Several accounts, Gmail preset, start at login (in the tray), automatic updates from GitHub
  (signed), English and German user interface

<img src="docs/images/screenshot-activity.png" width="800" alt="Status of two accounts and the activity log with an agent's calls">

## Install

Download the file for your system from the [latest release](https://github.com/OSULZER/osulzer-mailbrain/releases/latest).
The builds are not code-signed yet.

### Windows

1. Download `…_x64-setup.exe` and start it.
2. Windows SmartScreen may warn that the app is unknown: click **More info** → **Run anyway**.
3. The setup installs Mailbrain for your user, together with the stdio bridge for agents. Mailbrain
   starts at login and keeps running in the tray when you close the window.

### macOS

1. Download `…_aarch64.dmg` (Apple Silicon) or `…_x64.dmg` (Intel), open it and drag Mailbrain to
   **Applications**.
2. The app is not notarized by Apple. On first start macOS blocks it: open **System Settings → Privacy
   & Security** and click **Open Anyway** next to the message about Mailbrain.

### Linux

1. Download `…_amd64.AppImage` (then `chmod +x` it and start it) or `…_amd64.deb`
   (`sudo apt install ./…_amd64.deb`).
2. Passwords and keys are stored in the system keyring, which needs a Secret Service (GNOME Keyring
   or KWallet).

The AppImage updates itself; with the `.deb`, Mailbrain points you to the download page instead.

## First steps

1. **Connect account:** email address, IMAP server and password (Gmail: choose the provider
   **Gmail** and use an app password). IMAP needs TLS on port 993; for sending, SMTP with TLS or
   STARTTLS. The password goes to the operating system's keychain, not into the database.
2. On first start Mailbrain downloads its embedding model once (about 465 MB).
3. Mailbrain fetches and indexes in the background, newest mail first; search already works while it
   runs. For large mailboxes the first run can take hours. New mail is fetched every 2 minutes. The
   number of CPU cores used for semantic search can be set on the home page under **Status**.

More accounts: **Settings → Manage accounts → Add account**.

## Connecting agents

On the home page under **Agents**, enter a name and click **Add agent**. Mailbrain shows the access
key once, together with the ready-to-copy setup. Each agent gets its own key, which you can revoke
there at any time.

<img src="docs/images/screenshot-agents.png" width="800" alt="Agents section with a new key, the Claude Code command and the JSON for other clients">

**Recommended: the stdio bridge** `mailbrain-mcp-stdio`, which is installed with the app. It survives
restarts and starts Mailbrain when it is not running. Claude Code (the app shows the full path):

```sh
claude mcp add mailbrain --env MAILBRAIN_TOKEN=<key> -- "<path to mailbrain-mcp-stdio>"
```

Other clients (Claude Desktop, Cursor …), under **Other clients (stdio)**:

```json
{
  "mcpServers": {
    "mailbrain": {
      "command": "<path to mailbrain-mcp-stdio>",
      "env": { "MAILBRAIN_TOKEN": "<key>" }
    }
  }
}
```

**Alternative over HTTP** (the app must be running):

```sh
claude mcp add --transport http mailbrain http://127.0.0.1:47600/mcp --header "Authorization: Bearer <key>"
```

A good first instruction for the agent: call `get_instructions`, then work through
`list_emails` with `unprocessed_only` and close each mail with `mark_processed`. Before the first
automatic run, use **Mark existing emails as processed** (**Settings**, account page **Processed
flag**) so the agent does not work through your whole inbox.

## Permission levels and allowed recipients

Set per account under **Settings → Permissions & recipients**. New accounts start at level 1; raising
it needs a confirmation. The level is checked on every call.

| Level | Agents may |
|---|---|
| 1 Read only | search and read mails, threads and attachment text, read instructions and style samples, mark mails as processed |
| 2 Create drafts | also create drafts and reply drafts, save attachments to a folder, save style guides |
| 3 Full: send, move, flag, trash | also send, forward, move, archive, move to trash, set read and flagged |

`send_email` and `forward_email` only send when every recipient (To, Cc, Bcc) is on the account's
**Allowed recipients** list: full addresses or whole domains (`@example.com`). Otherwise nothing is
sent; the mail is saved as a draft and the answer names the blocked addresses. Agents cannot change
the list. Nothing is ever deleted for good; trash is a folder move.

## Writing style

Under **Settings → Writing style** (per account) Mailbrain builds two guides from the sent folder,
**Formal** and **Informal (first name)**, which agents receive with `get_instructions`. They are
generated either by a **Language model endpoint** (**Settings → Language model**: any OpenAI-compatible
service, local ones such as LM Studio or Ollama work) or by your **Connected agent**. You can edit them
and regenerate them.

<img src="docs/images/screenshot-writing-style.png" width="800" alt="Writing style settings with a formal guide generated from sent mail">

## Privacy

- Your mail stays on your computer: the database, the search index and the vectors live in the app's
  data folder (`%APPDATA%\at.osulzer.mailbrain` on Windows). Passwords and API keys are in the system
  keyring.
- The embedding model runs locally. Only the model download itself goes to the internet (Hugging
  Face), apart from your mail servers and the update check on GitHub.
- Mail text leaves your computer only in two cases: excerpts of sent mail go to the language-model
  endpoint you configure when you generate a writing style (a local LM Studio or Ollama keeps them on
  your machine; the page warns when the service is not in your network), and an agent you connect
  receives what it reads.
- The MCP server listens on `127.0.0.1` only and refuses every request without a valid access key.

## System requirements

- Windows (x64), macOS (Apple Silicon or Intel), Linux x86_64 with glibc 2.39 or newer (e.g.
  Ubuntu 24.04, Debian 13)
- Disk space: the embedding model 465 MB, plus about 200 MB of database and about 70 MB of vector index
  per 10,000 mails (measured with 107,000 mails and 60,000 attachments: 2.2 GB database, 718 MB
  vectors). Before a database upgrade Mailbrain writes a backup copy of the database next to it;
  older backups can be deleted.
- RAM: typically a few hundred MB while indexing, less when idle.
- IMAP with implicit TLS (port 993); SMTP with TLS or STARTTLS. No IMAP IDLE yet.
- Signature import from Thunderbird and Outlook is Windows only.

## Updates

Mailbrain checks GitHub once a day (**Settings → Updates**, **Check for updates automatically**) and
installs an update only when its signature is valid.

## Building

Requirements: Rust 1.96, Node.js and pnpm 11, the [Tauri prerequisites](https://tauri.app/start/prerequisites/)
for your system, and `protoc` (on Windows: `powershell -File scripts/setup-protoc.ps1`).

```sh
pnpm install
pnpm tauri dev                       # development build
pnpm build && pnpm test              # UI build and tests
cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
```

Integration tests against a GreenMail server need Docker:

```sh
docker compose -f docker-compose.test.yml up -d
cargo test -p mailbrain-core --test greenmail -- --ignored --test-threads=1
docker compose -f docker-compose.test.yml down
```

The installers with the stdio bridge are built by GitHub Actions, see
[.github/workflows/release.yml](.github/workflows/release.yml).

## License

Apache License 2.0 with the **Commons Clause**: you may use (also commercially), modify and share the
software, but you may not sell it or a service whose value derives substantially from it. The name
"OSULZER" and the OSULZER logo are not licensed and may not be used for modified versions. See
[LICENSE](LICENSE) and [NOTICE](NOTICE). Third-party licenses are listed in `THIRD-PARTY-LICENSES.html`
in every release.

---

Made by [OSULZER](https://www.osulzer.at).