Gmail MCP Server
Gmail MCP 服务器
本项目实现了一个模型上下文协议(MCP)服务器,允许通过 IMAP 和 SMTP 与 Gmail 账户进行交互。它提供了搜索电子邮件、检索内容、管理标签(创建、删除、重命名、应用、移除)以及发送/转发电子邮件的工具。
功能特性
电子邮件搜索: 按日期范围、关键词或原始 Gmail 查询字符串搜索电子邮件。支持搜索特定文件夹(收件箱、已发送)并限制结果数量。利用 Gmail 的
X-GM-RAW扩展实现高效的收件箱搜索(例如,按category:primary过滤)。电子邮件内容检索: 使用序列 ID 获取特定电子邮件的完整内容(标头、正文、附件)。
标签管理(增删改查):
列出所有可用的 Gmail 标签(文件夹)。
创建新的自定义标签。
重命名现有的自定义标签。
删除现有的自定义标签(无法删除系统标签)。
将标签应用于单个电子邮件。
从单个电子邮件中移除标签。
批量操作:
使用序列 ID 同时将标签应用于多封电子邮件。
同时从多封电子邮件中移除标签。
将多封电子邮件移动到特定标签/文件夹。
发送电子邮件: 发送新电子邮件(需要 SMTP 配置)。
转发电子邮件: 转发现有电子邮件,包括附件(需要 SMTP 配置)。
每日邮件计数: 统计指定日期范围内每天收到的电子邮件数量。
Related MCP server: Gmail MCP Server
项目结构
.
├── .gitignore # Specifies intentionally untracked files that Git should ignore
├── .python-version # Specifies Python version (used by pyenv)
├── LICENSE # Project license file
├── pyproject.toml # Python project configuration (dependencies, build system)
├── README.md # This file
├── task_list.md # Tracks development progress
├── uv.lock # Lock file for uv package manager
├── src/
│ └── email_client/
│ ├── __init__.py
│ ├── config.py # Handles loading configuration from environment variables (.env)
│ ├── handlers.py # Implements the logic for handling MCP tool calls
│ ├── imap_client.py # Contains functions for interacting with IMAP server
│ ├── server.py # Main MCP server script using @modelcontextprotocol/sdk
│ ├── smtp_client.py # Contains functions for interacting with SMTP server
│ ├── tool_definitions.py # Defines the available MCP tools and their schemas
│ └── utils.py # Utility functions (e.g., email parsing, date formatting)
└── ... (other potential files like test scripts, helper scripts)设置
克隆仓库(如适用):
git clone https://github.com/david-strejc/gmail-mcp-server.git cd gmail-mcp-server安装依赖: 本项目使用
uv进行包管理。# Ensure uv is installed (e.g., pip install uv) uv venv # Create virtual environment (.venv) uv sync # Install dependencies from pyproject.toml and uv.lock source .venv/bin/activate # Activate the virtual environment(或者,如果不使用
uv,可以创建虚拟环境并在生成requirements.txt后使用pip install -r requirements.txt进行安装。)配置环境变量: 在项目根目录中创建
.env文件,并添加您的 Gmail 凭据和服务器设置:# .env file GMAIL_EMAIL=your_email@gmail.com GMAIL_PASSWORD=your_app_password # Use an App Password if 2FA is enabled GMAIL_IMAP_SERVER=imap.gmail.com GMAIL_SMTP_SERVER=smtp.gmail.com GMAIL_SMTP_PORT=587 # Or 465 for SSL重要提示: 对于 Gmail,如果您已启用两步验证,则必须生成并使用"应用专用密码"。标准密码将无法使用。请参阅 Google 关于应用专用密码的文档。
如果您未使用两步验证,请确保已启用"低安全性应用访问"(通常不建议这样做)。
运行 MCP 服务器
激活虚拟环境并运行服务器脚本:
source .venv/bin/activate
python src/email_client/server.py服务器将启动并通过标准输入/输出监听 MCP 请求。
与 MCP 客户端集成(例如,Cline)
将服务器配置添加到您的 MCP 客户端设置文件中(例如,cline_mcp_settings.json 或 claude_desktop_config.json)。
cline_mcp_settings.json 条目示例:
{
"mcpServers": {
"gmail": {
"command": "/path/to/your/project/gmail-mcp-server/.venv/bin/python",
"args": ["/path/to/your/project/gmail-mcp-server/src/email_client/server.py"],
"env": {}, // Environment variables are loaded from .env by the script
"enabled": true, // Set to true to enable
"autoApprove": [] // Configure auto-approval if desired
}
// ... other servers
}
}将
/path/to/your/project/gmail-mcp-server替换为该项目目录的实际绝对路径。确保
command指向项目虚拟环境中的 python 可执行文件(.venv/bin/python)。
配置并启用后,客户端应能连接到服务器,并且定义的工具将变为可用。
可用工具(摘要)
search-emails:搜索电子邮件。get-email-content:获取完整的电子邮件详情。count-daily-emails:按天统计电子邮件数量。list-labels:列出所有标签/文件夹。create-label:创建新标签。rename-label:重命名现有标签。delete-label:删除标签。apply-label:将标签应用于一封电子邮件。remove-label:从一封电子邮件中移除标签。apply-label-batch:将标签应用于多封电子邮件。remove-label-batch:从多封电子邮件中移除标签。move-email:将单封电子邮件移动到标签。move-email-batch:将多封电子邮件移动到标签。send-email:发送新电子邮件。forward-email:转发现有电子邮件。
有关每个工具的详细输入模式,请参阅 src/email_client/tool_definitions.py。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organiz…
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Connect any mailbox to Claude, ChatGPT & AI: read, send, reply, schedule & search emails.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Gmail through the Gmail API to read, send, and manage emails. Supports multiple Gmail accounts with real-time monitoring and advanced features for email search and attachment handling.17Apache 2.0
- FlicenseNot gradedqualityDmaintenanceEnables interaction with Gmail through the Gmail API with OAuth2 authentication. Supports reading, sending, searching emails, and managing read status through natural language.
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to interact with Gmail accounts through IMAP/SMTP, supporting reading, sending, replying to emails, managing threads, downloading attachments, and searching with Gmail syntax using simple app password authentication.
- FlicenseNot gradedqualityNot gradedmaintenanceEnables interaction with Gmail through the Gmail API, allowing users to list, read, search emails, create and send drafts, and get email summaries through natural language commands with OAuth2 authentication.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/aakashlokhande99/Gmail_MCP_Server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server