mail-mcp logo

mail-mcp

Community
kacperkwapisz

MCP server bridging IMAP/SMTP email accounts to Poke — search, read, send, and watch emails via AI agents

Publisherkacperkwapisz
Repositorymail-mcp
LanguageGo
Forks
4
Stars
13
Available tools
0
Transport typestdio, streamable-http
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    mail-mcp exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    13 stars and 4 forks from the linked repository.

mail-mcp

An MCP server that gives AI agents controlled access to IMAP and SMTP mailboxes — read, search, organize, and send — without ever handing them your credentials.

Written in Go. Single static binary, no runtime dependencies, ~20 MB resident.

Why credentials stay server-side

The agent never sees a hostname, username, or password. Tools take an opaque account_id; the server resolves it against a local config file and makes the connection itself. Run it remotely and the model has no way to reconstruct how to reach your mailbox, even if it wanted to.

The same idea extends to message handles. A message_id is an opaque token encoding the account, folder, UIDVALIDITY, and UID together — so an agent cannot pair a handle from one mailbox with a different account, and a folder that gets renumbered produces a clear "this handle is stale" error instead of quietly acting on the wrong message.

Install

Docker

bash
docker run -d --name mail-mcp \
  -p 3000:3000 \
  -v "$PWD/config.yml:/config.yml:ro" \
  -e MCP_API_KEY="$(openssl rand -hex 32)" \
  ghcr.io/kacperkwapisz/mail-mcp:latest

From source

bash
git clone https://github.com/kacperkwapisz/mail-mcp.git
cd mail-mcp
make build          # → bin/mail-mcp

Binaries

Download for your platform from Releases.

Setup

1. Write the config.

bash
cp config.example.yml config.yml
yaml
allow_send: false # opt in per account below
allow_delete: false

accounts:
  - id: icloud
    imap:
      host: imap.mail.me.com
      username: you@icloud.com
      password: xxxx-xxxx-xxxx-xxxx # app-specific password
    smtp:
      host: smtp.mail.me.com
      username: you@icloud.com
      password: xxxx-xxxx-xxxx-xxxx
    from_address: you@yourdomain.com
    from_name: Your Name
    allow_send: true

Most providers need an app-specific password rather than your account password — iCloud, Gmail, Fastmail, and Zoho all work this way.

SMTP inherits the IMAP host and credentials when omitted, and connection security is inferred from the port (993 → TLS, 143 → STARTTLS, 465 → TLS, 587 → STARTTLS) unless you set security explicitly.

2. Generate a token and run.

bash
export MCP_API_KEY=$(openssl rand -hex 32)
./bin/mail-mcp --config config.yml

The HTTP transport refuses to start without MCP_API_KEY. There is no unauthenticated mode — this process can read and send your mail.

3. Verify.

bash
npx @modelcontextprotocol/inspector

Connect to http://localhost:3000/mcp over Streamable HTTP with an Authorization: Bearer <MCP_API_KEY> header, then call verify_account to confirm both IMAP and SMTP authenticate.

Local use

For a client on the same machine, stdio skips the network entirely and needs no token:

jsonc
{
  "mcpServers": {
    "mail": {
      "command": "/usr/local/bin/mail-mcp",
      "args": ["--config", "/etc/mail-mcp/config.yml", "--transport", "stdio"]
    }
  }
}

Tools

Discovery

ToolPurpose
list_accountsEvery configured mailbox and what it's allowed to do. No network.
verify_accountLive IMAP + SMTP connectivity and auth check.
get_server_infoVersion and the operational limits governing the other tools.

Reading

ToolPurpose
search_emailsSearch by sender, recipient, subject, body, date, or flags. Paginated.
read_emailOne message: headers, body, attachment metadata. HTML opt-in.
get_attachmentWrite one attachment to disk. Returns file_path and, on HTTP, a 15-minute download_url.

Sending

ToolPurpose
send_emailNew message, with attachments and full threading control.
reply_emailReply with derived subject, recipients, and threading headers.
forward_emailForward, carrying attachments and quoting the original.
create_draftSave to Drafts without sending. Works even when sending is off.

Organizing

