MCP Twake Mail README

The full upstream README, mirrored for reference. Install config, tool schemas, adoption signals and our own overview live on the MCP Twake Mail listing page.

mcp-twake-mail

npm version CI License: AGPL-3.0 Node.js >= 20

Give your AI assistant secure access to Twake Mail, the email service of the Twake.ai Digital Workplace.

Twake Mail

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 serverTwake.ai serviceProtocol
mcp-twake-mail (this project)Twake MailJMAP
mcp-twake-davTwake Calendar and contactsCalDAV / CardDAV
mcp-twake-driveTwake Drivecozy-stack API
mcp-twake-chatTwake ChatMatrix
mcp-twake-spaceTwake Space (team spaces)Twake Space API
mcp-twake-projectTwake 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 the batch_* 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> and npx mcp-twake-mail tools run 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 (--i asks 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

CategoryTools
Readget_email, get_email_labels, search_emails, get_thread, get_thread_emails
Draftscreate_draft, reply_draft, update_draft
Send ⚠️send_email, reply_email, forward_email, send_draft
Organisemark_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 ⚠️
Mailboxeslist_mailboxes, get_mailbox, create_mailbox, rename_mailbox, set_mailbox_subscription, delete_mailbox ⚠️
Delete ⚠️delete_email
Attachmentsget_attachments, download_attachment
Approvalapprove_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_draft builds a multipart/alternative message (plain text + HTML) from body (plain text, HTML generated) or htmlBody (rich formatting), and threads replies with replyToEmailId (the e-mail answered) or inReplyTo (its Message-ID, which get_email returns as messageId), filling the In-Reply-To and References headers.
  • Reply drafts: reply_draft prepares 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 with USER_LANGUAGE=fr).
  • Attachments on drafts: create_draft, reply_draft and update_draft attach 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, with position to 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=unsubscribed finds it, set_mailbox_subscription shows 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 ~/Downloads or JMAP_DOWNLOAD_DIR. save: true keeps 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)

Terminal
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:

Terminal
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:

Terminal
npm install -g mcp-twake-mail
mcp-twake-mail check   # verify the configuration

From source:

bash
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

CommandDescription
mcp-twake-mailStart the MCP server (stdio)
mcp-twake-mail setupInteractive configuration wizard
mcp-twake-mail authRe-run the OIDC authentication flow
mcp-twake-mail checkVerify the configuration and test the connection

Configuration

The server is configured through environment variables, usually set in your MCP client configuration.

Authentication

MethodVariables
Basic (default)JMAP_SESSION_URL, JMAP_USERNAME, JMAP_PASSWORD
BearerJMAP_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 commandJMAP_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

VariableDescriptionDefault
JMAP_DEFAULT_FROMDefault sender addressaccount identity
JMAP_SIGNATURE_PATHMarkdown signature file (inline HTML allowed)none
JMAP_DOWNLOAD_DIRFolder where download_attachment saves files (~ is your home folder)~/Downloads
JMAP_UPLOAD_DIRThe 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_TIMEOUTRequest timeout (ms)30000
LOG_LEVELfatal, error, warn, info, debug, traceinfo
JMAP_APPROVALelicit: the server asks you before every write; client: your MCP client confirmselicit
JMAP_APPROVAL_TIMEOUT_MSHow long an approval prompt waits for your answer600000
JMAP_APPROVAL_EXEMPTComma-separated tools you choose to run without a prompt (e.g. create_draft for a scheduled job that prepares drafts)none
USER_LANGUAGELanguage of the approval prompts, en or fren
USER_TIMEZONEIANA time zone of the dates shown in the promptssystem

Example signature file:

markdown
**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:

Code
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_draft reads 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=client only if your MCP client asks you to confirm every write tool itself.
  • JMAP_APPROVAL_EXEMPT lets you lift the prompt for chosen tools only (empty by default).

Using several accounts

The server serves one account: it fetches the JMAP session at JMAP_SESSION_URL and keeps the primary mail account of that session (primaryAccounts["urn:ietf:params:jmap:mail"]). The tools take no account: list_mailboxes, search_emails, send_email, the labels and the drafts all act on that account. The from parameter of the sending tools only chooses an identity that account may send as, not another mailbox.

To use two accounts, run two servers, each with its own name and environment, and let your MCP client start both:

config.json
{
  "mcpServers": {
    "twake-mail-work": {
      "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_DEFAULT_FROM": "jane.doe@example.com",
        "JMAP_SIGNATURE_PATH": "~/.mcp-twake-mail/work.md"
      }
    },
    "twake-mail-personal": {
      "command": "npx",
      "args": ["-y", "mcp-twake-mail"],
      "env": {
        "JMAP_SESSION_URL": "https://jmap.example.org/jmap/session",
        "JMAP_AUTH_METHOD": "oidc",
        "JMAP_OIDC_ISSUER": "https://sso.example.org",
        "JMAP_OIDC_CLIENT_ID": "my-personal-client",
        "JMAP_DEFAULT_FROM": "jane.doe@example.org",
        "JMAP_SIGNATURE_PATH": "~/.mcp-twake-mail/personal.md"
      }
    }
  }
}

The two accounts may live on different servers (different JMAP_SESSION_URL, issuer and client id) or on the same one: each instance still opens its own session with its own credentials. Everything else is per instance too: the signature file, JMAP_DOWNLOAD_DIR, JMAP_APPROVAL and JMAP_APPROVAL_EXEMPT. Most agents show the tools of each server under its name, so a request should name the mailbox it means ("my work inbox"), and each write is approved by the instance that would do it: its prompt names the account it acts as (As: …).

With mcp-twake-ai, a sign-in holds one account, and signing in with another address replaces it (its Twake Drive, Chat and setup --env settings are left behind). Keep one TWAKE_AI_HOME per account, each with its own login:

bash
TWAKE_AI_HOME=~/.twake-work     mcp-twake-ai login --email jane.doe@example.com
TWAKE_AI_HOME=~/.twake-personal mcp-twake-ai login --email jane.doe@example.org

Then set TWAKE_AI_HOME in each server entry, next to its JMAP_SESSION_URL and JMAP_TOKEN_COMMAND="/usr/local/bin/mcp-twake-ai token mail", so that the token command reads the session of the right account. mcp-twake-ai setup and export write such entries themselves.

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:

config.json
{
  "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

Terminal
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

yaml
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:

Terminal
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=value is converted to the type the tool gives key; --json takes the whole arguments object (@file, or - for stdin). The result goes to stdout (--json-output for 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 (--i asks first). Started by an agent (CLAUDECODE or HERMES_HOME set), 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, with npx 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.json on 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:

yaml
    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

Code
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

Terminal
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.