OxMail MCP
by tungmv
README.md
# OxMail MCP
An [MCP](https://modelcontextprotocol.io) server that lets an AI agent read and
send mail through an [OxMail](https://github.com/MYusufEka/oxmail) instance over
its JMAP endpoint.
No browser automation, no IMAP/SMTP passwords in the repo: the server speaks
JMAP (`POST /jmap`) with a Bearer token.
## Tools
| Tool | Arguments | What it does |
|---|---|---|
| `oxmail_status` | — | Signed-in identity and mailbox list |
| `oxmail_list` | `folder` (default `INBOX`), `limit` (1–50, default 15) | Recent messages with subject, sender, date, preview |
| `oxmail_read` | `id` | One message with its plain-text body |
| `oxmail_send` | `to`, `subject`, `body`, `cc?`, `bcc?`, `attachments?`, `confirm?` | Send mail. **Dry-run unless `confirm: true`** |
`oxmail_send` never delivers by accident: without `confirm: true` it validates the
payload and returns a preview.
## Install
```bash
git clone https://github.com/tungmv/oxmail-mcp.git
cd oxmail-mcp
node server.mjs # smoke test: prints "ready" on stderr
```
No dependencies; Node 20+.
## Configure
Add to your MCP client (for pi, `~/.pi/agent/mcp.json`; for Claude Code,
`claude mcp add`):
```json
{
"mcpServers": {
"oxmail": {
"type": "stdio",
"command": "node",
"args": ["/abs/path/to/oxmail-mcp/server.mjs"],
"env": {
"OXMAL_BASE": "https://mail.example.com",
"OXMAL_TOKEN": "eyJ..."
}
}
}
}
```
### Token resolution
The server looks for a Bearer token in this order:
1. `OXMAL_TOKEN`
2. `~/.config/oxmail/token` (a file containing just the token, mode 600)
3. A token captured from a logged-in OxMail tab via a local WebDriver BiDi
daemon on `127.0.0.1:9444` (`OXMAL_BIDI_PORT` to change)
Option 3 exists because OxMail's web UI keeps its OIDC token in `sessionStorage`
while using a fresher access token held in a module variable — so the storage
copy is often expired. To capture a live one, wrap `fetch` in the tab and open
any folder:
```js
window.__cap = [];
const of = window.fetch;
window.fetch = function (...a) {
try {
const h = (a[1] && a[1].headers) || {};
const au = h.Authorization || (h.get && h.get("Authorization")) || "";
if (au) window.__cap.push(String(au));
} catch (e) {}
return of.apply(this, a);
};
```
### Environment
| Variable | Default | Meaning |
|---|---|---|
| `OXMAL_BASE` | `http://localhost:8080` | OxMail base URL |
| `OXMAL_TOKEN` | — | Bearer token |
| `OXMAL_BIDI_PORT` | `9444` | BiDi daemon port for token capture |
## Verified
- `oxmail_status` → identity and mailboxes
- `oxmail_list` INBOX/Sent → real messages with previews
- `oxmail_read` → subject, from/to, body; Unicode round-trips
- `oxmail_send` → returns `emailId` + `submissionId`, message appears in Sent
- `oxmail_send` with `attachments` → file present server-side with the right
name, size and `disposition: attachment`
## Attachments
`attachments` takes absolute file paths. Each file is uploaded with
`POST /jmap/upload/{accountId}` and referenced from the create payload as
`attachments: [{ blobId, name, type, size }]`.
Note the shape: this OxMail build ignores `bodyStructure` and silently drops
parts sent that way. The working payload (matching the web UI) is:
```js
{
textBody: [{ partId: "1", type: "text/plain" }],
bodyValues: { 1: { value: body } },
attachments: [{ blobId, name, type, size }],
}
```
## Security
- The token is read from the environment or a 600-mode file and is never logged.
- `oxmail_send` defaults to a dry run; delivering requires an explicit
`confirm: true`.
- Point `OXMAL_BASE` at a host you control.
## License
MIT