跳过安装。2 分钟内即可运行。
在 cloud.anythingmcp.com 开始免费试用,一键添加 Gmail,然后将你的 AI 客户端(Claude、ChatGPT、Copilot 或 Cursor)指向生成的 MCP 端点。无需 Docker,无需 git clone,无需任何工程经验。
摘要
让你的 AI 在 Gmail 中工作:用 Gmail 自己的搜索语法搜索邮箱,读取邮件和会话,把邮件标为已读、归档、加星标或加标签,撰写、回复和发送邮件,或者保存草稿供你先检查。支持个人 Gmail 和 Google Workspace,使用你自己的 Google OAuth 客户端。
试试这样问
Gmail 的示例提示
点击任意提示即可复制,然后粘贴到 Claude、ChatGPT、Cursor、Gemini、Copilot 或 OpenClaw 中,在该连接器上运行。
Claude 是 AI,可能会出错。请核对回答。
💡 无需安装? 直接使用 cloud.anythingmcp.com。 登录、点击 Connectors → Gmail、粘贴凭证、生成 MCP API key,即可完成。无 Docker、无
git clone、无本地服务器。
Gmail
让你的 AI 在 Gmail 中工作:用 Gmail 自己的搜索语法搜索邮箱,读取邮件和会话,把邮件标为已读、归档、加星标或加标签,撰写、回复和发送邮件,或者保存草稿供你先检查。支持个人 Gmail 和 Google Workspace,使用你自己的 Google OAuth 客户端。
设置
- 打开 console.cloud.google.com,选择或创建一个项目,然后进入 APIs & Services → Library 启用 Gmail API。
- 打开 APIs & Services → OAuth consent screen。如果邮箱在 Google Workspace 中,选择 Internal(最简单),否则选择 External。选择 External 时,请把发布状态设为 In production:应用处于 Testing 状态时,Google 会在 7 天后撤销它的刷新令牌,连接器每周都会停止工作。
- 打开 APIs & Services → Credentials → Create credentials → OAuth client ID,应用类型选择 Web application,并添加已授权的重定向 URI
https://cloud.anythingmcp.com/api/mcp-oauth/callback。如果你自行托管 AnythingMCP,请改填https://your-anythingmcp-host/api/mcp-oauth/callback。 - 把客户端 ID 填入
GOOGLE_CLIENT_ID,把客户端密钥填入GOOGLE_CLIENT_SECRET,然后安装连接器。 - 在连接器页面点击 Authorize with Provider,用 AI 要使用的 Gmail 账户登录。刷新令牌会加密存储,访问令牌会自动续期。
- 让 AI 调用
gmail_get_profile:它会返回连接器所用的邮箱地址,以及邮箱中的邮件数和会话数。
一个 Google 客户端服务所有 Google 连接器:同一个 Cloud 项目和 OAuth 客户端可以服务所有 Google 连接器:Gmail、Google Calendar、Google Drive、Google Sheets、Google Docs、Google Tasks、Search Console、Analytics 和 Ads。在该项目中启用每个 API,复用同一个客户端 ID 和密钥,并为每个连接器各授权一次。每个连接器只请求它自己需要的权限。
Google 验证:Google 把这个连接器使用的 Gmail 权限(gmail.modify,只读设置时为 gmail.readonly)列为受限(restricted)权限。Internal 应用只供拥有该 Cloud 项目的 Workspace 组织内的账户使用,无需验证,对公司来说这是最直接的方式。供其他人使用的 External 应用会显示“Google hasn't verified this app”警告,并且在通过 Google 验证之前最多只能有 100 个用户;对于受限权限,验证还包括安全评估。如果只是单个个人 Gmail 账户,只有你自己使用的、处于 In production 状态的 External 应用在跳过警告后即可使用。
权限:连接器请求 https://www.googleapis.com/auth/gmail.modify:读取邮件、更改标签(标为已读、归档、加星标)、创建草稿和发送邮件。它以授权它的 Google 账户身份工作,看到的内容与该账户完全相同。它无法永久删除任何内容。
哪些工具会真正发出邮件:gmail_send_message(新邮件)、gmail_reply(会话中的回复)和 gmail_send_draft(按原样发送现有草稿)会立即从已登录的地址发送,发送后无法撤回。gmail_create_draft 只保存草稿(也可以是会话中的回复草稿),由你在 Gmail 中检查并发送;如果你没有明确要求发送,连接器会让 AI 优先保存草稿。一封邮件最多发给 500 个收件人。AI 读取的邮件中可能含有要求它发送内容的文字:如果 AI 只需要准备邮件,请停用 gmail_send_message、gmail_reply 和 gmail_send_draft,由你自己发送草稿。
只读设置:在连接器的 OAuth 设置中把 scope 改为 https://www.googleapis.com/auth/gmail.readonly,重新授权,并停用 gmail_modify_message_labels、gmail_modify_thread_labels、gmail_create_draft、gmail_send_draft、gmail_send_message 和 gmail_reply。
读取和整理邮件:搜索使用与 Gmail 搜索框相同的语法,例如 from:[email protected] is:unread newer_than:7d 或 has:attachment。邮件和会话以纯文本返回(只有 HTML 的邮件会被转换成文本);很长的正文在 20,000 个字符处截断,整个会话则在 100,000 个字符处截断。附件会列出名称、类型和大小,但不会下载。标为已读、归档、加星标和按标签归类,都是对单封邮件或整个会话更改标签。
速率限制:Gmail 允许每个用户每分钟 6,000 个配额单位。一次搜索花费 5 个,读取一封邮件 20 个,读取一个会话 40 个,发送一封邮件或草稿 100 个。超出限制时 Gmail 返回 429(或 403 userRateLimitExceeded):请等一分钟后重试。
常见错误:401 表示授权已过期或被撤销(同意屏幕处于 Testing 状态时,7 天后必然发生):请再次点击 Authorize with Provider。403 accessNotConfigured 表示 Cloud 项目中没有启用 Gmail API。403 insufficientPermissions 或 ACCESS_TOKEN_SCOPE_INSUFFICIENT 表示 scope 不允许该调用,例如在只读设置下更改标签。404 表示此邮箱中不存在该 ID;草稿 ID(以 r- 开头)不是邮件 ID。400 invalidArgument 通常表示标签 ID 不存在:自建标签的 ID 形如 Label_12,可以通过 gmail_list_labels 获取。
连接器不发送或下载附件,不连同原始附件转发邮件,不把邮件移到回收站,也不删除邮件,并且不处理过滤器、设置、发件别名或其他人的邮箱。
前提条件: GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
本地安装连接器
curl -fsSL https://raw.githubusercontent.com/HelpCode-ai/anythingmcp/main/docker-compose.quickstart.yml -o docker-compose.yml
printf 'JWT_SECRET=%s\nENCRYPTION_KEY=%s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 32)" > .env
docker compose up -d
打开 http://localhost:3000/connectors/store,选择 Gmail 并填入前提条件中列出的环境变量。
可用工具
| Tool | What it does |
|---|---|
gmail_get_profile | Return the Gmail account the connector works with: its email address, the total number of messages and threads in the mailbox, and the… |
gmail_list_messages | Search or list messages in the mailbox with Gmail search syntax and optional label filters |
gmail_get_message | Get one message by id, decoded: sender, recipients, subject, date, Message-ID and References, labels and the body as plain text (HTML-only… |
gmail_list_threads | Search or list conversations (threads) with Gmail search syntax and optional label filters |
gmail_get_thread | Get one conversation by thread id with all its messages in order, each decoded like gmail_get_message: sender, recipients, subject, date… |
gmail_list_labels | List all labels of the mailbox, system labels (INBOX, UNREAD, STARRED, SENT, SPAM, TRASH, categories) and the user's own, with id, name and… |
gmail_get_label | Get one label by id with its message and thread counts, total and unread, plus its visibility settings and colour |
gmail_modify_message_labels | Add and remove labels on one message: mark it read (remove UNREAD) or unread (add UNREAD), archive it (remove INBOX), star it (add STARRED)… |
gmail_modify_thread_labels | Add and remove labels on every message of a conversation at once, e.g. archive a whole thread (remove INBOX) or mark it read (remove UNREAD) |
gmail_list_drafts | List the drafts in the mailbox, optionally filtered with Gmail search syntax |
gmail_get_draft | Get one draft by draft id with its message decoded: recipients, subject and the body as plain text, to check it before it is sent with… |
gmail_create_draft | Save a new email as a draft in the mailbox without sending it, so the user can review it in Gmail; send it later with gmail_send_draft |
gmail_send_draft | Send an existing draft to its recipients exactly as it is written |
gmail_send_message | Write and send a new email from the signed-in Gmail account right away |
gmail_reply | Send a reply inside an existing conversation |
示例提示
- “过去 3 天里哪些未读邮件还需要我回复?每封用一句话概括。”
- “找到 [email protected] 关于报价的最新一封邮件,写一份接受新日期的回复草稿。先不要发送,我会在 Gmail 里检查。”
- “把收件箱里一周以前的所有新闻通讯标为已读并归档,然后列出你归档了哪些。”
- “列出 10 月 1 日以来所有看起来像发票的带附件邮件,包括发件人、日期、主题和文件名。”
下一步
这份指南对你有帮助吗?