gmail-mcp
gmail-mcp v1.0.0
用于 Gmail 的统一多账户 Google OAuth2 MCP 服务器。 跨多个 Google 账户无缝搜索、读取、撰写、发送、创建草稿和整理邮件。
功能(4 个统一工具)
gmail_search:使用官方 Gmail 搜索语法检索邮件(is:unread、from:boss@corp.com、subject:invoice、newer_than:2d、has:attachment)gmail_read:读取完整的邮件内容和元数据(主题、发件、正文文本、HTML、抄送、密送、标签、附件列表)gmail_send:发送邮件或创建草稿(支持 HTML、抄送、密送、线程回复和文件附件)gmail_manage:标签管理、归档、垃圾邮件处理、已读/未读切换、永久删除以及多账户清单
Related MCP server: Moist
多账户架构
单个 Google Cloud OAuth 客户端(credentials.json)即可认证多个 Gmail 账户。
令牌按账户存储在 ~/.secrets/gmail/tokens/<account_name>.json 中。
1. 设置 Google OAuth 凭据(一次性)
在 Google Cloud Console 中创建项目。
启用 Gmail API。
创建 OAuth 2.0 客户端 ID(桌面应用)。
下载客户端密钥 JSON 文件,并将其保存为
~/.secrets/gmail/credentials.json(或设置GMAIL_CREDENTIALS_JSON)。
2. 认证账户
为每个账户运行交互式授权 CLI:
gmail-auth default # Authenticates primary account
gmail-auth work # Authenticates secondary work account
gmail-auth client_x # Authenticates any additional account列出所有已认证的账户:
gmail-auth --list在 MCP 客户端中安装(Claude Desktop、OpenCode、Cursor、Windsurf)
选项 1:通过 uvx 即时安装(推荐)
{
"mcpServers": {
"gmail": {
"command": "uvx",
"args": ["--from", "git+https://github.com/Steph-ux/gmail-mcp.git", "gmail-mcp"]
}
}
}选项 2:通过 pip install 安装
pip install git+https://github.com/Steph-ux/gmail-mcp.git然后在你的 MCP 配置中:
{
"mcpServers": {
"gmail": {
"command": "gmail-mcp"
}
}
}选项 3:本地克隆(开发)
{
"mcpServers": {
"gmail": {
"command": "python",
"args": ["D:\\Steph\\script\\gmail-mcp\\server.py"]
}
}
}使用示例
1. 搜索邮件
# Search in default account:
gmail_search(query='is:unread from:github')
# Search in work account:
gmail_search(account='work', query='subject:invoice newer_than:7d')2. 读取邮件
gmail_read(account='work', message_id='18f2a9b4c10d')3. 发送邮件或创建草稿
# Send direct email:
gmail_send(
account='default',
to='colleague@example.com',
subject='Project Update',
body_text='Here is the latest status...',
body_html='<h1>Project Update</h1><p>Here is the latest status...</p>'
)
# Create a draft:
gmail_send(
account='work',
to='client@example.com',
subject='Proposal draft',
body_text='Please review the proposal.',
draft=True
)4. 整理与管理
# Archive email:
gmail_manage(account='work', action='archive', message_id='18f2a9b4c10d')
# Mark as unread:
gmail_manage(account='default', action='mark_unread', message_id='18f2a9b4c10d')
# Move to trash:
gmail_manage(account='default', action='trash', message_id='18f2a9b4c10d')
# List active accounts:
gmail_manage(action='list_accounts')测试
pytest tests许可证
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
A MCP server for Gmail that lets you search, read, and draft emails and replies.
Email inboxes for AI agents: send, receive, reply, search, and manage threaded email over MCP.
Hosted email MCP for your own Gmail, Outlook.com, Microsoft 365, iCloud or IMAP inbox: read, search, draft, reply in thread, forward and file mail. It moves or flags up to 500 messages in one call, and a send leaves exactly one copy in Sent. A calendar is a separate connection, and connecting one adds diary and scheduling tools.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Gmail through the MCP protocol, supporting sending, reading, searching, replying, forwarding, managing drafts and labels, and saving attachments.12 npm3MIT
- AlicenseNot gradedqualityDmaintenanceEnables Gmail operations such as reading, sending, searching, and managing emails, threads, labels, and drafts via MCP tools.1MIT
- FlicenseNot gradedqualityDmaintenanceEnables searching, reading, and drafting emails across multiple Gmail accounts through a single MCP server.-
- FlicenseNot gradedqualityDmaintenanceEnables reading, searching, sending, and drafting Gmail emails via MCP tools, with support for multiple accounts and background notifications.-