plmail-mcp
by jo2904
README.md
# plmail-mcp
An MCP server that gives an agent (Hermes, Claude, any MCP client) the mail,
calendar and contacts of a [plMail](https://github.com/karatektus/pl_mail)
server — every mailbox plMail syncs (IMAP, Gmail, Outlook) through **one URL
and one app password**. No per-mailbox IMAP/SMTP settings: plMail already
holds those, this talks to its JMAP API.
## Setup
1. In plMail: **Settings → App passwords → create** (e.g. "Hermes"). The
secret starts with `plmail_` and is shown once.
2. Write `~/.config/plmail-mcp/config.toml`, mode 600
(see `contrib/config.example.toml`):
```toml
url = "https://mail.example.org"
token = "plmail_…"
```
Environment variables override the file: `PLMAIL_URL`, `PLMAIL_TOKEN` or
`PLMAIL_TOKEN_FILE`, `PLMAIL_VERIFY_TLS`, and `PLMAIL_MCP_CONFIG` for
another file path. A config file or token file readable by anyone but
its owner is refused.
3. Check what the agent will see:
```sh
uv run plmail-mcp check
```
Revoking the app password in plMail cuts the agent off everywhere at once.
### Switching tools off
Every tool is on by default. To take one away from the agent, set it to
`false` in a `[tools]` table; it then disappears from the tool list the agent
sees:
```toml
[tools]
send_email = false
send_draft = false
jmap = false
```
A name that matches no tool is refused at start-up, so `sned_email = false`
cannot leave sending on by mistake. Switch `jmap` off whenever another tool
is off: the raw JMAP tool can do anything the others do, and the server warns
when it is left on. These switches are enforced by this server, not by
plMail: the app password itself can still do everything, so keep it where the
agent cannot read it (see Running).
## Running
```sh
uv run plmail-mcp serve # stdio
uv run plmail-mcp serve --transport streamable-http \
--host 127.0.0.1 --port 9558 # http://127.0.0.1:9558/mcp
```
For an agent that runs sandboxed (Hermes' gateway), run the HTTP server
outside the sandbox as a user service, so the app password never enters it:
`contrib/plmail-mcp.service`. Then, in `~/.hermes/config.yaml`:
```yaml
mcp_servers:
plmail:
url: http://127.0.0.1:9558/mcp
```
For a client that spawns servers itself (stdio):
```yaml
mcp_servers:
plmail:
command: uv
args: ["run", "--directory", "/path/to/plmail-mcp", "plmail-mcp", "serve"]
```
## Tools
| | |
|---|---|
| Accounts | `list_accounts`, `list_mailboxes`, `list_identities` |
| Reading | `search_emails` (all accounts at once unless one is named), `read_email`, `read_thread` |
| Organising | `update_emails` (read/unread, star, add/remove folder or label), `move_thread`, `snooze_thread`, `trash_emails` |
| Writing | `create_draft` (replies fill in recipients, subject, threading, sending address), `send_draft`, `send_email`, `cancel_send` (for sends held with `delay_seconds`) |
| Contacts | `find_contacts`, `suggest_recipients`, `save_contact`, `delete_contact` |
| Calendar | `list_calendars`, `list_events` (recurrences expanded), `save_event`, `delete_event` |
| Templates | `list_templates`, `render_template` |
| Anything else | `jmap`: a raw JMAP request, for every other plMail method |
Accounts are named by id or address (`"3"`, `"me@gmail.com"`, or a unique
part of it). Every result carries the `account` it came from.
The agent can send mail unless `send_email` and `send_draft` are switched
off. With them on, the tool descriptions tell it to send only when asked, and
`create_draft` + `send_draft` leave a step for review.
## Behaviour worth knowing
- Trash is a move: plMail never hard-deletes.
- Waking a snoozed conversation puts it back in the inbox **unread** (plMail's
own snooze semantics).
- plMail's Session advertises `urn:plmail:params:jmap:push`, which its API
then refuses in `using`. The client drops any capability the API refuses
and retries.
- Calendars and contacts belong to the plMail user, served from the session's
primary account; mail is per account.
## Testing
`tests/smoke.py` starts the server over stdio and calls every tool against a
**throwaway** plMail (it creates and deletes drafts, contacts and events):
```sh
PLMAIL_URL=http://127.0.0.1:8001 PLMAIL_TOKEN_FILE=/path/to/token uv run python tests/smoke.py
```
A local plMail test stack: `compose.test.yaml` in the plMail repo, then
`bin/console app:test:seed-user --email=demo@plmail.test --password=…`,
`app:test:seed-demo --email=demo@plmail.test` and
`app:test:seed-api-token --email=demo@plmail.test -q` for the token.