Skip to main content
Glama
gmail-mcp

gmail-mcp

by iXanadu

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-doctor

HTTP トランスポートを実行する前に、.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 http://127.0.0.1:8767/oauth/callback を追加(.env の GMAIL_MCP_OAUTH_REDIRECT_URI と一致させる必要あり)

5

.keys

Client ID と Client secret を GMAIL_MCP_GOOGLE_CLIENT_ID / GMAIL_MCP_GOOGLE_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_remove

MCP クライアントから 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 client
  • MCP 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

GMAIL_MCP_ENVIRONMENT

.env

ログ / ステータス用のラベル

GMAIL_MCP_LOG_LEVEL

.env

サーバーのログレベル

GMAIL_MCP_HTTP_HOST

.env

HTTP バインドアドレス(デフォルト 127.0.0.1)

GMAIL_MCP_HTTP_PORT

.env

HTTP ポート(デフォルト 8879)

GMAIL_MCP_OUTBOX_ROOT

.env

送信添付ファイルのパスのルート

GMAIL_MCP_DOWNLOAD_ROOT

.env

get_attachment の書き込み先ルート

GMAIL_MCP_TOKENS_DIR

.env

OAuth トークンの保存ディレクトリ

GMAIL_MCP_OAUTH_REDIRECT_URI

.env

OAuth ループバックコールバック

GMAIL_MCP_GOOGLE_CLIENT_ID

.keys

Google OAuth クライアント ID

GMAIL_MCP_GOOGLE_CLIENT_SECRET

.keys

Google OAuth クライアントシークレット

GMAIL_MCP_HTTP_BEARER_TOKEN

.keys

HTTP トランスポート用のベアラートークン

設定を変更したら gmail-doctor を実行してください。

トランスポート

stdio(ローカル)

gmail-mcp

accounts_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

gmail_status

バージョンと設定の概要

accounts_list

接続済みアドレスとトークンの健全性

accounts_add

OAuth 同意(stdio のみ)

accounts_remove

トークンの失効と破棄(stdio のみ)

search

Gmail クエリ。スレッドを返します

get_thread / get_message

format=plain または full

get_attachment

ダウンロードルート配下に書き込む

send / reply / forward

パスのみ。JSON 内の content / base64 は拒否

draft_create / draft_send

send と同じ添付 / 証明ルール

labels_list / labels_create

ユーザー + システムラベル

label / unlabel

カンマ区切りの名前または ID

archive / trash / untrash

スレッド単位

accounts_list、accounts_add、gmail_status を除くすべてのツールは、account 引数(Gmail アドレス)を必要とします。

送信ルール(概要)

  • 添付ファイル: { "path": "/absolute/or/under/outbox/file.pdf" } — インライン base64 はなし

  • ライブの Gmail 署名が送信時に追加されます(キャッシュなし)

  • 署名の後に任意の footer

  • 証明を返します: サイズ、href、ok false → ツールエラー(例: 切り詰められた添付ファイル、google.com/url の書き換え)

テスト

pytest tests/ -v

モック化した Gmail HTTP を使用します。実際のメールボックスは不要です。

仕様

製品要件: docs/specs/gmail-mcp-spec.md

ライセンス

Apache-2.0

Available Tools

23 tools
accounts_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

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

    B3.1/5.0

    Scored across 23 tools

    Disambiguation4/5

    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.

    Naming Consistency3/5

    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.

    Tool Count3/5

    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.

    Completeness4/5

    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

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables 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.
      2
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Provides 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.
      5
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with Gmail through the MCP protocol, supporting sending, reading, searching, replying, forwarding, managing drafts and labels, and saving attachments.
      7 npm
      3
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables interacting with multiple Gmail accounts through a single MCP server, supporting search, labels, drafts, and thread management with per-account OAuth.
      1
      -