Minimal MCP server that bridges an MCP-capable agent to an IMAP mailbox.
Project description
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): ReturnMESSAGES,RECENT, andUNSEENcounts.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 theDraftsmailbox.
Notes:
- UIDs are relative to the folder you query; use the same
directoryforsearchand subsequentget_*calls. - Message fetches are read-only and avoid marking messages as seen.
get_text()andget_html()use the localgpgkeyring formultipart/encryptedmessages withapplication/pgp-encrypted.change_keywords()andcreate_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)
gpginstalled on the host when you want to read PGP/MIME-encrypted messages
Setup
- (Recommended)
python3 -m venv .venv && source .venv/bin/activate - 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:
- 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
- Run the token helper script:
python3 gmail_auth.py --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET - Follow the browser prompt to authorize access
- Copy the
access_tokento your.envfile asIMAP_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
-
High:
[PATCH 4/4]mis-encodes successful_NEWgetsockopt()results when userspace passes a buffer larger thansizeof(struct target__kernel_sock_timeval). The new branch chooses the 64-bit copy path only on exact equality; any largerlenfalls back tocopy_to_user_timeval(), which writes the old layout instead. The decision needs to be based onoptname, withlenclamped viaMIN(...), not onlen == sizeof(...). Relevant code is inlinux-user/syscall.c:2604. Source for the patch hunk: https://www.mail-archive.com/qemu-devel%40nongnu.org/msg1186189.html -
Medium:
[PATCH 1/4]should not replaceabi_llongwith plainint64_tinstruct target__kernel_sock_timeval.abi_llongcarries target ABI alignment requirements;int64_tdoes not, so this can change guest-visible layout/alignment on some targets. The current struct is atlinux-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_timevalRe: [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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file imap_mcp_server-0.1.0.tar.gz.
File metadata
- Download URL: imap_mcp_server-0.1.0.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
438febcd071a38eef2f897f3047474f4805761d70b0ab707f1bf744e230058b3
|
|
| MD5 |
2e469cf3f48551c825ef18814196650e
|
|
| BLAKE2b-256 |
a07b2a1d3bab2dd57a52507c288ec75b20a12d1b9adde5893eb534a5f1b4256a
|
Provenance
The following attestation bundles were made for imap_mcp_server-0.1.0.tar.gz:
Publisher:
python-publish.yml on vivier/imap-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
imap_mcp_server-0.1.0.tar.gz -
Subject digest:
438febcd071a38eef2f897f3047474f4805761d70b0ab707f1bf744e230058b3 - Sigstore transparency entry: 1412340091
- Sigstore integration time:
-
Permalink:
vivier/imap-mcp-server@87481d611c02765afdd089835d291f5e43c7b7af -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vivier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@87481d611c02765afdd089835d291f5e43c7b7af -
Trigger Event:
release
-
Statement type:
File details
Details for the file imap_mcp_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: imap_mcp_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be05e4339d1711502003ae17ba17bb68acf87134ff63ad5db29a5a88f23f42d
|
|
| MD5 |
ed710ab142a9e573a6f877ef750e0bec
|
|
| BLAKE2b-256 |
6e3491d6cc2d08385e8c74a492afd2ce9a97959a1f898da16e925ae7f5e79403
|
Provenance
The following attestation bundles were made for imap_mcp_server-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on vivier/imap-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
imap_mcp_server-0.1.0-py3-none-any.whl -
Subject digest:
8be05e4339d1711502003ae17ba17bb68acf87134ff63ad5db29a5a88f23f42d - Sigstore transparency entry: 1412340222
- Sigstore integration time:
-
Permalink:
vivier/imap-mcp-server@87481d611c02765afdd089835d291f5e43c7b7af -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vivier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@87481d611c02765afdd089835d291f5e43c7b7af -
Trigger Event:
release
-
Statement type: