mcp-agent-mail
Allows AI agents to read, send, and reply to GPG-encrypted email through a Gmail account via IMAP/SMTP, with PGP key management, contact book with key provenance, and email archiving/search.
Integrates with GnuPG for PGP operations: encrypting and verifying messages, listing keyring keys, exporting public keys, and managing agent key status, enabling end-to-end encrypted email workflows.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-agent-mailcheck my inbox for new encrypted emails and summarize them"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-agent-mail
Encrypted email + PGP for AI agents, as a local MCP server. Read, send, and reply to GPG-encrypted mail; manage a contact book with key provenance; archive and search everything you read.
Built to be called by any MCP-aware agent harness (Claude, opencode, etc.) over stdio. Works with Gmail and any IMAP/SMTP provider.
Standalone rewrite. This project is a clean, security-hardened rebuild of the earlier prototype. Core security invariants were carried over verbatim; several deliberately-added behavioral changes are flagged with ⚠ below.
Why this design
Keys and bodies must never reach the model's context window:
Inbound PGP key interception — public keys that arrive by email are imported and linked to the sender's contact before the body reaches the model. The block is replaced by a notice, never shown.
No silent downgrade (⚠) —
email_sendencrypts by default. If no key is on file for the recipient it refuses to send; the model must explicitly chooseencrypt=Falseto send in the clear.Full fingerprints only — 16-char key IDs are rejected everywhere (Evil32 collision attack).
Secrets are opaque —
SecretStringwraps passphrase/password; reprs, logs, tracebacks show***. Private keys are never exported.Fail-fast config (⚠) — missing secrets abort startup with a list, never a warning and never a fallback default.
Related MCP server: mcp-imap
Tool surface
Domain | Tools |
| |
Contacts |
|
GPG |
|
Archive |
|
Utility |
|
Requirements
Python 3.13+
GnuPG — Gpg4win on Windows,
gnupg2on Linux/macOSAn email account with IMAP/SMTP app-password access (Gmail: enable 2FA, create an app password)
Install
git clone <repo-url> mcp_agent_mail
cd mcp_agent_mail
uv syncSetup
Generate a dedicated agent PGP key pair:
gpg --full-generate-keyCreate
.envfrom the template and fill it (see.env.examplefor passphrase quoting pitfalls):Copy-Item .env.example .envRequired:
EMAIL_ADDRESS,EMAIL_PASSWORD(app password),GPG_KEY_ID(the agent key's full 40-char fingerprint),GPG_PASSPHRASE.The
envbackend stores secrets in plaintext on disk. For production use, followdocs/SECURITY.mdand plan to move to a credential-store backend (M2 roadmap: Windows Credential Manager / KeePassXC / gpg-agent pinentry).Sanity check:
uv run mcp-agent-mail setup # deps + key presence + secret status uv run mcp-agent-mail doctor # offline config diagnostics uv run mcp-agent-mail doctor --live # opt-in IMAP + keyring checks
Usage
Run as an MCP server (stdio — what harnesses expect)
uv run mcp-agent-mailTo serve over HTTP instead:
uv run mcp-agent-mail serve --http --port 8000Register in an MCP client
Point the client at the project — the server reads .env directly and does
not need the environment pre-seeded:
{
"mcpServers": {
"mcp-agent-mail": {
"command": "uv",
"args": ["--project", "C:/path/to/mcp_agent_mail", "run", "mcp-agent-mail"]
}
}
}CLI commands
Command | Purpose |
| Run the MCP server. |
| Check dependencies, key presence, secret status |
| Offline diagnostics; |
| List keyring keys ( |
| Inspect the JSONL archive ( |
Development
uv run ruff check .
uv run pytest -q101 tests cover: secret handling, fail-fast config, fingerprint/key-block
validation, contact provenance, archive dedup/search, the outbound encryption
gate, and the full tool surface. No .env or real account is needed — tests
seed fake secrets and mock the transports.
Configuration reference
Var | Default | Purpose |
| — (required) | Account identity / IMAP+SMTP login |
| — (required) | IMAP/SMTP app password |
| — (required) | Agent key fingerprint (40 hex) |
| — (required) | Agent key passphrase |
|
| Secret resolution backend (M2: more) |
|
| IMAP (SSL) |
|
| SMTP (STARTTLS) |
|
| Set |
|
| From display name |
|
| Relative to project root |
|
| JSONL mail archive |
|
| Rotating DEBUG logs (5×5 MB) |
|
| Where public keys are exported |
| (blank = system default) | Must be blank or absolute |
Documentation
docs/SECURITY.md— threat model, guarantees, trade-offsdocs/ARCHITECTURE.md— module map and data flow
License
MIT © 2026 Christof Milius
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.
- PO6 MailboxOAuthcom.po6
Give AI agents secure access to your email via private aliases with dedicated mailbox storage.
Hosted email for AI agents: create inboxes, send, receive, and reply over MCP with scoped API keys
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to manage multiple email accounts with secure credentials, local full-text search, thread-aware replies, and automation.6 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with email accounts via IMAP and SMTP, supporting mailbox listing, email search, retrieval, sending, and management.MIT
- AlicenseBqualityDmaintenanceEnables AI assistants to send, read, and manage emails via SMTP and IMAP, with support for attachments, threads, and mailbox organization.1617 npm1MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI models to send, receive, search, and manage emails via SMTP/IMAP, including support for attachments, contacts, and advanced search.-