imap-mcp-server

imap-mcp-server

Bridges an MCP-capable agent to an IMAP4 mailbox, enabling folder exploration, message search, retrieval, keyword management, PGP/MIME decryption, and draft creation.

Category
访问服务器

README

imap-mcp-server

Minimal MCP server that bridges an MCP-capable agent to an IMAP4 mailbox. It uses fastmcp with imap-tools to expose mailbox helpers so an agent can explore folders, search, fetch message content, inspect and change message keywords, decrypt PGP/MIME message bodies, and create draft replies without speaking IMAP directly.

Exposed tools

  • whoami(): Return the configured login/email address.
  • list_mailboxes(directory, pattern): Enumerate folders using IMAP globbing.
  • mailboxes_status(directory): Return MESSAGES, RECENT, and UNSEEN counts.
  • search(directory="INBOX", criteria="ALL"): Run an IMAP search and return matching UIDs.
  • get_header(directory, uids): Fetch raw headers (dict of header name to list of values) for each UID.
  • get_header_field(directory, uids, field): Fetch one header field for each UID.
  • get_text(directory, uids): Fetch the plain text body for each UID, decrypting PGP/MIME messages when possible.
  • get_html(directory, uids): Fetch the HTML body for each UID, decrypting PGP/MIME messages when possible.
  • get_size(directory, uids): Fetch RFC822 message sizes in bytes.
  • get_keywords(directory, uids): Fetch IMAP flags/keywords for each UID.
  • change_keywords(directory, uids, keywords, set): Add or remove IMAP flags/keywords.
  • create_message(content): Append a raw RFC 822 message to the Drafts mailbox.

Notes:

  • UIDs are relative to the folder you query; use the same directory for search and subsequent get_* calls.
  • Message fetches are read-only and avoid marking messages as seen.
  • get_text() and get_html() use the local gpg keyring for multipart/encrypted messages with application/pgp-encrypted.
  • change_keywords() and create_message() modify the mailbox state.

Requirements

  • Python 3.10+
  • An IMAP account with host, username, and either:
    • Password/app password (traditional authentication), or
    • OAuth2 token (for Gmail and other OAuth-enabled providers)
  • gpg installed on the host when you want to read PGP/MIME-encrypted messages

Setup

  1. (Recommended) python3 -m venv .venv && source .venv/bin/activate
  2. Install dependencies: python3 -m pip install -r requirements.txt

Configuration

The server reads credentials from environment variables; a .env file is supported via python-dotenv.

Traditional IMAP Authentication

For standard IMAP servers:

IMAP_HOST=imap.example.com
IMAP_LOGIN=user@example.com
IMAP_PASSWORD=app-specific-password

Gmail OAuth2 Authentication

For Gmail using OAuth2:

IMAP_HOST=imap.gmail.com
IMAP_LOGIN=user@gmail.com
IMAP_TOKEN=your-oauth2-access-token

Optional GnuPG Configuration

To decrypt encrypted message bodies through get_text() and get_html():

GNUPGHOME=/path/to/gpg-home

If GNUPGHOME is unset, the server uses the default GnuPG home directory for the account running mcp-server.py. The required secret keys must already be available in that keyring.

To obtain a Gmail OAuth2 token:

  1. Create OAuth2 credentials in Google Cloud Console
    • Enable Gmail API for your project
    • Create OAuth 2.0 Client ID (Desktop application)
    • Note your client ID and client secret
  2. Run the token helper script:
    python3 gmail_auth.py --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET
    
  3. Follow the browser prompt to authorize access
  4. Copy the access_token to your .env file as IMAP_TOKEN

Keep credentials out of version control and prefer app passwords or OAuth2 tokens when possible.

Run

Direct execution: python mcp-server.py

Register with a client: clause mcp add mailbox ./mcp-server.py or codex mcp add mailbox ./mcp-server.py

You can also run the MCP server using http transport:

fastmcp run mcp-server.py -t http --host 192.168.100.1

And then add it to codex:

codex mcp add email --url http://192.168.100.1:8000/mcp

Ensure you run the command in a shell where the environment variables above are set or a .env file is present.

Example

> Review message-id 20260424091024.23495-1-deller@kernel.org from INBOX/Qemu/linux-user
  1. High: [PATCH 4/4] mis-encodes successful _NEW getsockopt() results when userspace passes a buffer larger than sizeof(struct target__kernel_sock_timeval). The new branch chooses the 64-bit copy path only on exact equality; any larger len falls back to copy_to_user_timeval(), which writes the old layout instead. The decision needs to be based on optname, with len clamped via MIN(...), not on len == sizeof(...). Relevant code is in linux-user/syscall.c:2604. Source for the patch hunk: https://www.mail-archive.com/qemu-devel%40nongnu.org/msg1186189.html

  2. Medium: [PATCH 1/4] should not replace abi_llong with plain int64_t in struct target__kernel_sock_timeval. abi_llong carries target ABI alignment requirements; int64_t does not, so this can change guest-visible layout/alignment on some targets. The current struct is at linux-user/syscall_defs.h:240. Richard Henderson already NACKed this point in-thread: https://www.mail-archive.com/qemu-devel%40nongnu.org/msg1186340.html

I did not find another separate functional issue in patches 2/4 or 3/4 beyond those. If you want, I can turn this into a reply mail in the repo's preferred quoted format.

> Write replies in Draft folder

Two draft replies are in Drafts:

  • Re: [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval
  • Re: [PATCH 4/4] linux-user: Add getsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW

The first calls out the target ABI alignment issue with replacing abi_llong, and the second points out the _NEW getsockopt bug when userspace provides a buffer larger than the 64-bit timeval struct.

License

Distributed under the GNU General Public License v2.0. See LICENSE for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选