imap-mcp
An MCP server that gives Claude access to plain IMAP mailboxes, enabling reading, searching, moving, and forwarding emails with safety controls configured via config files.
README
imap-mcp — let your AI manage your mailbox
An MCP server that turns any plain IMAP mailbox into something Claude (or any MCP client) can work in: search it, clean it up, file things away, pull out attachments and forward receipts to your accounting system — while hard, config-level guardrails make sure it can never send to strangers or delete anything permanently.
Gmail and Microsoft 365 have official connectors. This is for the rest of your mail: self-hosted servers, Migadu, your domain host's IMAP, the old business account you still have to check. Standard IMAP/SMTP is all it needs.
What you can use it for
Inbox cleanup that respects your judgment. Most of what lands in an inbox isn't spam — it's just not important: newsletters you once signed up for, event marketing, "your webinar starts in 2 hours" for a webinar that ended last month, renewal warnings for things you already renewed. Ask your AI to sweep the inbox, trash the noise (recoverable — trash is the only "delete" that exists), and ask you about anything it isn't sure of.
Receipts and invoices to your accounting system. Have the AI find
invoices and receipts across folders, file them in a Receipts folder,
download the PDFs, or forward them directly to your bookkeeper or your
accounting system's inbox address (e-conomic, Billy, Dinero, …) — but
only to addresses you've whitelisted in the config.
Spend your time on what matters. Instead of wading through 60 unread mails, ask: "go through my inbox, summarize what actually needs me, star it and mark it unread — archive or trash the rest." You come back to a mailbox where the flagged items are the to-do list and everything else is filed.
Find that mail you filed away and forgot. Cross-folder search means "somewhere in this account there's a confirmation from my Apple developer enrollment" is a one-line request, not ten minutes of clicking through folders.
Example prompts that work well in Claude Desktop / Cowork:
Go through the INBOX on
personal. Move obvious newsletters and marketing to trash, file receipts into a Receipts folder, and give me a prioritized summary of what needs my attention. Star what I need to handle and mark it unread. Ask before touching anything you're unsure about.
Here's a spreadsheet of missing receipts. Search all folders for each one (supplier, amount, date), download the PDFs, and forward the mails to my bookkeeping inbox. Show me the list before you send anything.
Safety model
The guardrails live in config, not in prompt instructions — so they hold no matter what the model is asked to do, including by a malicious mail trying to prompt-inject it:
- Reading is always allowed, and folders are opened read-only, so nothing even gets marked as read by accident.
- Writes require
"allow_writes": trueper account inaccounts.json— without it every write tool refuses. - No permanent deletion. "Delete" means move to the trash folder
(
trash_folder, defaultTrash), so everything is recoverable until the server's own retention empties it. - Forwarding only to a whitelist.
forward_messagerequires an"smtp"block and an"allow_send_to"list on the account. Recipients are matched against the list (wildcards like*@e-conomic.dkare fine) — anything else is refused hard. There is no compose-new-mail tool, only forward.
Setup
Requires Python 3.11+ on PATH and Claude Desktop installed.
-
Clone/copy this folder and run the setup script:
- Windows (PowerShell):
.\setup.ps1 - macOS/Linux:
bash setup.sh
The script creates a venv, installs dependencies, creates
accounts.jsonfrom the template (if missing) and registers the server asimap-mailin Claude Desktop's config (Windows:%APPDATA%\Claude\, macOS:~/Library/Application Support/Claude/). - Windows (PowerShell):
-
Fill in
accounts.json— host, username and password per account. The key (e.g.personal) is the name Claude uses as theaccountparameter.encryption:"ssl"(port 993, default) or"starttls"(port 143).- Use an app password if your provider supports them.
accounts.jsonis gitignored — credentials are entered per machine.
-
Test the configuration (Windows:
.venv\Scripts\python.exe, macOS/Linux:.venv/bin/python):.venv/bin/python server.py --check -
Restart Claude Desktop.
Tools
| Tool | Does |
|---|---|
list_accounts |
List configured accounts |
list_folders |
Folders in an account (INBOX, Sent, …) |
search_messages |
Search (sender/subject/text/date), newest first — one folder or the whole account (all_folders) |
get_message |
Read one message incl. its attachment list |
download_attachment |
Save one attachment to a directory (never overwrites) |
create_folder |
Create a new folder (requires allow_writes) |
move_messages |
Move messages between folders (requires allow_writes) |
trash_messages |
Move messages to the trash folder (requires allow_writes) |
mark_messages |
Star/unstar and mark read/unread (requires allow_writes) |
forward_message |
Forward a message incl. attachments (requires smtp + allow_send_to) |
Notes and limitations
- Search criteria containing non-ASCII characters are not sent to the
IMAP server (many servers reject UTF-8 SEARCH) — they are filtered
locally instead. Always constrain with
since/before; otherwise only the newest ~300 messages are scanned, and the response setsscan_truncated: trueso the model knows to narrow the range. accounts.jsonstores credentials in plain text. Keep it out of git and sync services (it is gitignored here), prefer app passwords, and treat the file like you would a password manager export.- Authentication is plain IMAP/SMTP login — no OAuth. Gmail and Microsoft 365 accounts are better served by their official connectors anyway; this server is for everything else.
- Mail content is untrusted input. The config-level guardrails limit the blast radius of prompt injection, but it's still wise to tell your AI to treat mail text as data, not instructions, and to confirm with you before forwarding anything.
Tests
.venv/bin/python test_server.py
Runs offline — verifies tool registration, config validation and the write/send gating without touching any mail server.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。