MCP IMAP Server
Allows interaction with a Gmail IMAP mailbox, enabling email search, mailbox listing, message retrieval, attachment download, and flag updates such as marking messages seen/unseen or deleted.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MCP IMAP Server
A lightweight Model Context Protocol (MCP) server that exposes your IMAP mailbox through tools, enabling AI assistants to interact with your email.
Features
š Search emails with flexible criteria (sender, subject, date range, text, etc.)
š¬ List mailboxes and folders in your IMAP account
š§ Retrieve messages with full headers, body content, and attachment metadata
š Download attachments (base64 or temporary one-time URL)
ā Mark messages as seen/unseen
šļø Mark messages as deleted (
\\Deleted) in batches of up to 10 (no expunge)š Secure - uses standard IMAP authentication
š Flexible deployment - supports both local (stdio) and remote (HTTP) modes
Related MCP server: imap-mcp
Installation
Prerequisites
Python 3.10 or higher
An IMAP-enabled email account (Gmail, Outlook, etc.)
Setup
Clone this repository:
git clone <repository-url>
cd mcp-imap-serverCreate and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activateInstall the package:
pip install -U pip
pip install -e .Configuration
Environment Variables
Copy .env.example to .env and configure your IMAP settings:
cp .env.example .envRequired Settings
IMAP_HOST- Your IMAP server hostname (e.g.,imap.gmail.com)IMAP_USERNAME- Your email address or usernameIMAP_PASSWORD- Your password or app-specific password
Optional Settings
IMAP_PORT- IMAP server port (default:993)IMAP_SSL- Use SSL/TLS connection (default:true)IMAP_STARTTLS- Use STARTTLS (default:false)IMAP_TIMEOUT_SECONDS- Connection timeout (default:30)MCP_ATTACHMENT_URL_HOST- Host/IP used when returning temporary attachment URLs (must resolve to192.168.x.x; required forserve=trueif auto-detection cannot find one)MCP_ATTACHMENT_URL_PORT- Port used in temporary attachment URLs (default: same asMCP_PORT)MCP_ATTACHMENT_URL_SCHEME- URL scheme for temporary attachment URLs (httporhttps, default:http)MCP_ATTACHMENT_URL_TTL_SECONDS- Token TTL in seconds for temporary attachment URLs (default:300)MCP_ATTACHMENT_STORAGE_DIR- Directory for temporary attachment files
Email Provider Examples
Gmail:
IMAP_HOST=imap.gmail.com
IMAP_USERNAME=your-email@gmail.com
IMAP_PASSWORD=your-app-passwordNote: Gmail requires app-specific passwords when 2FA is enabled.
Outlook/Office 365:
IMAP_HOST=outlook.office365.com
IMAP_USERNAME=your-email@outlook.com
IMAP_PASSWORD=your-passwordUsage
Running with Docker (Recommended)
The easiest way to run the server is using Docker:
Build the Docker image:
docker build -t mcp-imap-server .Run with environment variables:
docker run -d \
--name mcp-imap-server \
-p 8993:8993 \
-e IMAP_HOST=imap.gmail.com \
-e IMAP_USERNAME=your-email@gmail.com \
-e IMAP_PASSWORD=your-app-password \
mcp-imap-serverOr use docker-compose with your
.envfile:
docker-compose up -dThe server will be available at http://localhost:8993/mcp
To view logs:
docker logs -f mcp-imap-serverTo stop:
docker-compose down
# or
docker stop mcp-imap-serverRunning as HTTP Server (Native)
This mode allows AI clients on other machines (like Warp) to connect to your email server:
source .venv/bin/activate
# Listen on all interfaces
MCP_HOST=0.0.0.0 MCP_PORT=8993 mcp-imap-server
# Or listen on localhost only (more secure)
MCP_HOST=127.0.0.1 MCP_PORT=8993 mcp-imap-serverThe MCP endpoint will be available at:
Local:
http://127.0.0.1:8993/mcpRemote:
http://<server-ip>:8993/mcp
You can test the server with:
curl http://localhost:8993/healthRunning in stdio Mode (Local Process)
For local AI clients that spawn the server as a subprocess:
source .venv/bin/activate
MCP_TRANSPORT=stdio mcp-imap-serverConnecting with Warp
In Warp, configure the MCP server by adding to your MCP settings:
{
"mcpServers": {
"imap": {
"url": "http://<server-ip>:8993/mcp"
}
}
}Available Tools
The server exposes the following MCP tools:
list_mailboxes
Returns all available mailboxes/folders in your IMAP account.
Returns: List of mailboxes with names, delimiters, and flags.
search_messages
Search for messages with various criteria.
Parameters:
mailbox(str, default: "INBOX") - Mailbox to search infrom_(str, optional) - Filter by sender emailto(str, optional) - Filter by recipient emailsubject(str, optional) - Filter by subject texttext(str, optional) - Search in message bodyunseen(bool, optional) - Filter by read/unread statussince(str, optional) - Messages since date (YYYY-MM-DD)before(str, optional) - Messages before date (YYYY-MM-DD)limit(int, default: 20) - Maximum number of results
Returns: List of message summaries with UID, subject, sender, date, flags, and size.
get_message
Retrieve full message content by UID.
Parameters:
uid(int, required) - Message UIDmailbox(str, default: "INBOX") - Mailbox containing the messageinclude_body(bool, default: true) - Include message bodyinclude_html(bool, default: false) - Include HTML bodymax_body_chars(int, default: 20000) - Maximum body length
Returns: Full message with headers, body, flags, and attachment metadata.
download_attachment
Download a message attachment by UID.
Parameters:
uid(int, required) - Message UIDmailbox(str, default: "INBOX") - Mailbox containing the messageattachment_index(int, default: 0) - 0-based index among attachmentsfilename(str, optional) - Exact filename match (preferred when known)offset_bytes(int, default: 0) - Start offset into the attachment payload (for chunked downloads)max_bytes(int, default: 10000000) - If > 0, truncate returned bytes to this limitserve(bool, default: false) - If true, return a temporary one-time URL (nocontent_base64)
Returns:
With
serve=false(default): attachment metadata pluscontent_base64With
serve=true: attachment metadata plus:temporary_download_urltemporary_download_url_expires_attemporary_download_url_ttl_secondstemporary_download_url_single_use=true
set_seen
Mark a message as read or unread.
Parameters:
uid(int, required) - Message UIDmailbox(str, default: "INBOX") - Mailbox containing the messageseen(bool, default: true) - Mark as seen (true) or unseen (false)
Returns: Updated message flags.
mark_deleted
Mark up to 10 messages as deleted by setting the IMAP \\Deleted flag.
This tool does not expunge messages. It only marks them so you can review or undo from your IMAP client before any permanent deletion.
Parameters:
uids(list[int], required) - Message UIDs to mark as deleted (max 10)mailbox(str, default: "INBOX") - Mailbox containing the messages
Returns: Mailbox name, marked count, expunged=false, and per-message updated flags.
Security Considerations
ā ļø App-Specific Passwords: Use app-specific passwords instead of your main account password when possible
š Firewall: If running in HTTP mode on
0.0.0.0, ensure your firewall restricts access appropriatelyš Network: For remote access, consider using a VPN or SSH tunnel instead of exposing the server directly to the internet
š Environment Variables: Never commit your
.envfile - it's already in.gitignoreš Read-Only by Default: Most operations are read-only except flag updates (
set_seen,mark_deleted);mark_deleteddoes not expunge
Development
Project Structure
mcp-imap-server/
āāā src/
ā āāā mcp_imap_server/
ā āāā __init__.py
ā āāā __main__.py
ā āāā server.py # Main MCP server and tool definitions
ā āāā config.py # Configuration management
ā āāā imap.py # IMAP client wrapper
āāā pyproject.toml
āāā README.md
āāā .env.example
āāā .gitignoreRunning Tests
To test the server functionality:
Ensure your
.envfile is configured correctlyStart the server in one terminal
Use an MCP client or curl to test the endpoints
Troubleshooting
Connection Errors
Verify your IMAP credentials are correct
Check if your email provider requires app-specific passwords
Ensure the IMAP port (usually 993) is not blocked by your firewall
Try enabling debug logging by checking server output
Authentication Failures
Some providers (like Gmail) require enabling "Less secure app access" or using OAuth2
Use app-specific passwords when 2FA is enabled
Verify the username format (some providers need full email, others just the username)
Performance
Use the
limitparameter insearch_messagesto reduce result sizeAdjust
max_body_charsinget_messageto limit body content sizeConsider using the
unseenfilter to only fetch unread messages
License
GPL-3.0-only ā see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter issues or have questions, please open an issue on the GitHub repository.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogā¦
This server cannot be deployed
Maintenance
Related MCP Connectors
Email infrastructure for AI agents ā send, receive, search, and reply to email over MCP.
Email inboxes for AI agents: send, receive, reply, search, and manage threaded email over MCP.
Your IMAP mailbox as an MCP server: read, search and (if you allow it) organize mail. Open source.
Your agent needs a mailbox of its own ā to receive, thread, draft and send, with attachments, without borrowing your personal inbox or your company's SMTP. **What you can ask for** ⢠"Create an inbox for this agent and tell me its address." ⢠"Read the new messages in this thread and draft a reply." ⢠"Send this message with the attachment and wait for the response." ⢠"Search this inbox for everything from that domain." ⢠"Show delivery metrics and the events on this inbox." **How to use it** Point any MCP client at https://mcp.aisa.one/mail/mcp and sign in with OAuth ā there is no key to create or paste. 49 tools: create and delete inboxes, list and read messages, raw message bodies, attachments, threads, drafts and draft attachments, send and reply, message search, inbox events, metrics, and list entries ā reads and writes. **Why this rather than the source** A real inbox an agent owns, rather than an SMTP credential it borrows from a human. **It is also a door to the rest** The same login reaches 26 sources and 580+ operations. Find the contact elsewhere in the catalogue, then write to them from here ā without adding a second server. **What it costs** Finding and inspecting an operation is free. Running one is billed per call at API prices, with no seat and no monthly minimum, and every call takes max_price_usd so an agent cannot overspend by accident. **Where else it reaches** https://mcp.aisa.one/sales/mcp finds the person to write to.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA generic IMAP and SMTP MCP server that enables AI agents to interact with email accounts for reading, searching, and sending messages. It provides high-level tools for managing email workflows like daily digests and folder organization across any standard email provider.1MIT
- AlicenseBqualityCmaintenanceAn MCP server that exposes IMAP operations as tools for AI assistants, enabling email management including listing mailboxes, reading, searching, moving, flagging emails, and creating drafts.747 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables secure mailbox access and email management via IMAP/SMTP, with tools for reading, searching, organizing, sending, and deleting emails, designed for local use and compatible with MCP clients like ChatGPT.1MIT
- AlicenseNot gradedqualityCmaintenanceConnects any IMAP/SMTP mailbox to AI agents via MCP, enabling email read, search, send, reply, and management through natural language.11 npmMIT