ToolPurpose
archive_emailMove to the account's Archive folder.
move_emailMove to any folder.
mark_emailread / unread / flagged / unflagged / answered / unanswered.
delete_emailMove to Trash. Gated, and requires confirm: true.
list_foldersFolders with their normalized roles.
create_folder · rename_folder · delete_folderFolder management.

Design decisions

Attachment bytes never enter the response. read_email returns attachment metadata with a part_id; get_attachment writes the file to disk and returns file_path (on the server) plus, when public_url is set, a 15-minute signed download_url. A remote agent curls that URL onto its own machine. A 7 MB PDF base64-encoded into a tool result would blow the context window without accomplishing anything.

Bodies are truncated and HTML is opt-in. Message HTML is attacker-controlled and enormous. It is sanitized through bluemonday before it is ever returned, and omitted entirely unless include_html is set. Messages with no plain-text part get one derived from the HTML, with paragraph breaks preserved.

One pooled IMAP connection per account. A TLS handshake plus LOGIN on every tool call is the single biggest source of latency in servers of this kind. Connections are kept authenticated, health-checked with NOOP after idling, and reconnected transparently. Operations on one account are serialized, since IMAP's selected-mailbox state makes ordering matter; different accounts run concurrently.

Every network operation is bounded. Separate timeouts for IMAP connect, IMAP command, SMTP connect, and SMTP send — the last one generous, because DATA transmission for a large attachment on a slow uplink legitimately takes minutes. A command that exceeds its budget closes the socket, which is the only thing that reliably unblocks a stuck IMAP read.

Sent copies are the exact bytes that were delivered. Rather than rebuilding an approximation for the Sent folder, the serialized message is captured before transmission and APPENDed verbatim. Whether to append at all is provider-aware: Gmail and Zoho file their own copy on submission, so a second one is redundant or a visible duplicate; iCloud, Office 365, and generic relays file nothing, so skipping it loses the copy.

Send validation happens before a socket opens. Recipients, subject length, header injection via embedded newlines, and body presence are all checked locally. A malformed call fails instantly with a specific message instead of after a TLS handshake.

Tool-call syntax in a body is rejected outright. LLMs periodically concatenate body_text and body_html into one argument and leak the separator markup into the recipient's inbox. Prompt instructions do not reliably prevent this, so the server refuses any send whose fields contain </body_text>, <parameter name="body_html">, and similar markers. Legitimate technical content that merely mentions <parameter> still passes.

Folder roles come from the server, not a name list. SPECIAL-USE attributes are used where available, with a localized name table as fallback — so a Polish "Wysłane" or a Gmail "[Gmail]/Sent Mail" is recognized as Sent rather than triggering the creation of a duplicate folder.

Destructive operations are gated twice. allow_delete is false by default, and even when enabled delete_email requires confirm: true per call and moves to Trash rather than expunging. delete_folder additionally refuses INBOX and any special-use folder.

Configuration reference

Environment

VariableDefaultPurpose
MCP_API_KEY—Bearer token. Required for HTTP; unused for stdio.
CONFIG_PATHconfig.ymlPath to the YAML config.
TRANSPORThttphttp or stdio.
PORT / ADDR3000Listen port or full address.
LOG_LEVELinfodebug, info, warn, error.
TRUST_PROXYfalseTrust X-Forwarded-For for rate limiting.
RATE_LIMIT_GET_RPM60Per-client GET budget per minute.
RATE_LIMIT_POST_RPM240Per-client POST budget per minute.

Flags mirror these: --config, --transport, --addr, --log-level, --trust-proxy, --version.

Config file

See config.example.yml for the annotated version.

KeyDefaultPurpose
allow_sendfalseGlobal send gate.
allow_deletefalseGlobal delete gate.
limits.max_body_chars50000Per-part body truncation.
limits.max_search_results100Largest search page.
limits.max_attachment_bytes26214400Attachment size ceiling.
limits.attachment_dirsystem tempWhere get_attachment writes.
public_urlemptyOrigin used to mint download_url. Empty disables it.
timeouts.*see exampleimap_connect, imap_command, smtp_connect, smtp_send.
accounts[].allow_sendinherits globalPer-account send gate.
accounts[].allow_deleteinherits globalPer-account delete gate.
accounts[].save_sentprovider-awareForce the Sent-folder copy on or off.

