gmail-mcp
gmail-mcp
MCP クライアント向けの Gmail コネクタ。1 つのサーバーで、OAuth リフレッシュトークン経由の複数の Gmail アカウントを扱えます。実際の MIME を送信します(ファイルパス添付、ライブ署名、送信後の証明)。モデルにメガバイト単位の base64 を流し込むことなく、メールの読み取りと整理ができます。
Google がホストする Gmail MCP のラッパーではありません。ホスト上で RFC822 を組み立て、gmail.googleapis.com に直接通信します。
Features
マルチアカウント OAuth —
accounts_addでメールボックスを追加。トークンはローカルに保存(モード 0600)送信 / 返信 / 転送 — サーバーが MIME を構築。送信元は outbox のファイルパスのみ、25 MB 上限、冪等性キー、成功時の証明
読み取り / 整理 — 検索(スレッド + ページネーション)、スレッド / メッセージ取得、ラベル、アーカイブ / ゴミ箱、下書き
添付ファイル —
~/Outbox(設定可能)から送信し、~/Inbox(設定可能)へダウンロードデュアルトランスポート — ローカル実行環境向けの stdio。リモートクライアント向けにゲートウェイ越しの Streamable HTTP
Related MCP server: Gmail MCP Server
Requirements
Python 3.12+(開発は pyenv 経由で 3.13)
Google Cloud の Desktop OAuth クライアント(クライアント ID + シークレット)
同梱の LaunchAgent スクリプト(HTTP サービス)には macOS。手動実行は Linux でも動作
Quick start
git clone https://github.com/iXanadu/gmcp.git
cd gmcp
# Python 3.12+ (example with pyenv)
pyenv virtualenv 3.13 gmail-mcp-3.13
pyenv local gmail-mcp-3.13
pip install -e '.[dev]'
# Config (see examples/)
cp examples/.env.example .env
cp examples/.keys.example .keys
chmod 600 .keys
# Sanity check
gmail-doctorHTTP トランスポートを実行する前に、.keys に Google OAuth の認証情報と HTTP ベアラートークンを記入してください。
Google Cloud Console(一度だけ必要)
Desktop OAuth クライアントが必要です。サービスアカウントやドメイン全体の委任ではありません。
Step | Where | What |
1 | APIs & Services → Library | Gmail API を有効にする |
2 | OAuth consent screen | 個人利用なら External で問題ありません。アプリが Testing モードの間は、Google アカウントを テストユーザー に追加してください。 |
3 | Credentials → Create | OAuth クライアント ID → デスクトップアプリ |
4 | Client settings | リダイレクト URI |
5 |
| Client ID と Client secret を |
最初の accounts_add の際、Google が同意を求めます。スコープはサーバー側で固定されています。メールの読み取り / 送信 / 整理に加え、send-as 署名の読み取り(キャッシュなし)です。
ユーザー名 / パスワード、アプリパスワード、リフレッシュトークンの貼り付けをチャットで行う必要はありません。
メールボックスを接続する(accounts_add)
accounts_add は Google の同意のためにブラウザを開きます。これは stdio トランスポート(gmail-mcp)でのみ動作し、HTTP では実行できません。
gmail-mcp # stdio — required for accounts_add and accounts_removeMCP クライアントから accounts_add を呼び出してください。同意が完了すると、サーバーは Google が返した Gmail アドレスを記録します。このアドレスが、他のすべてのツールの account キーになります。
トークンは ~/.config/gmail-mcp/tokens/(モード 0600)に保存されます。必要に応じて、同じサーバーを実行する他のホストにこのディレクトリをコピーしてください。
ヘッドレスサーバー(ローカルにブラウザがない場合)
OAuth コールバックは http://127.0.0.1:8767/oauth/callback です。ディスプレイのないマシンでも、Google のログインページ用にブラウザがどこか必要です。よくある 2 つのパターンは次のとおりです。
A — SSH ポートフォワード(あなたのラップトップで同意)
ヘッドレスホストで stdio MCP / accounts_add を起動します。ラップトップから:
ssh -L 8767:127.0.0.1:8767 user@headless-hostサーバーが出力する認可 URL を開きます(トンネルを確立した状態で、MCP クライアント経由で accounts_add をトリガーしても構いません)。コールバックはトンネル経由でヘッドレスホストの 127.0.0.1:8767 に到達します。
B — デスクトップで同意し、トークンをコピー
ブラウザと同一の .env / .keys を持つ Mac または PC で、accounts_add を一度実行してください。同意後、~/.config/gmail-mcp/tokens/ を本番ホストにコピーします(同じパス、モード 0600)。Google がリフレッシュトークンを失効させない限り、再同意は不要です。
デプロイ構成
一般的な本番環境の分割:
┌─────────────────────┐ ┌──────────────────────────┐
│ Operator machine │ │ MCP server (Linux/macOS) │
│ (browser for OAuth)│ │ gmail-mcp-http │
│ accounts_add │ copy │ 127.0.0.1:8879 │
│ token files ───────┼────────►│ + .env / .keys │
└─────────────────────┘ tokens └───────────┬──────────────┘
│
Cloudflare / gateway / TLS
│
Hand / remote MCP clientMCP HTTP のために運用者のラップトップをパブリックインターネットに公開しないでください。HTTP はサーバー上のループバック(
127.0.0.1:8879)にバインドされます。リバースプロキシが TLS を終端し、そのポートに転送します。OAuth はブラウザが存在する場所(運用者のマシンまたは SSH トンネル)で行われます。トークンの JSON ファイルはサーバーにコピーされます。
ゲートウェイは、OAuth ワークステーションではなく、あなたが管理するサーバーのホスト名(例:
mcp.example.com)を指します。長いランダムな
GMAIL_MCP_HTTP_BEARER_TOKENを生成してください。ゲートウェイはこれをAuthorization: Bearer …として提示します。
デプロイ後は、gmail-doctor、./scripts/start.sh(macOS LaunchAgent)、または独自の systemd ユニットを実行し、その後 HTTP 経由で accounts_list を呼び出してトークンを確認します。
設定
機密性の低い設定は .env に、シークレットは .keys に置きます(値を入れた状態でどちらもコミットしないでください)。examples/.env.example と examples/.keys.example を参照してください。
Variable | File | Purpose |
|
| ログ / ステータス用のラベル |
|
| サーバーのログレベル |
|
| HTTP バインドアドレス(デフォルト |
|
| HTTP ポート(デフォルト |
|
| 送信添付ファイルのパスのルート |
|
|
|
|
| OAuth トークンの保存ディレクトリ |
|
| OAuth ループバックコールバック |
|
| Google OAuth クライアント ID |
|
| Google OAuth クライアントシークレット |
|
| HTTP トランスポート用のベアラートークン |
設定を変更したら gmail-doctor を実行してください。
トランスポート
stdio(ローカル)
gmail-mcpaccounts_add と accounts_remove を含むすべてのツールを登録します。
Cursor / Claude Code の MCP 設定に、venv の gmail-mcp バイナリと、cwd をリポジトリに設定して組み込みます(これにより .env / .keys が読み込まれます)。
Streamable HTTP(ゲートウェイ)
gmail-mcp-httpデフォルトで 127.0.0.1:8879 にバインドします。Authorization: Bearer <GMAIL_MCP_HTTP_BEARER_TOKEN> が必要です。有効なトークンのないリクエストは 401 になります。
手動許可リスト(HTTP のみ): 読み取り / 整理ツールに加え、send、reply、forward、draft_create、draft_send、accounts_list、gmail_status。アカウント管理は stdio のままです。
macOS サービス(ユーザー LaunchAgent)
./scripts/start.sh # install plist → ~/Library/LaunchAgents, load
./scripts/stop.sh
./scripts/restart.shチェックアウト先や pyenv の名前が異なる場合は、launchd/com.gmail-mcp.plist のパスを編集してください。ログは logs/ に出力されます。
Linux では、同じループバックバインドで gmail-mcp-http を systemd の下で実行してください。上記のデプロイ構成を参照してください。
ツール
Tool | Notes |
| バージョンと設定の概要 |
| 接続済みアドレスとトークンの健全性 |
| OAuth 同意(stdio のみ) |
| トークンの失効と破棄(stdio のみ) |
| Gmail クエリ。スレッドを返します |
|
|
| ダウンロードルート配下に書き込む |
| パスのみ。JSON 内の |
| send と同じ添付 / 証明ルール |
| ユーザー + システムラベル |
| カンマ区切りの名前または ID |
| スレッド単位 |
accounts_list、accounts_add、gmail_status を除くすべてのツールは、account 引数(Gmail アドレス)を必要とします。
送信ルール(概要)
添付ファイル:
{ "path": "/absolute/or/under/outbox/file.pdf" }— インライン base64 はなしライブの Gmail 署名が送信時に追加されます(キャッシュなし)
署名の後に任意の
footer証明を返します: サイズ、href、
okfalse → ツールエラー(例: 切り詰められた添付ファイル、google.com/urlの書き換え)
テスト
pytest tests/ -vモック化した Gmail HTTP を使用します。実際のメールボックスは不要です。
仕様
製品要件: docs/specs/gmail-mcp-spec.md
ライセンス
Apache-2.0
Available Tools
23 toolsaccounts_addA
Connect a Gmail account via local loopback OAuth (stdio only).
Inputs: no named parameters. Returns: result
accounts_auth_startA
Start Google OAuth for a mailbox over HTTP. Returns auth_url for a human to open; consent completes via the public /oauth/callback and the account appears in accounts_list.
Inputs: no named parameters. Returns: result
accounts_listA
List connected Gmail addresses and whether each refresh token still works.
Inputs: no named parameters. Returns: result
accounts_removeA
Remove a connected Gmail account and revoke its token at Google.
Inputs: account (required). Returns: result
archiveB
Remove INBOX from a thread.
Inputs: account (required), thread_id (required). Returns: result
draft_createC
Create a draft with the same MIME rules as send (from_identity as in send).
Inputs: to (required), account (required), subject (required), cc, +6 more. Returns: result
draft_sendB
Send a draft with post-send proof.
Inputs: account (required), draft_id (required), idempotency_key (required). Returns: result
forwardC
Forward a message on-thread. Same attachment and proof rules as send.
Inputs: to (required), account (required), message_id (required), idempotency_key (required), +6 more. Returns: result
get_attachmentA
Write an attachment under download_root. output_path may be a bare filename (lands in download_root) or an absolute path under it. Returns path and size.
Inputs: account (required), message_id (required), output_path (required), attachment_id (required). Returns: result
get_messageA
Get one message. format=metadata is headers+snippet only (cheap); plain adds the text body; full adds HTML and attachment metadata.
Inputs: account (required), message_id (required), format. Returns: result
get_threadB
Get messages on a thread. format=metadata is headers+snippet only (cheap); plain adds the text body; full adds HTML and attachment metadata.
Inputs: account (required), thread_id (required), format. Returns: result
gmail_statusA
Report server version and configuration (no Gmail API calls).
Inputs: no named parameters. Returns: result
identities_listA
Verified send-as identities for an account. Only these may be used as from_identity.
Inputs: account (required). Returns: result
labelA
Add labels to a thread (comma-separated names or ids).
Inputs: labels (required), account (required), thread_id (required). Returns: result
labels_createC
Create a user label.
Inputs: name (required), account (required). Returns: result
labels_listA
List system and user labels for an account.
Inputs: account (required). Returns: result
messages_listA
List messages (not threads) with headers only — no bodies. Use for routing sweeps: originalTo is the real recipient behind a catch-all; authResults carries dkim/dmarc. Fetch bodies afterwards with get_message only where needed.
Inputs: query (required), account (required), page_token, max_results. Returns: result
replyC
Reply on a thread. Same attachment and proof rules as send.
Inputs: account (required), message_id (required), idempotency_key (required), body, +5 more. Returns: result
searchC
Search Gmail threads using Gmail query syntax.
Inputs: query (required), account (required), page_token, max_results. Returns: result
sendB
Send new mail. Attachments are outbox file paths only. Returns proof payload.
from_identity: optional verified send-as address (see identities_list). Sets From with its display name and Reply-To. Empty = the account address itself.
Inputs: to (required), account (required), subject (required), idempotency_key (required), +6 more. Returns: result
trashC
Move a thread to trash.
Inputs: account (required), thread_id (required). Returns: result
unlabelA
Remove labels from a thread (comma-separated names or ids).
Inputs: labels (required), account (required), thread_id (required). Returns: result
untrashB
Restore a thread from trash.
Inputs: account (required), thread_id (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 23 tools
Most tools target clearly distinct actions or resources, such as send vs reply vs forward or get_thread vs get_message. A few boundaries are close, notably accounts_add vs accounts_auth_start and get_message vs get_thread, but the descriptions are sufficient to avoid serious misselection.
The naming style is mixed: some tools use resource_action (accounts_list, labels_create), some use action_resource (get_attachment, get_thread), and some are bare verbs (send, reply, archive, label). Within subfamilies the naming is consistent, but across the whole set there is no single predictable pattern.
23 tools is on the heavy side and falls into the borderline range for a single server. However, the count is justified by the breadth of Gmail functionality covered: accounts, labels, threads, messages, drafts, sending, and attachments.
The tool surface covers core Gmail workflows well: search, read, send, reply, forward, draft, label, archive, trash, and attachment retrieval. Minor gaps exist, such as no explicit mark-read/unread or message mutation beyond labels and trash, but agents can work around these.
Maintenance
Related MCP Connectors
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.
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.
Gmail for agents: create inboxes, read and reply to mail, send email, manage domains. OAuth sign-in.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables interaction with Gmail through MCP-compatible clients to list, read, search, and send emails. It supports advanced features such as managing labels, handling threaded replies, and utilizing Gmail's native search syntax.2MIT
- AlicenseAqualityDmaintenanceProvides access to Gmail functionalities including listing unread emails, searching via query syntax, and managing messages through archiving or marking as read. It enables MCP clients to securely interact with and organize email data using the Gmail API.5MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Gmail through the MCP protocol, supporting sending, reading, searching, replying, forwarding, managing drafts and labels, and saving attachments.7 npm3MIT
- FlicenseNot gradedqualityBmaintenanceEnables interacting with multiple Gmail accounts through a single MCP server, supporting search, labels, drafts, and thread management with per-account OAuth.1-