Gmail MCP 服务器是一个功能强大且灵活的 Gmail 集成服务器,基于 MCP(消息控制协议)框架构建。它提供了与 Gmail API 交互的强大接口,支持邮件的读取、发送和管理,能极大地提升邮件处理效率。
使用 Smithery 可自动安装 Gmail 集成服务器:
npx -y @smithery/cli install @Quantum-369/Gmail-mcp-server --client claude
git clone
cd gmail-mcp-server
python -m venv venv
# Windows 系统
venv\Scripts\activate
# Unix/MacOS 系统
source venv/bin/activate
pip install .
运行 Gmail MCP 服务器之前,请确保以下条件已满足:
client_secret.json 并放在项目根目录中gmail_token_creator.py 中设置电子邮件标识符:email_identifier = 'your.email@gmail.com' # 根据需要修改
python gmail_token_creator.py
gmail_server.py:主要 MCP 服务器实现gmail_api.py:Gmail API 交互函数google_apis.py:Google API 认证工具read_emails.py:邮件读取功能search_emails.py:邮件搜索功能send_emails.py:邮件发送功能python gmail_server.py
await send_gmail(
email_identifier="your.email@gmail.com",
to="recipient@example.com",
subject="Test Subject",
body="Email body content",
attachment_paths=["path/to/attachment"]
)
async def process_email(email):
# 处理找到的邮件
pass
await search_emails(
email_identifier="your.email@gmail.com",
query="subject:important",
callback=process_email
)
async def download_attachment(attachment):
# 处理下载的附件
pass
await get_attachments(
email_identifier="your.email@gmail.com",
message_id="message-id-12345",
attachments_callback=download_attachment
)
client_secret.json 文件的安全性,避免泄露。通过以上步骤,您可以轻松设置并使用 Gmail MCP 服务器来管理您的邮件和附件。