Skip to main content
Glama
adityai4

gmail-cleanup-mcp

by adityai4

Gmail Cleanup MCP Server

一个专注于 Gmail 收件箱清理的 Model Context Protocol 服务器 — 将邮件移到回收站、管理过滤器、提取退订链接。旨在补充 Anthropic 内置的 Gmail 连接器,后者负责读取、搜索、草稿和发送。

这是 dcerniglia/gmail-cleanup-mcp 的修补分支(MIT 许可)。该分支修复了一个 bug:search_and_trashbatch_trash_emails 过去会静默丢弃失败而不重试 — 同时发出 50 个并发删除请求可能会触发 Gmail 的速率限制,并在不显示任何错误的情况下丢弃约一半批次。现在这两个工具都会以更小的批次处理、退避、自动重试,并针对每条失败消息报告实际错误。

工具

工具

描述

trash_email

将单个邮件移到回收站(30 天安全网)

batch_trash_emails

按邮件 ID 将最多 500 封邮件移到回收站,每批处理 50 封

search_and_trash

按 Gmail 查询条件查找邮件并将其移到回收站 — 支持 试运行 预览

create_filter

创建过滤器以自动归档、自动打标签、自动删除或转发

list_filters

列出所有现有 Gmail 过滤器及其条件和操作

delete_filter

按 ID 移除 Gmail 过滤器

get_unsubscribe_info

从邮件中提取 List-Unsubscribe 标头

Related MCP server: Gmail AutoAuth MCP Server

前置要求

  • Node.js 18+

  • 一个启用了 Gmail API 的 Google Cloud 项目

  • OAuth 2.0 凭据(桌面应用类型)

设置

1. Google Cloud OAuth

已经有来自其他 Gmail MCP 服务器的 ~/.gmail-mcp/gcp-oauth.keys.json 跳到第 2 步 — 此服务器使用相同的凭据位置。

  1. 转到 Google Cloud Console

  2. 创建项目(或复用现有项目)并启用 Gmail API

  3. 转到 凭据创建凭据OAuth 客户端 ID

  4. 选择 桌面应用,下载 JSON

  5. 将其保存为 ~/.gmail-mcp/gcp-oauth.keys.json(或将 gcp-oauth.keys.json 放在项目目录中 — 首次运行时会自动复制)

2. 安装与构建

git clone https://github.com/davidcerniglia/gmail-cleanup-mcp.git
cd gmail-cleanup-mcp
npm install
npm run build

3. 身份验证

npm run auth

这会在浏览器中打开 Google OAuth 授权页面。凭据将保存到 ~/.gmail-mcp/credentials.json,权限为 0600(仅所有者)。

4. 添加到 Claude Desktop

添加到 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS):

{
  "mcpServers": {
    "gmail-cleanup": {
      "command": "node",
      "args": ["/absolute/path/to/gmail-cleanup-mcp/dist/index.js"]
    }
  }
}

对于 Claude Code,则添加到 .claude/settings.json

{
  "mcpServers": {
    "gmail-cleanup": {
      "command": "node",
      "args": ["/absolute/path/to/gmail-cleanup-mcp/dist/index.js"]
    }
  }
}

使用示例

提示

实际行为

"将所有来自 newsletter@spam.com 且超过 6 个月的邮件移到回收站"

使用 Gmail 查询语法的 search_and_trash

"做一次试运行 — 显示 LinkedIn 中会被移到回收站的邮件"

search_and_trash 配合 dryRun: true 先预览匹配结果

"创建一个过滤器,自动归档来自 nextdoor.com 的邮件"

create_filter 配合 removeLabelIds: ["INBOX"]

"检查那封营销邮件是否有退订链接"

get_unsubscribe_info 提取 List-Unsubscribe 标头

与 Claude 内置 Gmail 的配合方式

内置 Gmail 连接器

本服务器

搜索与读取

草稿与发送

将邮件移到回收站

批量清理

是(每次最多 500 封)

过滤器管理

退订信息提取

安全性

  • 最小权限范围gmail.modify + gmail.settings.basic — 执行回收站和过滤器操作所需的最小权限

  • 移到回收站,而非永久删除:所有删除操作都使用 Gmail 的回收站(30 天恢复期),绝不会永久删除

  • 试运行模式search_and_trash 可以在执行前预览匹配结果

  • 严格的文件权限:凭据以 0600 权限存储(仅所有者可读写)

  • 不处理附件:零路径遍历风险

  • 不访问任何文件系统,仅 ~/.gmail-mcp/ 中的凭据存储除外

环境变量

变量

默认值

描述

GMAIL_OAUTH_PATH

~/.gmail-mcp/gcp-oauth.keys.json

OAuth 客户端密钥的路径

GMAIL_CREDENTIALS_PATH

~/.gmail-mcp/credentials.json

已存储凭据的路径

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    C
    quality
    D
    maintenance
    Enables comprehensive Gmail management through the Gmail API, including sending/receiving emails, organizing labels and threads, managing drafts, and configuring account settings with secure OAuth2 authentication.
    64
    1,398
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to manage Gmail through natural language interactions, supporting email operations (send, read, search, draft), comprehensive attachment handling (send, receive, download), label management, filters, and batch operations with automatic OAuth2 authentication.
    192
    MIT
  • A
    license
    Not graded
    quality
    F
    maintenance
    Provides comprehensive Gmail integration with 25+ tools for intelligent email management, including AI-powered categorization, advanced search and filtering, automated archiving and cleanup, analytics, and secure OAuth2 authentication.
    192
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to manage Gmail through natural language, supporting operations like sending, searching, and reading emails. It includes comprehensive label management, batch processing, and a streamlined OAuth2 auto-authentication flow.
    MIT

View all related MCP servers

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…

  • AI email automation, follow-ups, training, previews, and mailbox troubleshooting.

View all MCP Connectors

Latest Blog Posts

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/adityai4/gmail-cleanup-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server