Email Alert MCP Server
Enables AI agents to read, filter, send emails, and check unread counts via the Model Context Protocol using Gmail SMTP/IMAP.
README
📧 Email Alert MCP Server
An MCP (Model Context Protocol) server that exposes email operations as tools for AI agents. This allows Claude or other LLM-based agents to naturally read, filter, send emails, and check unread counts through the MCP protocol.
🎯 Features
- Read Emails: Fetch recent emails from your inbox
- Filter Emails: Search emails by sender, subject, or unread status
- Send Emails: Compose and send emails through your account
- Unread Count: Check how many unread messages you have
- Works with Gmail: Uses SMTP/IMAP for universal compatibility
🛠️ Prerequisites
- Python 3.10 or higher
- Gmail account with App Password enabled (see setup below)
- Claude Desktop or any MCP-compatible client
📦 Installation
1. Clone or Navigate to the Project
cd "C:\Users\tejas\OneDrive\Desktop\Email MCP server"
2. Create Virtual Environment (if not already created)
python -m venv venv
3. Activate Virtual Environment
Windows:
venv\Scripts\activate
Mac/Linux:
source venv/bin/activate
4. Install Dependencies
pip install -r requirements.txt
🔐 Gmail Setup (App Password)
For security, Gmail requires an App Password instead of your regular password when using SMTP/IMAP.
Steps to Get Gmail App Password:
- Go to your Google Account: https://myaccount.google.com/
- Navigate to Security → 2-Step Verification (enable if not already enabled)
- Scroll down to App passwords
- Click Select app → Choose "Mail"
- Click Select device → Choose "Other" → Name it "MCP Server"
- Click Generate
- Copy the 16-character password (e.g.,
abcd efgh ijkl mnop) - Update your
.envfile with this App Password
Update .env File
Your .env file should look like this:
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-16-char-app-password
IMAP_SERVER=imap.gmail.com
SMTP_SERVER=smtp.gmail.com
IMAP_PORT=993
SMTP_PORT=587
OPENAI_API_KEY=your-openai-api-key (optional)
🚀 Running the Server
Test Locally
python server.py
The server will start and listen for MCP protocol messages via stdin/stdout.
🔧 Connecting to Claude Desktop
To use this MCP server with Claude Desktop, you need to add it to your Claude Desktop configuration.
1. Find Your Claude Config File
Mac:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%\Claude\claude_desktop_config.json
2. Add MCP Server Configuration
Edit the config file and add (see claude_desktop_config.example.json for reference):
{
"mcpServers": {
"email-alert": {
"command": "python",
"args": [
"/absolute/path/to/your/project/server.py"
],
"env": {
"PYTHONPATH": "/absolute/path/to/your/project"
}
}
}
}
Windows Example:
{
"mcpServers": {
"email-alert": {
"command": "C:\\Users\\YourName\\path\\to\\venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\YourName\\path\\to\\Email MCP server\\server.py"
]
}
}
}
Mac/Linux Example:
{
"mcpServers": {
"email-alert": {
"command": "/usr/bin/python3",
"args": [
"/home/username/Email-MCP-server/server.py"
]
}
}
}
Note: Replace paths with your actual project location.
3. Restart Claude Desktop
Close and reopen Claude Desktop to load the new MCP server.
🧪 Testing the Tools
Once connected to Claude Desktop, you can test the email tools with natural language:
Examples:
Check Unread Emails:
"How many unread emails do I have?"
Read Recent Emails:
"Show me my 5 most recent emails"
Filter by Sender:
"Show me all emails from john@example.com"
Search by Subject:
"Find emails with 'meeting' in the subject"
Send an Email:
"Send an email to sangeeta@example.com with subject 'Meeting Reminder' and tell her about the 4 PM meeting"
🔧 Available MCP Tools
1. read_emails
Read recent emails from inbox or specified folder.
Parameters:
count(number, optional): Number of emails to retrieve (default: 10)folder(string, optional): Email folder (default: "INBOX")
2. filter_emails
Search and filter emails by criteria.
Parameters:
sender(string, optional): Filter by sender email addresssubject(string, optional): Filter by subject (substring match)is_unread(boolean, optional): Filter by unread statusfolder(string, optional): Email folder (default: "INBOX")
3. send_email
Send an email to a recipient.
Parameters:
to(string, required): Recipient email addresssubject(string, required): Email subject linebody(string, required): Email body contentcc(string, optional): CC recipient email address
4. get_unread_count
Get count of unread emails.
Parameters:
folder(string, optional): Email folder (default: "INBOX")
🏗️ Project Structure
Email MCP server/
├── server.py # Main MCP server
├── email_client.py # Email operations (SMTP/IMAP)
├── requirements.txt # Python dependencies
├── .env # Environment variables (NOT in git)
├── .env.example # Example environment file
├── .gitignore # Git ignore rules
└── README.md # This file
🔒 Security Notes
⚠️ Important:
- Never commit
.envfile - It contains sensitive credentials - Use App Passwords - Never use your main Gmail password
- Restrict Access - Keep your MCP server local and trusted
- Monitor Usage - Review sent emails periodically
📤 Pushing to GitHub
✅ Safe to Push:
server.py- Your MCP server codeemail_client.py- Email operationstest_email.py- Testing scriptrequirements.txt- Dependencies listREADME.md- Documentation.env.example- Template (NO real credentials)claude_desktop_config.example.json- Config template.gitignore- Git ignore rules
❌ NEVER Push:
.env- Contains your email password! (Auto-ignored)claude_desktop_config.json- Has your specific paths (Auto-ignored)venv/- Virtual environment folder (Auto-ignored)__pycache__/- Python cache (Auto-ignored)
The .gitignore file is already configured to protect sensitive files.
🐛 Troubleshooting
"Authentication failed" Error
- Make sure you're using a Gmail App Password, not your regular password
- Verify 2-Step Verification is enabled on your Google account
- Check that
EMAIL_USERandEMAIL_PASSin.envare correct
"Connection refused" Error
- Check your internet connection
- Verify firewall isn't blocking SMTP (port 587) or IMAP (port 993)
- Ensure Gmail hasn't flagged your account for suspicious activity
"MCP server not showing in Claude Desktop"
- Verify the path in
claude_desktop_config.jsonis correct - Check that Python is in your system PATH
- Restart Claude Desktop after config changes
- Check Claude Desktop logs for errors
📚 Learn More
📝 License
MIT License - Feel free to use and modify!
🤝 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
Built with ❤️ using 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 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。