Real-time global intelligence dashboard. AI-powered news aggregation, geopolitical monitoring, and infrastructure tracking in a unified situational awareness interface
IMAP email connector for Claude and MCP clients
This repo provides an MCP server that lets an agent read, search, send, reply to, forward, and organize email across one or more IMAP accounts. It stores credentials securely, pools connections, and offers a web setup flow for common mail providers.
Builders who want their agent to read and manage email accounts through MCP.
You can handle email work from your agent instead of switching to a mail client.
What it does
Secure account storage
Stores account credentials encrypted and supports runtime environment overrides for sensitive fields.
Email search and retrieval
Searches messages across folders, fetches full email content, and can include parsed body text in one call.
Send, reply, forward, and drafts
Sends mail through SMTP, replies or forwards threads, and saves drafts and sent copies when configured.
Folder and mailbox tools
Lists folders, checks folder status, counts unread mail, and helps find threads across folders.
Bulk and safety controls
Supports bulk delete, read-only mode, and tool allowlists to limit what the agent can do.
Web setup wizard
Includes a browser-based setup flow with presets for common email providers and account creation help.
How to get it
- 1Once published to npm, you can run the server directly without cloning or buildingβ¦
npx -y imap-mcp-server
- 2Run
curl -fsSL https://raw.githubusercontent.com/nikolausm/imap-mcp-server/main/install.sh | bash
- 3Run
iwr -useb https://raw.githubusercontent.com/nikolausm/imap-mcp-server/main/install.ps1 | iex
- 4Clone the repository
git clone https://github.com/nikolausm/imap-mcp-server.git cd imap-mcp-server
- 5Install dependencies
npm install
- 6Build the project
npm run build
README
IMAP MCP Server
A powerful Model Context Protocol (MCP) server that provides seamless IMAP email integration with secure account management and connection pooling.
Features
- π Secure Account Management: Encrypted credential storage with AES-256 encryption
- π Connection Pooling: Efficient IMAP connection management
- π§ Comprehensive Email Operations: Search, read, move, mark, delete, and bulk delete emails
- βοΈ Email Sending: Send, reply, and forward emails via SMTP
- π Folder Management: List folders, check status, get unread counts
- π Multiple Account Support: Manage multiple IMAP accounts simultaneously
- π‘οΈ Type-Safe: Built with TypeScript for reliability
- π Web-Based Setup Wizard: Easy account configuration with provider presets
- π± 15+ Email Providers: Pre-configured settings for Gmail, Outlook, Yahoo, and more
- π Auto SMTP Configuration: Automatic SMTP settings based on IMAP provider
Installation
Requires Node.js 22.12 or newer. Node 18 and 20 have both reached end-of-life, and several of this package's dependencies no longer support them. Check yours with
node --version.
Run via npx (No Installation Required)
Once published to npm, you can run the server directly without cloning or building anything β npx downloads the prebuilt package and runs it:
npx -y imap-mcp-server
This is the easiest way to use the server in an MCP client (see Configuration for ready-to-paste npx configs).
Quick Install (Recommended)
macOS/Linux:
curl -fsSL https://raw.githubusercontent.com/nikolausm/imap-mcp-server/main/install.sh | bash
Windows (PowerShell as Administrator):
iwr -useb https://raw.githubusercontent.com/nikolausm/imap-mcp-server/main/install.ps1 | iex
Manual Installation
- Clone the repository:
git clone https://github.com/nikolausm/imap-mcp-server.git
cd imap-mcp-server
- Install dependencies:
npm install
- Build the project:
npm run build
Account Setup
Accounts are stored encrypted in ~/.imap-mcp/accounts.json. This file is shared by all run modes β whether you start the server via npx, a global install, or a local clone, they all read the same accounts. So you only need to set up your accounts once.
Setting Up Accounts in npx Mode
If you run the server via npx (no clone), you have two ways to add accounts:
Option A β Run the setup wizard directly via npx (no install needed):
npx -p imap-mcp-server imap-setup
This launches the same web-based wizard described below and writes to ~/.imap-mcp/accounts.json, which your npx-configured MCP server then picks up automatically.
Option B β Add accounts straight from your AI client:
Once the MCP server is configured, just ask your assistant to add an account β it uses the imap_add_account tool. For example:
"Add my IMAP account: host imap.gmail.com, port 993, user me@gmail.com, password β¦"
No separate setup step required.
Web-Based Setup Wizard (Recommended)
After installation, run the setup wizard:
npm run setup
Or if installed globally:
imap-setup
Or directly via npx without installing:
npx -p imap-mcp-server imap-setup
This will:
- Start a local web server
- Open your browser to the setup wizard
- Guide you through adding email accounts with pre-configured settings
Overriding Credentials via Environment Variables
You can override the username and password of an already-configured account at
runtime with environment variables β useful when you inject secrets from a
password manager or CI system instead of storing them in accounts.json.
The variables are keyed by the account name, uppercased with every
non-alphanumeric character replaced by _. For an account named Work Gmail
(key WORK_GMAIL):
| Variable | Overrides |
|---|---|
IMAP_MCP_ACCOUNT_WORK_GMAIL_IMAP_USERNAME | IMAP username (user) |
IMAP_MCP_ACCOUNT_WORK_GMAIL_IMAP_PASSWORD | IMAP password |
IMAP_MCP_ACCOUNT_WORK_GMAIL_SMTP_USERNAME | SMTP username (smtp.user) |
IMAP_MCP_ACCOUNT_WORK_GMAIL_SMTP_PASSWORD | SMTP password |
Notes:
- Overrides apply only to existing accounts; if no account's normalized name matches, the variable is ignored.
- They are applied in memory only β nothing is written back to
accounts.json, and the values are used as-is (not re-encrypted). - Variables are consumed at startup: on server start they are captured into
an AES-256-encrypted in-memory cache and removed from
process.env, so the plaintext secret does not linger in the environment (where it could leak to child processes or diagnostics). Set them before launching the server.
The setup wizard integrates with this: each credential field (IMAP password,
IMAP username, SMTP username, SMTP password) has a "Do not save to config; set
later using an environment variable" checkbox. When ticked, the value you enter
is still used to test the connection, but it is not written to accounts.json β
the wizard shows the exact variable name to export, and the account picks the
credential up from that variable at runtime.
- SMTP variables take effect only when the account already has an SMTP config.
- Each variable takes effect independently; set only the ones you need.
If the variable is missing, the account still holds the empty placeholder the wizard wrote. Rather than dialing out with a blank credential β which providers answer with a generic authentication failure that looks exactly like a wrong password β the server refuses the connection and names what to set:
Account "Work Gmail" has IMAP credentials marked as environment-managed, but
this variable was not set when the server started:
IMAP_MCP_ACCOUNT_WORK_GMAIL_IMAP_PASSWORD. Set it and restart the server, or
store the credentials on the account via imap_update_account.
Because the variables are read once at startup, setting one in an already-running shell has no effect until the server is restarted.
Supported Email Providers
The setup wizard includes pre-configured settings for:
- Gmail / Google Workspace
- Microsoft Outlook / Hotmail / Live
- Yahoo Mail
- Apple iCloud Mail
- GMX
- WEB.DE
- IONOS (1&1)
- ProtonMail (with Bridge)
- Fastmail
- Zoho Mail
- AOL Mail
- mailbox.org
- Posteo
- Custom IMAP servers
Configuration
Claude Code (CLI)
Option A β via npx (no clone/build needed)
claude mcp add imap -- npx -y imap-mcp-server
This always runs the latest published version and requires no local build.
Option B β from a local clone
If you use Claude Code in the terminal, add the MCP server with a single command:
Step 1: Make sure you have built the project first (see Manual Installation).
Step 2: Run this command in your terminal:
claude mcp add imap -- node /absolute/path/to/imap-mcp-server/dist/index.js
Important: Replace
/absolute/path/to/imap-mcp-serverwith the actual path where you cloned the repository. For example:# macOS/Linux example: claude mcp add imap -- node /Users/yourname/imap-mcp-server/dist/index.js # Windows example: claude mcp add imap -- node C:\Users\yourname\imap-mcp-server\dist\index.js
Step 3: Verify it was added:
claude mcp list
You should see imap in the list of configured MCP servers. That's it β the IMAP tools are now available in your Claude Code sessions.
Tip: If you want to remove the server later, run:
claude mcp remove imap
Claude Desktop (GUI App)
Add the IMAP MCP server to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Option A β via npx (recommended, no clone/build needed):
{
"mcpServers": {
"imap": {
"command": "npx",
"args": ["-y", "imap-mcp-server"],
"env": {}
}
}
}
Option B β from a local clone:
{
"mcpServers": {
"imap": {
"command": "node",
"args": ["/path/to/imap-mcp-server/dist/index.js"],
"env": {}
}
}
}
Restricting tool access (read-only mode / allowlist)
By default all tools are exposed. You can restrict which tools the agent sees
using two environment variables (set them under the env key of your MCP
config). This is useful when you want to give an assistant read-only access
to a mailbox, or expose only a hand-picked subset of tools.
| Variable | Effect |
|---|---|
IMAP_MCP_READ_ONLY | When truthy (1, true, yes, on), only the safe, read-only tools are registered β searching, reading, listing folders, unread counts, spam analysis. No tool that sends mail, deletes/moves messages, changes flags, or edits accounts is exposed. |
IMAP_MCP_ENABLED_TOOLS | Comma-separated allowlist of tool names β only these are registered. Names are case-insensitive and the imap_ prefix is optional (search_emails β‘ imap_search_emails). When set, it takes precedence over IMAP_MCP_READ_ONLY. |
Example β read-only access:
{
"mcpServers": {
"imap": {
"command": "npx",
"args": ["-y", "imap-mcp-server"],
"env": { "IMAP_MCP_READ_ONLY": "true" }
}
}
}
Example β explicit allowlist:
{
"mcpServers": {
"imap": {
"command": "npx",
"args": ["-y", "imap-mcp-server"],
"env": { "IMAP_MCP_ENABLED_TOOLS": "imap_search_emails,imap_get_email,imap_get_latest_emails" }
}
}
}
The read-only subset is: imap_list_accounts, imap_connect, imap_disconnect,
imap_test_account, imap_search_emails, imap_get_email,
imap_get_latest_emails, imap_download_attachment, imap_find_thread_messages,
imap_find_email_by_message_id, imap_list_folders, imap_folder_status,
imap_get_unread_count, imap_check_spam, imap_domain_stats,
imap_list_spam_domains.
Usage
Once configured, the IMAP MCP server provides the following tools in Claude:
Choosing an account. For the email and folder tools,
accountIdis optional and backward-compatible. You may instead passaccountName, and if you only have a single account configured you can omit both β that account is used by default. With multiple accounts and no selector, the tool returns a clear error listing your options (imap_list_accounts).
Account Management
-
imap_add_account: Add a new IMAP account
Parameters: - name: Friendly name for the account - host: IMAP server hostname - port: Server port (default: 993) - user: Username - password: Password - tls: Use TLS/SSL (default: true) - sentFolder: Explicit Sent-folder name for sent-mail copies, e.g. "Gesendet" (optional β only needed when the server has no \Sent SPECIAL-USE folder and auto-detection fails) - defaultBcc: Optional BCC address(es) applied automatically to every outbound send, reply, forward, and draft for this account. Merged with any per-call `bcc` (duplicates removed case-insensitively) -
imap_update_account: Update an existing account (fix SMTP settings, rename, etc.)
Parameters: - accountId: ID of the account to update - name, host, port, user, password, tls, email: IMAP fields (all optional) - smtpHost, smtpPort, smtpSecure, smtpUser, smtpPassword: SMTP fields (optional) - saveToSent: Save sent emails to the Sent folder (optional) - sentFolder: Explicit Sent-folder override (optional). Pass an empty string to clear the override and re-enable auto-detection - defaultBcc: Optional default BCC address(es) (optional). Pass an empty string to clear -
imap_list_accounts: List all configured accounts
-
imap_remove_account: Remove an account
Parameters: - accountId: ID of the account to remove -
imap_connect: Connect to an account
Parameters: - accountId OR accountName: Account identifier -
imap_disconnect: Disconnect from an account
Parameters: - accountId: Account to disconnect
Email Operations
-
imap_search_emails: Search for emails
Parameters: - accountId: Account ID - folder: Folder name (default: INBOX; ignored when searchAllFolders is true) - searchAllFolders: Search across ALL folders at once (default: false). Skips Trash/Spam/Drafts and non-selectable folders by default. Use when a message may have been filed/moved/archived and you don't know its folder. - includeTrash, includeSpam, includeDrafts: Opt those noisy folders back into a searchAllFolders run (default: false each) - from, to, subject, body: Search criteria - since, before: Date filters - seen, flagged: Status filters - keywords: Match messages with ANY of these custom keywords (server-side OR). Read a mailbox's available custom keywords from `imap_folder_status`'s `customKeywords` field first. - unKeywords: Exclude messages with ANY of these custom keywords (result has NONE of them). Same keyword source as `keywords`. - limit: Max results (default: 50) - includeBody: Include parsed message body in the response (default: false). Fetches the RFC822 source once and parses it with mailparser, so you get uid + body in a single tool call instead of paying the N+1 cost of one `imap_get_email` per match. Body is rendered per `bodyFormat` and capped at `bodyMaxLength` per field. - bodyFormat: How to render the body when `includeBody` is true β `markdown` (default, clean Markdown via Turndown), `text`, `html`, or `auto`. - bodyMaxLength: Per-field cap when `includeBody` is true (default: 10000).With
searchAllFolders, results include afolderfield per message plusfoldersSearched, and any folder that failed to open is reported infoldersErrored(so a 0-result answer is never silently incomplete).includeBodyis honored in the single-folder path only. For a cross-folder sweep the lightweight header shape is preserved by design β pulling RFC822 source for every match across many folders would multiply bandwidth and parse cost. Follow up withimap_get_emailfor the specific uids whose bodies you need.On some servers a "flagged"/starred message carries a custom keyword (e.g. an Open-Xchange color label or Apple's
$MailFlagBit*) instead of, or in addition to, the\Flaggedsystem flag β after any flagged search, check each result'scustomKeywordsfield before concluding a message is or isn't flagged. -
imap_get_email: Get full email content
Parameters: - accountId: Account ID - folder: Folder name - uid: Email UID - maxContentLength: Max characters for text/html body (default: 10000) - includeAttachmentText: Include text attachment previews (default: true) - maxAttachmentTextChars: Max characters per text attachment (default: 100000) -
imap_get_latest_emails: Get recent emails
Parameters: - accountId: Account ID - folder: Folder name (default: INBOX) - count: Number of emails (default: 10) - includeBody: Include parsed message body (default: false). Same semantics as the `includeBody` option on `imap_search_emails` β one round-trip instead of NΓ`imap_get_email`. - bodyFormat: `markdown` (default), `text`, `html`, or `auto`. - bodyMaxLength: Per-field cap (default: 10000). -
imap_mark_as_read/unread: Change email read status
Parameters: - accountId: Account ID - folder: Folder name - uid: Email UID, OR an array of UIDs to flag in one call. Batch uses a single IMAP STORE so the operation is atomic at the server level β all UIDs are flagged, or none. Useful when triaging many messages at once. -
imap_flag_email/unflag_email: Star/unstar an email (sets or clears the IMAP \Flagged system flag β shows as a "star" in Gmail and Apple Mail). Some servers/clients (Open-Xchange, Apple Mail) also set a separate custom keyword (e.g.
$cl_N,$MailFlagBit*) when flagging; unflag only clears\Flagged, so if a message still shows as flagged, checkcustomKeywordsviaimap_get_emailand clear it withimap_remove_keyword.Parameters: - accountId: Account ID - folder: Folder name - uid: Email UID -
imap_add_keyword/remove_keyword: Set or clear an arbitrary custom (non-system) IMAP keyword/label on an email, passed through verbatim (e.g. provider color labels like Open-Xchange's
$cl_1..$cl_10or Apple Mail's$MailFlagBit0..$MailFlagBit2, or any other custom keyword). Backslash-prefixed system flags (e.g.\Flagged,\Seen,\Deleted) are rejected β use the dedicated flag/read tools for those. Not every server permits custom-keyword changes (see the mailbox's PERMANENTFLAGS); if the server rejects or silently ignores the change, the call fails instead of reporting success.Parameters: - accountId: Account ID - folder: Folder name - uid: Email UID - keyword: IMAP keyword to set/remove (e.g. "$cl_3") -
imap_delete_email: Delete an email
Parameters: - accountId: Account ID - folder: Folder name - uid: Email UID -
imap_move_email: Move an email from one folder to another
Parameters: - accountId: Account ID - folder: Source folder name (default: INBOX) - uid: Email UID, OR an array of UIDs to move in one call. Batch moves are attributed per-uid in the response (`results[]` with per-uid `uidMap` and any errors). Single-uid calls return the legacy response shape. - targetFolder: Destination folder name - createDestinationIfMissing: Create the destination folder if it does not exist (default: false) -
imap_find_thread_messages: Find inbox messages that belong to the same conversation threads as messages already sorted into another folder. Uses RFC 3501 HEADER search on In-Reply-To and References β works on any IMAP server.
Parameters: - accountId: Account ID - sourceFolder: Folder containing the already-sorted thread messages - searchFolder: Folder to search for related messages (default: INBOX) - searchReferences: Also match the References header for multi-level threads (default: true) - includeBody: Include parsed message body for each found thread message (default: false). Same semantics as the `includeBody` option on `imap_search_emails` β one round-trip instead of NΓ`imap_get_email`. - bodyFormat: `markdown` (default), `text`, `html`, or `auto`. - bodyMaxLength: Per-field cap (default: 10000). -
imap_download_attachment: Download an email attachment (returns images inline, extracts text from PDFs, or saves to downloads directory)
Parameters: - accountId: Account ID - folder: Folder name (default: INBOX) - uid: Email UID - filename: Attachment filename or contentId - savePath: Optional file path to save the attachment to - extractText: For PDFs, extract and return text content inline (default: true) -
imap_bulk_delete: Delete multiple emails at once with chunking and auto-reconnection
Parameters: - accountId: Account ID - folder: Folder name (default: INBOX) - uids: Array of email UIDs to delete - chunkSize: Emails to delete per batch (default: 50) -
imap_bulk_delete_by_search: Search for emails matching criteria and delete them all
Parameters: - accountId: Account ID - folder: Folder name (default: INBOX) - from, to, subject: Search criteria (optional) - before, since: Date filters (optional) - chunkSize: Emails to delete per batch (default: 50) - dryRun: Preview what would be deleted without deleting (default: false)At least one concrete criterion (
from,to,subject,before, orsince) is required β a call with no criteria is refused, so it can never match and delete an entire folder. -
imap_send_email: Send a new email
Parameters: - accountId: Account ID to send from - to: Recipient email address(es) β an array, or a single comma-separated string - subject: Email subject - text: Plain text content (optional) - html: HTML content (optional) - cc: CC recipients (optional) - bcc: BCC recipients (optional) - replyTo: Reply-to address (optional) - attachments: Array of attachments (optional) - filename: Attachment filename - content: Base64 encoded content - path: File path to attach - contentType: MIME type - contentDisposition: "attachment" (default) or "inline" β use "inline" for images shown in the HTML body via cid: - cid: Content-ID for inline attachments; must match the `cid:` value used in an `<img src="cid:...">` tag in `html`After sending, a copy is saved to the account's Sent folder (unless
saveToSentis disabled on the account). The folder is resolved via the account'ssentFolderoverride β the server's\SentSPECIAL-USE flag β a list of known localized names ("Sent", "Gesendet", "ΓlΓ©ments envoyΓ©s", β¦). The response reports the outcome:savedToSent(boolean),sentFolder(the folder used), and β when the save fails βsentSaveErrorexplaining why, instead of failing silently. The same applies toimap_reply_to_emailandimap_forward_email.When the account has
defaultBccconfigured, those address(es) are always BCC'd on send, reply, forward, and draft (merged with any per-callbcc; duplicates removed case-insensitively). The Bcc header is kept in the MIME stored for drafts and Sent-folder copies so mail clients show it. -
imap_save_draft: Save an email as a draft (no send). Takes the same fields as
imap_send_email, plusinReplyTo,references, and an optionalfolderoverride for the Drafts folder. -
imap_reply_to_email: Reply to an existing email
Parameters: - accountId: Account ID - folder: Folder containing the original email - uid: UID of the email to reply to - text: Plain text reply content (optional) - html: HTML reply content (optional) - replyAll: Reply to all recipients (default: false) - bcc: BCC recipients (optional; merged with account defaultBcc) - attachments: Array of attachments (optional, same shape as imap_send_email, including contentDisposition/cid for inline images) -
imap_forward_email: Forward an existing email
Parameters: - accountId: Account ID - folder: Folder containing the original email - uid: UID of the email to forward - to: Forward to email address(es) - text: Additional text to include (optional) - bcc: BCC recipients (optional; merged with account defaultBcc) - includeAttachments: Include original attachments (default: true)
Folder Operations
-
imap_list_folders: List all folders
Parameters: - accountId: Account IDEach folder includes its
attributes(raw IMAP LIST flags) and, when the server advertises it,specialUseβ the RFC 6154 role (\Sent,\Drafts,\Trash,\Junk,\Archive) that identifies a folder independent of its localized display name (e.g. "Gesendet" carriesspecialUse: "\Sent"). -
imap_folder_status: Get folder information
Parameters: - accountId: Account ID - folder: Folder name Returns: - messages: { total, new, unseen } β from IMAP STATUS - uidvalidity, uidnext - flags, permanentFlags: string arrays - customKeywords: the mailbox's non-system keywords, usable as the `keywords` / `unKeywords` input of imap_search_emails -
imap_create_folder: Create a new IMAP folder/mailbox. Most servers also create any missing parent folders. Returns success even if the folder already exists.
Files in the repo
- .github
- public
- src
- tests
- .gitignore
- AGENTS.md
- build.mjs
- CHANGELOG.md
- CLAUDE.md
- example-usage.md
- install.ps1
- install.sh
- LICENSE
- package-lock.json
- package.json
- quick-install.sh
- README.md
- SECURITY.md
- server.json
- tsconfig.json
- vitest.config.ts
Discussion (0)
Ask about usage, or say what you built with itSign in to join the discussion.
No comments yet. Be the first to say what this is good for.
More connectors

Universal provider proxy for OpenAI Codex & Claude Code β use any LLM (Claude, Gemini, Grok, DeepSeek, Ollamaβ¦) with Codex CLI, App, SDK, and Claude Code
BankMCPβ’: your AI can now read your bank. Self-hosted, read-only MCP server for your own bank accounts via open banking (Enable Banking). Standard MCP; tested with Claude and Ollama.
Open-source auth gateway connecting 1400+ SaaS providers to AI agents through SDK, CLI, MCP, HTTP, and OpenAPI.
Open-source 3D architectural editor with a local CLI, MCP tools, and practical workflows for humans and AI agents.
Open-source MCP server for comparing products and asking the buyer before purchase.