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 ライセンス)のパッチ適用フォークです。このフォークは、search_and_trash と batch_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 の同意画面がブラウザで開きます。認証情報は 0600 パーミッション(所有者のみ)で ~/.gmail-mcp/credentials.json に保存されます。

4. Claude Desktop に追加

macOS の ~/Library/Application Support/Claude/claude_desktop_config.json に追加:

{
  "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"]
    }
  }
}

使用例

プロンプト

動作

"6 か月以上前の newsletter@spam.com からのメールをすべてゴミ箱に移動して"

Gmail クエリ構文を使用した search_and_trash

"ドライランして — LinkedIn からゴミ箱に移動されるものを表示して"

dryRun: true の search_and_trash が先に一致をプレビュー

"nextdoor.com からのメールを自動アーカイブするフィルタを作成して"

removeLabelIds: ["INBOX"] を使用した create_filter

"そのマーケティングメールに配信停止リンクがあるか確認して"

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

Related MCP Connectors

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,192 npm
    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.
    174 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    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.
    174 npm
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to manage Gmail accounts through natural language for tasks like sending, reading, searching, and organizing emails. It supports advanced features including draft management, label operations, and batch actions via secure OAuth 2.0 authentication.
    MIT