mcp-server-mail-agent
Multi-account email management server supporting IMAP, Gmail, and Outlook with a unified inbox, security-first design, and Docker-ready deployment.
README
MCP Email Server
A Model Context Protocol (MCP) server for email management supporting multiple providers and accounts with a unified inbox.
Features
- Multi-Provider: Gmail (OAuth2), Outlook (Microsoft Graph), and any IMAP server
- Multi-Account: Unified inbox across all your email accounts
- Security-First: Secrets must use environment variables (plaintext rejected)
- Docker-Ready: Runs in a container for security and portability
- MCP Standard: Works with Claude Code, Claude Desktop, and any MCP-compatible client
Supported Providers
| Provider | Auth Method | Features |
|---|---|---|
| Gmail | OAuth2 | Full Gmail API access |
| Outlook | OAuth2 | Microsoft Graph API |
| IMAP | App Password | Any email server (Gmail, Yahoo, iCloud, custom) |
Quick Start
1. Clone & Install
git clone https://github.com/gufao/mcp-server-mail-agent.git
cd mcp-server-mail-agent
npm install
2. Configure
# Create credentials directory
mkdir -p credentials
# Copy example files
cp accounts.example.json credentials/accounts.json
cp .env.example .env
# Edit with your settings
nano credentials/accounts.json
nano .env
3. Set Up Provider
IMAP (Easiest - works with any email)
Edit .env:
IMAP_HOST=imap.gmail.com
IMAP_USER=your@gmail.com
IMAP_PASSWORD=your-app-password
SMTP_HOST=smtp.gmail.com
Edit credentials/accounts.json:
{
"accounts": [
{
"id": "main",
"name": "My Email",
"provider": "imap",
"default": true,
"config": {
"host": "${IMAP_HOST}",
"port": 993,
"user": "${IMAP_USER}",
"password": "${IMAP_PASSWORD}",
"tls": true,
"smtpHost": "${SMTP_HOST}",
"smtpPort": 587,
"smtpSecure": false
}
}
]
}
Gmail (OAuth2)
- Go to Google Cloud Console
- Create project, enable Gmail API
- Create OAuth credentials (Desktop app)
- Download as
credentials/gmail-credentials.json - Run:
npm run auth:gmail
Outlook (OAuth2)
- Go to Azure Portal > App registrations
- New registration > Set redirect URI:
http://localhost:3000/callback - Add API permissions:
Mail.Read,Mail.Send,Mail.ReadWrite,offline_access - Create client secret
- Set env vars and run:
npm run auth:outlook
4. Build & Test
# Build
npm run build
# Test locally
source .env && ACCOUNTS_PATH=./credentials/accounts.json node dist/index.js
# Build Docker
docker build -t mcp-email-server .
# Test Docker
docker run --rm -v "$(pwd)/credentials:/app/credentials:ro" --env-file .env mcp-email-server
5. Add to Docker MCP Gateway
Step 1: Create v3 Catalog File
Create or update ~/.docker/mcp/catalogs/custom.yaml:
version: 3
name: custom
displayName: custom
registry:
email:
description: "Multi-account Email MCP Server supporting IMAP, Gmail, and Outlook"
title: "Email Manager"
type: server
dateAdded: "2025-11-23T00:00:00Z"
image: mcp-email-server:latest
ref: ""
tools:
- name: list_accounts
- name: fetch_unread_emails
- name: search_emails
- name: get_email
- name: mark_as_read
- name: mark_as_unread
- name: send_email
- name: get_all_folders
- name: delete_email
prompts: 0
resources: {}
volumes:
- "/absolute/path/to/mcp-server-mail-agent/credentials:/app/credentials:ro"
env:
- name: ACCOUNTS_PATH
value: "/app/credentials/accounts.json"
- name: IMAP_HOST
value: "{{email.imap_host}}"
- name: IMAP_USER
value: "{{email.imap_user}}"
- name: IMAP_PASSWORD
value: "{{email.imap_password}}"
- name: SMTP_HOST
value: "{{email.smtp_host}}"
metadata:
category: productivity
tags: [email, imap, gmail, outlook]
license: GPL-3.0
owner: local
Important:
- The catalog must be v3 format with
version,name,displayName, andregistrykeys- Use template variables like
{{email.imap_host}}instead of hardcoding credentials- Replace
/absolute/path/to/with your actual project path
Step 2: Add Credentials to Docker MCP Config
Edit ~/.docker/mcp/config.yaml to store your actual credentials:
email:
imap_host: imap.example.com
imap_user: user@example.com
imap_password: your-app-password-here
smtp_host: smtp.example.com
Why this matters: Hardcoding credentials directly in the catalog
envvalues causes authentication failures in the Docker MCP Gateway, even though the same values work withdocker run. Using template variables that referenceconfig.yamlresolves this issue.
Step 3: Import and Enable
# Import the catalog
docker mcp catalog import ~/.docker/mcp/catalogs/custom.yaml
# (the CLI will prompt for a name; enter "custom")
# Enable the email server
docker mcp server enable email
# Verify tools are available
docker mcp tools ls --format list | grep -E "list_accounts|fetch_unread_emails|send_email"
# Test authentication
docker mcp tools call list_accounts
Expected output should include your IMAP account with no authentication errors.
Step 4: Use in Claude Code
Run /mcp in Claude Code to reconnect, or restart Claude Desktop.
Available Tools
| Tool | Description |
|---|---|
list_accounts |
List all connected email accounts |
fetch_unread_emails |
Get unread emails (all accounts or specific) |
search_emails |
Search across all accounts |
get_email |
Get full email content by ID |
mark_as_read |
Mark email as read |
mark_as_unread |
Mark email as unread |
send_email |
Send email from specific account |
get_all_folders |
List folders from all accounts |
delete_email |
Delete/trash an email |
Security
Enforced Security
- Plaintext secrets rejected: The server will refuse to start if
passwordorclientSecretare hardcoded inaccounts.json - Environment variables required: All secrets must use
${VAR_NAME}syntax - Validation on startup: Missing or empty secrets are reported
Best Practices
- Never commit
.envorcredentials/to git (already in.gitignore) - Use app passwords instead of regular passwords for IMAP
- Docker volumes are mounted read-only
- Container runs as non-root user
Common IMAP Servers
| Provider | IMAP Host | SMTP Host |
|---|---|---|
| Gmail | imap.gmail.com | smtp.gmail.com |
| Outlook/Hotmail | outlook.office365.com | smtp.office365.com |
| Yahoo | imap.mail.yahoo.com | smtp.mail.yahoo.com |
| iCloud | imap.mail.me.com | smtp.mail.me.com |
| ProtonMail | 127.0.0.1 (Bridge) | 127.0.0.1 (Bridge) |
Usage Examples
"What email accounts do I have?"
"Show me my unread emails"
"Search for emails from john@example.com"
"Read email ID abc123 from my work account"
"Send an email to jane@example.com about the meeting"
"Mark that email as read"
"Delete the spam email"
Project Structure
mcp-email-server/
├── src/
│ ├── index.ts # MCP server entry
│ ├── types.ts # TypeScript interfaces
│ ├── config.ts # Environment configuration
│ ├── account-manager.ts # Multi-account orchestration
│ ├── providers/
│ │ ├── base.ts # Abstract EmailProvider
│ │ ├── gmail.ts # Gmail API
│ │ ├── outlook.ts # Microsoft Graph
│ │ ├── imap.ts # IMAP/SMTP
│ │ └── index.ts # Provider factory
│ └── auth/
│ ├── gmail-auth.ts # Gmail OAuth setup
│ └── outlook-auth.ts # Outlook OAuth setup
├── credentials/ # Your credentials (gitignored)
├── Dockerfile
├── docker-compose.yml
├── package.json
└── tsconfig.json
Development
# Install dependencies
npm install
# Build
npm run build
# Run locally
npm start
# Auth scripts
npm run auth:gmail
npm run auth:outlook
Troubleshooting
| Issue | Solution |
|---|---|
| "SECURITY ERROR: plaintext secret" | Use ${ENV_VAR} syntax in accounts.json |
| "Environment variable X is not set" | Add the variable to .env and source it |
| "ENOENT: token.json" | Run the auth script for that provider |
| "ENOTFOUND" | Check IMAP/SMTP host settings |
| "Authentication failed" | Verify credentials, use app password for IMAP |
| "Failed to reconnect to MCP_DOCKER" | Restart Docker Desktop, check MCP Gateway is enabled |
| "yaml: unmarshal errors" | Check custom.yaml format - env must be array of {name, value} objects |
| Docker MCP Gateway auth fails (AUTHENTICATIONFAILED) | Don't hardcode credentials in catalog. Use template vars {{email.*}} and put actual values in ~/.docker/mcp/config.yaml |
| Empty accounts list in Gateway | Ensure catalog uses v3 format with template variables, and config.yaml has actual credential values |
Gateway works with docker run but not MCP |
Credentials hardcoded in catalog cause auth failures. Move them to config.yaml and use template variables |
License
GPL-3.0 License - see LICENSE for details.
Author
Augusto Linhares - 18X Labs
Built with the Model Context Protocol
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。