mcp-twake-mail
v4.5.1MCP server for Twake.ai Mail: give any MCP-compatible AI assistant secure access to your sovereign JMAP mailbox (Twake Mail, Apache James…)
mcp-twake-mail is a Model Context Protocol (MCP) server. MCP is the open standard that lets AI assistants (Claude Desktop, Claude Code, Hermes Agent, Cursor, VS Code and many others) use external tools. This server exposes your mailbox to the assistant as 33 tools: read, search, write drafts, reply, organise, handle attachments. It speaks JMAP (RFC 8620 / RFC 8621), the modern email standard used by Twake Mail and Apache James, so it also works with any JMAP server (Stalwart, Cyrus IMAP, Fastmail…).
Summary extracted from the README.
mcp-twake-mail
Give your AI assistant secure access to Twake Mail, the email service of the Twake.ai Digital Workplace.

What is it?
mcp-twake-mail is a Model Context Protocol (MCP) server. MCP is the open standard that lets AI assistants (Claude Desktop, Claude Code, Hermes Agent, Cursor, VS Code and many others) use external tools. This server exposes your mailbox to the assistant as 33 tools: read, search, write drafts, reply, organise, handle attachments.
It speaks JMAP (RFC 8620 / RFC 8621), the modern email standard used by Twake Mail and Apache James, so it also works with any JMAP server (Stalwart, Cyrus IMAP, Fastmail…).
Part of Twake.ai
Twake.ai is the truly open source and sovereign Digital Workplace developed by LINAGORA: Twake Mail, Twake Calendar, Twake Drive, Twake Chat, Twake Space and Twake Visio with a single account, hosted in France or on your own infrastructure.
Five open source MCP servers connect AI assistants to the whole workplace:
| MCP server | Twake.ai service | Protocol |
|---|---|---|
| mcp-twake-mail (this project) | Twake Mail | JMAP |
| mcp-twake-dav | Twake Calendar and contacts | CalDAV / CardDAV |
| mcp-twake-drive | Twake Drive | cozy-stack API |
| mcp-twake-chat | Twake Chat | Matrix |
| mcp-twake-space | Twake Space (team spaces) | Twake Space API |
| mcp-twake-project | Twake Project (projects, boards, tasks) | Twake Project API |
Used together, they let one assistant prepare a meeting from the invitation, the related email thread, the chat discussion and the documents in the drive, without your data leaving your servers.
What it brings
- Triage and catch-up: "What are my unread emails from this morning? Summarise the important ones."
- Search across years of mail: "Find the last exchange with the auditors about the 2026 accounts."
- Writing help, you stay in control: the assistant writes a reply as a draft (HTML + plain text, with your signature, correctly threaded); you review it and send it from Twake Mail.
- Organisation: move, label, mark as read, create folders, in batches of up to 50 emails.
- Attachments: list and download attachments so the assistant can read a PDF or a spreadsheet.
- One approval for a series of writes: before several writes (several drafts, several moves), the assistant can ask you once for the exact list with
approve_batch. Each listed call then runs without another question, once, within 15 minutes, in the session that approved it; anything else, or anything changed since, asks as usual; not to be confused with thebatch_*tools, which are one action on several e-mails (see Approving a series of writes at once). - From the command line:
npx mcp-twake-mail call <tool>andnpx mcp-twake-mail toolsrun every tool from a terminal or a script, with the server's configuration. A write you type in a terminal is approved without a question (--iasks first); a write started by an agent is refused, since agents write through their MCP tools, which ask you; without a terminal (cron), a write needs--yes --as <name>, for a name you allowed once in a terminal (see From the command line). - Sovereignty: the server runs next to your assistant and talks directly to your mail server. Pair it with a self-hosted or European AI model to keep the whole chain under your control.
Features
33 MCP tools
| Category | Tools |
|---|---|
| Read | get_email, get_email_labels, search_emails, get_thread, get_thread_emails |
| Drafts | create_draft, reply_draft, update_draft |
| Send ⚠️ | send_email, reply_email, forward_email, send_draft |
| Organise | mark_as_read, mark_as_unread, move_email, add_label, remove_label |
| Batch (up to 50 emails) | batch_mark_read, batch_mark_unread, batch_move, batch_add_label, batch_remove_label, batch_delete ⚠️ |
| Mailboxes | list_mailboxes, get_mailbox, create_mailbox, rename_mailbox, set_mailbox_subscription, delete_mailbox ⚠️ |
| Delete ⚠️ | delete_email |
| Attachments | get_attachments, download_attachment |
| Approval | approve_batch (one approval for a series of writes, see below) |
⚠️ = sends mail on your behalf or deletes data. Every tool carries MCP annotations (readOnlyHint, destructiveHint, idempotentHint).
Every write is approved by you first. Before a tool sends, drafts, marks, moves, labels, deletes or saves anything, the server itself shows you the exact action through MCP elicitation (see Prior approval) and acts only on your explicit OK. Reading e-mails, threads and attachments needs no approval.
Highlights
- Four authentication methods: Basic, Bearer token, OIDC with PKCE (enterprise SSO, automatic token refresh) and token command (short-lived tokens from an external broker).
- Auto-discovery: configure with just your email address (DNS SRV,
.well-known/jmap, OAuth metadata). - Rich drafts:
create_draftbuilds amultipart/alternativemessage (plain text + HTML) frombody(plain text, HTML generated) orhtmlBody(rich formatting), and threads replies withreplyToEmailId(the e-mail answered) orinReplyTo(its Message-ID, whichget_emailreturns asmessageId), filling theIn-Reply-ToandReferencesheaders. - Reply drafts:
reply_draftprepares an answer without sending it:Re:subject, threading headers, recipients of the original (reply-all optional), your signature, then the quoted original ("On …, X wrote:", in French withUSER_LANGUAGE=fr). - Attachments on drafts:
create_draft,reply_draftandupdate_draftattach files taken from the upload folder only (JMAP_UPLOAD_DIR); a path outside it, also through a symbolic link, is refused, and the approval prompt lists each file with its size. - Signatures: a Markdown signature file is converted to HTML and plain text and appended to drafts and sent emails.
- All exchanges with someone:
search_emails participant=<address, name or domain>finds it in From, To, Cc or Bcc, in every mailbox, withpositionto page through the results and the mailbox names of each e-mail. - Hidden folders: a folder you cannot see in Thunderbird may just be unsubscribed:
list_mailboxes role=unsubscribedfinds it,set_mailbox_subscriptionshows it again. - System folder protection: Inbox, Sent, Drafts and Trash cannot be renamed or deleted.
- Large attachments (> 750 KB) are saved to disk instead of being returned inline, in
~/DownloadsorJMAP_DOWNLOAD_DIR.save: truekeeps any attachment on disk, to upload it to Twake Drive for instance. - HTTPS only; logs on stderr, never on the MCP channel.
Requirements
- Node.js >= 20
- A JMAP server: Twake Mail, Apache James, Stalwart, Cyrus IMAP, Fastmail…
- An MCP client: Claude Desktop, Claude Code, Hermes Agent, Cursor, VS Code, or any MCP-compatible assistant
Installation
Quick start with mcp-twake-ai (recommended)
npx mcp-twake-ai setup
mcp-twake-ai sets up this server and the other Twake.ai MCP servers for your Twake.ai account: it asks for your email, signs you in at the Twake.ai identity provider (in the browser, or with a code over SSH), and finds the agents on your computer (Claude Code, Hermes, Claude Desktop, Cursor, VS Code) and the services of your account. It then installs pinned versions of the servers, writes their entries in each agent's configuration and checks that each server starts. For any other agent, mcp-twake-ai export --agent <id> writes the configuration files.
Manual installation
Interactive setup of this server only:
npx mcp-twake-mail setup
The wizard discovers your JMAP server from your email address, asks for the authentication method and credentials, configures the default sender and signature, tests the connection, and can write the Claude Desktop configuration for you.
Global install:
npm install -g mcp-twake-mail
mcp-twake-mail check # verify the configuration
From source:
git clone https://github.com/linagora/mcp-twake-mail.git
cd mcp-twake-mail
npm install
npm run build # then run: node build/index.js
CLI commands
| Command | Description |
|---|---|
mcp-twake-mail |
Start the MCP server (stdio) |
mcp-twake-mail setup |
Interactive configuration wizard |
mcp-twake-mail auth |
Re-run the OIDC authentication flow |
mcp-twake-mail check |
Verify the configuration and test the connection |
Configuration
The server is configured through environment variables, usually set in your MCP client configuration.
Authentication
| Method | Variables |
|---|---|
| Basic (default) | JMAP_SESSION_URL, JMAP_USERNAME, JMAP_PASSWORD |
| Bearer | JMAP_SESSION_URL, JMAP_AUTH_METHOD=bearer, JMAP_TOKEN |
| OIDC (PKCE S256) | JMAP_SESSION_URL, JMAP_AUTH_METHOD=oidc, JMAP_OIDC_ISSUER, JMAP_OIDC_CLIENT_ID, optional JMAP_OIDC_SCOPE (default openid profile email offline_access), JMAP_OIDC_REDIRECT_URI (loopback with a port, default http://localhost:3000/callback) |
| Token command | JMAP_SESSION_URL, JMAP_AUTH_METHOD=command, JMAP_TOKEN_COMMAND |
With token command, the server runs JMAP_TOKEN_COMMAND to get an access token, either raw on stdout or as JSON {"access_token": "...", "expires_at": <epoch seconds>}, and runs it again shortly before expiry. A single broker you control can then own the OIDC grant (and its refresh-token rotation) for several tools, and long-lived secrets stay out of the MCP client configuration.
For Twake.ai, mcp-twake-ai is that broker: JMAP_TOKEN_COMMAND="/usr/local/bin/mcp-twake-ai token mail". Give the command with an absolute path, as some MCP clients do not see your PATH. It runs through the system shell (sh, or cmd.exe on Windows, where paths go in double quotes).
See docs/oidc-configuration.md and docs/auto-discovery.md.
Identity, signature and other options
| Variable | Description | Default |
|---|---|---|
JMAP_DEFAULT_FROM |
Default sender address | account identity |
JMAP_SIGNATURE_PATH |
Markdown signature file (inline HTML allowed) | none |
JMAP_DOWNLOAD_DIR |
Folder where download_attachment saves files (~ is your home folder) |
~/Downloads |
JMAP_UPLOAD_DIR |
The only folder whose files create_draft, reply_draft and update_draft may attach (~ is your home folder) |
Uploads inside the download folder, created when needed |
JMAP_REQUEST_TIMEOUT |
Request timeout (ms) | 30000 |
LOG_LEVEL |
fatal, error, warn, info, debug, trace |
info |
JMAP_APPROVAL |
elicit: the server asks you before every write; client: your MCP client confirms |
elicit |
JMAP_APPROVAL_TIMEOUT_MS |
How long an approval prompt waits for your answer | 600000 |
JMAP_APPROVAL_EXEMPT |
Comma-separated tools you choose to run without a prompt (e.g. create_draft for a scheduled job that prepares drafts) |
none |
USER_LANGUAGE |
Language of the approval prompts, en or fr |
en |
USER_TIMEZONE |
IANA time zone of the dates shown in the prompts | system |
Example signature file:
**Jane Doe**
Head of Operations, Example Corp
[jane.doe@example.com](mailto:jane.doe@example.com)
The signature is read at startup: restart the server after editing it.
Prior approval
With JMAP_APPROVAL=elicit (the default), every write tool sends the MCP client an elicitation request before it acts, for instance:
Twake Mail: Send a reply
As: jane.doe@example.com (your account)
In reply to: Bob DURAND <bob.durand@example.com> · Budget 2027
From: Jane DOE <jane.doe@example.com>
To: Bob DURAND <bob.durand@example.com>
Cc: chloe.petit@example.com
Subject: Re: Budget 2027
Text:
Approved, thanks Bob.
[signature included]
Ref. 3f9a1c · Accept to do it now, refuse to cancel.
- Sending tools show the e-mail as it will leave: sender, the recipients the server computed (reply-all included), subject, text and attachments.
send_draftreads the draft back first. - Other tools list the e-mails they touch (sender, date, subject; at most 10 shown) and the folders by name.
- The server acts only on accept. A refusal, a dismissal, a timeout or an error sends and changes nothing, and the tool tells the assistant not to retry.
- A client without elicitation support gets an error and nothing is done. Set
JMAP_APPROVAL=clientonly if your MCP client asks you to confirm every write tool itself. JMAP_APPROVAL_EXEMPTlets you lift the prompt for chosen tools only (empty by default).
Use it with your assistant
Claude Desktop
Edit claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/, Linux: ~/.config/Claude/, Windows: %APPDATA%\Claude\), then restart Claude Desktop:
{
"mcpServers": {
"twake-mail": {
"command": "npx",
"args": ["-y", "mcp-twake-mail"],
"env": {
"JMAP_SESSION_URL": "https://jmap.example.com/jmap/session",
"JMAP_AUTH_METHOD": "oidc",
"JMAP_OIDC_ISSUER": "https://sso.example.com",
"JMAP_OIDC_CLIENT_ID": "my-client-id",
"JMAP_DEFAULT_FROM": "jane.doe@example.com",
"JMAP_SIGNATURE_PATH": "~/.mcp-twake-mail/signature.md"
}
}
}
}
Claude Code
claude mcp add twake-mail --scope user \
-e JMAP_SESSION_URL=https://jmap.example.com/jmap/session \
-e JMAP_AUTH_METHOD=oidc \
-e JMAP_OIDC_ISSUER=https://sso.example.com \
-e JMAP_OIDC_CLIENT_ID=my-client-id \
-- npx -y mcp-twake-mail
Hermes Agent
mcp_servers:
twake_mail:
command: npx
args: ["-y", "mcp-twake-mail"]
env:
JMAP_SESSION_URL: https://jmap.example.com/jmap/session
JMAP_AUTH_METHOD: command
JMAP_TOKEN_COMMAND: /usr/local/bin/mcp-twake-ai token mail
JMAP_SIGNATURE_PATH: ~/.mcp-twake-mail/signature.md
JMAP_APPROVAL_TIMEOUT_MS: "330000"
USER_LANGUAGE: fr
timeout: 420 # longer than the approval wait
elicitation:
enabled: true
timeout: 300
Hermes shows the approval prompts in the desktop app, the terminal or on your messaging platform, and declines them where nobody can answer (cron jobs, one-shot queries).
Other MCP clients
Any client that can launch a stdio MCP server works: command npx, arguments -y mcp-twake-mail, and the environment variables above.
From the command line
Every tool of this server can be called from a terminal or a script, with the same configuration (JMAP_* variables) as the server:
npx mcp-twake-mail tools # one line per tool
npx mcp-twake-mail call search_emails --arg participant=bob@example.com --arg limit=5
npx mcp-twake-mail call create_draft --json @draft.json
--arg key=valueis converted to the type the tool giveskey;--jsontakes the whole arguments object (@file, or-for stdin). The result goes to stdout (--json-outputfor the raw result), everything else to stderr.- Exit codes: 0 done, 1 the tool answered with an error, 2 wrong command or argument, 3 a write was not approved, 4 the server could not be reached.
- Writes: typed by you in a terminal, a write is approved without a question (
--iasks first). Started by an agent (CLAUDECODEorHERMES_HOMEset), a write is refused: agents write through their MCP tools, which ask you. Without a terminal (cron), a write is refused unless it passes--yes --as <name>for a name you allowed once, in a terminal, withnpx mcp-twake-mail allow-unattended <name>. The allowed names are shared by the six Twake.ai servers, in~/.config/twake-ai/cli.json(%USERPROFILE%\AppData\Roaming\twake-ai\cli.jsonon Windows). - These rules stop an agent that follows instructions; they cannot stop a program that hides that it is an agent, or rewrites
cli.json, under your account. - With mcp-twake-ai,
npx mcp-twake-ai call mail …does the same with your Twake.ai sign-in.
Approving a series of writes at once
Before a series of writes (several drafts, several moves), an agent can ask you once for the whole list with approve_batch: you see every action, numbered, in one approval. Each call that then carries the batchId and matches a listed action exactly runs without another question, once, within 15 minutes. A call that is not in the list, or whose target changed since you approved, asks as usual. A batch approves exactly what each action's approval text shows; it belongs to the session that approved it, and is forgotten when that session ends. With JMAP_APPROVAL=client, there is no batch; a tool in JMAP_APPROVAL_EXEMPT is listed as asking nothing. Not to be confused with the batch_* tools, which are one action on several e-mails.
Recommended safe configuration
Keep JMAP_APPROVAL=elicit (the default): every e-mail sent in your name, and every other write, waits for your OK on the exact content. If you prefer that the assistant never sends at all (drafts only: you send from Twake Mail), filter out the sending and deleting tools in your MCP client, for example with Hermes Agent:
tools:
exclude: [send_email, reply_email, forward_email, send_draft,
delete_email, batch_delete, create_mailbox, rename_mailbox, delete_mailbox]
Email content is written by third parties: a message can contain instructions aimed at your assistant (prompt injection). Keep a human in the loop for every write action. See SECURITY.md.
Usage examples
- "What are my unread emails? Which ones need an answer today?"
- "Show me the whole thread about the budget meeting."
- "Prepare a draft reply to Pierre thanking him and proposing Tuesday at 10."
- "Move all newsletters from last week to the Archive folder."
- "Download the PDF attached to the last email from the accountant."
- "Create a folder called Projects / 2027."
Architecture
MCP client ⇄ stdio (JSON-RPC) ⇄ mcp-twake-mail ⇄ HTTPS (JMAP) ⇄ Twake Mail / any JMAP server
Layers: Zod configuration with fail-fast validation, Pino logger on stderr, authentication (Basic, Bearer, OIDC with PKCE and refresh, token command), auto-discovery, JMAP client (session, batching, blob download), signature conversion, AI-friendly transformers, and the MCP tools.
Development
npm install
npm run build # compile TypeScript
npm test # 700+ tests (Vitest), no real server needed
npm run dev # watch mode
npm run lint
Contributing
Contributions are welcome: read CONTRIBUTING.md and our Code of Conduct. Please report vulnerabilities privately as described in SECURITY.md. Release notes are in CHANGELOG.md.
License
Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
Copyright © 2026 LINAGORA
About
mcp-twake-mail is developed by LINAGORA, French open source software publisher, as part of Twake.ai. For support, hosting or integration of Twake.ai and its AI connectors, contact LINAGORA at https://linagora.com.