Configs written for poke-mail v1 still load: the flat imap_host / smtp_username style keys are folded into the nested form automatically.

Security

  • Authentication is mandatory on HTTP. No token, no start.
  • Credentials never leave the server. Tools receive ids, not connection details.
  • Everything outside /mcp returns an empty 404, revealing nothing to scanners.
  • TLS is mandatory for STARTTLS accounts. No opportunistic fallback to plaintext, which would send your password in the clear.
  • Rate limited per client, with separate GET and POST budgets so polling cannot starve real work. X-Forwarded-For is ignored unless you declare a trusted proxy, since otherwise any caller could spoof it.
  • Attachment filenames are sanitized before touching the filesystem — path separators, traversal segments, and control characters are stripped.
  • HTML is sanitized with bluemonday before it is returned.
  • DNS rebinding protection is on by default via the MCP SDK.

Put it behind TLS in any real deployment — a reverse proxy or a tunnel. The bearer token is the only thing standing between the internet and your mail.

Development

bash
make check    # fmt + vet + test
make test
make race
make cover
make build
make docker

License

MIT — see LICENSE.

Installation

TypingMind
{
  "mcpServers": {
    "kacperkwapisz-mail-mcp": {
      "command": "./bin/mail-mcp",
      "args": [
        "--config",
        "path/to/your/config.yml",
        "--transport",
        "stdio"
      ]
    }
  }
}

Use mail-mcp MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once mail-mcp is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. You can run MCP locally on your device or connect to a remote MCP server URL.

Option 1: Use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add mail-mcp as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the mail-mcp MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "kacperkwapisz-mail-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the mail-mcp MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the mail-mcp MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use mail-mcp to help me with this task?
mail-mcp
Sure. I read it.
Here is what I found using mail-mcp.

Option 2: Add an MCP server URL

Use this when mail-mcp is already hosted remotely or your team wants one shared connector that multiple users can access.

1

Open MCP connectors

In TypingMind, go to Plugins, open MCP connectors, then choose Add URL.

  1. Open TypingMind in your browser.
  2. Go to Plugins.
  3. Open MCP connectors.
  4. Click Add URL.
TypingMind Add Custom MCP Server URL form
2

Paste the server URL

Enter the MCP server URL from the provider in the Server URL field. Add a connection name, description, icon, custom HTTP headers, or OAuth client settings if the server requires them.

  1. Paste the MCP server URL from the provider into the Server URL field.
  2. Enter a connection name for mail-mcp.
  3. Add a description and icon if you want it to be easier to identify.
  4. Add custom HTTP headers or OAuth client details if the server requires authentication.
3

Create the connection

Click Create connection, then return to the Plugins list and confirm the new MCP connection is active.

  1. Click Create connection.
  2. Return to the MCP connectors list.
  3. Confirm the mail-mcp connection appears as active.
  4. Refresh the plugin list if the connection does not appear immediately.
4

Switch models without reconnecting

Start a chat with your preferred model, enable the mail-mcp tools from Plugins, and switch to another model whenever needed. The MCP connection stays available to the TypingMind workspace.

  1. Start a new chat in TypingMind.
  2. Select the AI model you want to use.
  3. Enable the mail-mcp tools from Plugins.
  4. Ask the model to use the tool when needed.
  5. Switch to another AI model and reuse the same MCP connection.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use mail-mcp to help me with this task?
mail-mcp
Sure. I read it.
Here is what I found using mail-mcp.

Frequently asked questions

What is the mail-mcp MCP server used for?

mail-mcp is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use mail-mcp MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use mail-mcp with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use mail-mcp MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With mail-mcp connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect mail-mcp MCP to TypingMind?

mail-mcp can be connected in TypingMind with the local MCP connector or by adding a remote MCP server URL. Use the local connector when the server needs access to files, apps, or private resources on your device, and use a server URL when the MCP server is hosted remotely.

What tools does mail-mcp MCP provide in TypingMind?

mail-mcp exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use mail-mcp MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If mail-mcp requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