gmail-mcp-server
gmail-mcp-server
MCPサーバーは、Gmail API を介して Gmail メッセージを(オプションのファイル添付付きで)送信する1つのツール send_email を公開します。Claude Code 内でローカル stdio MCP サーバーとして使用するために構築されています。
スコープは意図的に狭くしています: gmail.send のみ(メールボックスへの読み取り・変更アクセスはなし)— メール送信だけを仕事とするツールへの最小権限です。
この README は実際の初回セットアップに基づいて書かれており、その過程で発生したすべてのエラーを含みます。上から下へ順に従えば、それらのエラーには遭遇しないはずです。
PowerShell に関する注意:
&&は Windows PowerShell ではコマンド区切り文字として機能しません(これは bash/cmd の構文です)。以下の複数コマンドの行はすべて別々の行として書くか、1行にしたい場合は;を使用してください:cd C:\Users\GaneshGupta\gmail-mcp-server; python auth_setup.py
1. Google Cloud — API の有効化と OAuth 認証情報の作成
これに関する Google コンソールの UI は最近「OAuth consent screen」から Google Auth Platform に改名され、設定は左ナビの複数ページ(Branding / Audience / Clients / Data Access / Verification Center)に分割されています。以下の手順は現在の名称を使用しています。
console.cloud.google.com にアクセスします。新しいプロジェクトを作成するか、既存のプロジェクトを再利用してください。
APIs & Services → Library → 「Gmail API」を検索 → Enable。
APIs & Services → OAuth consent screen(ここで新しい Google Auth Platform セクションに移動します)→ Branding ページに入力します:
App name: 任意の名前(例:
gmail-mcp-tool)User support email: 自分の Gmail アドレス
Developer contact email: 自分の Gmail アドレス
ロゴ/App domain フィールドは今は空のままにしてください — 「incomplete configuration」エラーが発生した場合は、ステップ4で App domain に戻ります。 推測で記入せず、実際にそのエラーを見た場合だけ記入してください。
Audience ページ(左ナビ)→ Test users の下 → + Add users → 自分の Gmail アドレス(メールを送信するアドレス)を入力 → Save。
「Add users」がブロックされた場合 — 黄色いバナーに "Your app's OAuth configuration is incomplete... Please visit the Branding page" と表示されたら — これは
gmail.sendが機密スコープであり、Testing のみのアプリでも App domain フィールドが空でないことを要求するためです。修正方法:Branding → App domain に移動し、以下を入力:
Application home page:
https://example.comApplication privacy policy link:
https://example.com/privacyApplication terms of service link:
https://example.com/terms
これで Authorized domains フィールドが表示されます。ドメインのみ(
https://プレフィックスなし)を入力してください:正しい:
example.com間違い(「Invalid domain: must not specify the scheme」というエラーで拒否される):
https://example.com
Branding で Save します(「Branding changes saved!」というトーストが表示されるはずです)。
Audience → Add users に戻ってもう一度試してください — 今度は通るはずです。
これらの URL は実際に機能する必要はありません — アプリが Testing ステータスの間、Google はそれらを検証しません。フィールドが入力されていればよいだけです。
Clients ページ(左ナビ)→ + Create client:
Application type: Desktop app
Name: 任意の名前(例:
gmail-mcp-desktop)Create → Download JSON(作成直後にボタンが表示されます)
ダウンロードされたファイルは
client_secret_<long-id>.apps.googleusercontent.com.jsonのような名前になります。正確にclient_secret.jsonにリネーム し、次の場所に移動してください:C:\Users\GaneshGupta\gmail-mcp-server\credentials\client_secret.jsonファイル名が正確であることが重要です —
gmail_auth.pyはその名前でファイルを探し、一致しない場合はFileNotFoundErrorを発生させます(ここで最もよくある間違いです)。
Related MCP server: Gmail MCP Server
2. 依存関係のインストール
cd C:\Users\GaneshGupta\gmail-mcp-server
pip install -r requirements.txt3. 初回ログイン
python auth_setup.py何が起こるか:
ブラウザウィンドウが開き、通常の Google サインインが表示されます。
「Google hasn't verified this app」 という画面が表示されます。これは想定内です — 自分の OAuth クライアントが Testing モードで機密スコープを要求しているためです。Continue をクリックします(旧 UI では: Advanced → Go to [app name] (unsafe))。
「Send email on your behalf」権限を許可します。
ブラウザに "The authentication flow has completed. You may close this window." と表示されます。
ターミナルに
Authorized. Token saved to ...credentials\token.jsonと表示されます。
ステップ2で代わりに Error 403: access_denied / "has not completed the Google verification process... can only be accessed by developer-approved testers" が表示された場合 — あなたの Gmail アドレスがまだ Audience → Test users リストにありません。上記のステップ 1.4 に戻ってください。
これは一度だけ行います。以降、server.py は保存されたトークンを静かに更新するだけで、自分からブラウザを開くことはありません。
4. トークンの動作確認(任意ですが推奨)
python -c "from gmail_auth import load_credentials; c = load_credentials(); print('valid:', c.valid); print('scopes:', c.scopes); print('has refresh token:', bool(c.refresh_token))"valid: True、scopes: ['https://www.googleapis.com/auth/gmail.send']、has refresh token: True が表示されるはずです。
5. Claude Code に登録する
claude mcp add gmail-sender --scope user -- python C:\Users\GaneshGupta\gmail-mcp-server\server.py--scope user はこれをグローバルに登録します — コマンドを実行したセッションだけでなく、以降このマシン上のすべての Claude Code セッションで利用可能になります。すでに実行中のセッションには遡って表示されません — MCP サーバーはセッション開始時に読み込まれるため、新しいターミナル / 新しい claude セッションで確認してください。
確認:
claude mcp listリストに gmail-sender が表示されるはずです。
6. 使用方法
(上記の登録後)どの Claude Code セッションでも、自然言語で次のように依頼するだけです:
jane@example.com に、件名「Following up」、本文「...」でメールを送信して — C:\path\to\file.pdf を添付
Claude Code が send_email ツールを直接呼び出します。セッションごとの追加設定は不要です。
ツールリファレンス
send_email(to, subject, body, attachments=None, cc=None, bcc=None, html=False)
to/cc/bcc: カンマ区切りのアドレスattachments: 絶対パスのローカルファイルパスのリスト。合計 15MB の制限(Gmail の raw 送信上限は 25MB。生ファイル 15MB なら base64 エンコードによる増加 + ヘッダーの分の余裕が残ります)html: true に設定すると、プレーンテキストの代わりに HTML 本文を送信します戻り値:
{status, message_id, thread_id, to, subject, attachment_count}
トラブルシューティング一覧
症状 | 原因 | 修正方法 |
| ダウンロードした JSON が Google デフォルトの長いファイル名のままだった | 正確に |
| アカウントがまだ Test ユーザーになっていない | Audience → Test users → 自分の Gmail アドレスを追加する |
Audience ページ: 「Your app's OAuth configuration is incomplete」バナーが Add users をブロック | 機密スコープ( | Branding → App domain(home page/privacy/terms)に任意の |
Authorized domain フィールドで「Invalid domain: must not specify the scheme」 | ベアドメインではなく |
|
ログイン中の「Google hasn't verified this app」警告 | 想定内 — 自分の OAuth クライアントが Testing モード | Continue(または Advanced → Go to app)をクリックする。これは正常で、エラーではない |
| これは PowerShell ではなく bash の構文 |
|
| 現在のセッション開始後に登録した、またはスコープが間違っている | 新しい |
別の Gmail アカウントから送信する必要がある | トークンはログインしたアカウントに紐づいている |
|
添付ファイルが拒否される / 大きなファイルで送信が失敗する | 添付ファイルの合計が 15MB を超えている | 複数のメールに分割するか、圧縮する |
注記
credentials/client_secret.jsonとcredentials/token.jsonは gitignore されています — 決してコミットしないでください。別の Gmail アカウントから送信するには、
credentials/token.jsonを削除してauth_setup.pyを再実行してください。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organiz…
Send transactional email over a verified domain — templates, attachments, custom headers.
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables comprehensive Gmail management including sending, reading, and organizing emails, managing labels, drafts, threads, and configuring account settings through the Gmail API with secure OAuth2 authentication.641,723MIT
- AlicenseNot gradedqualityBmaintenanceEnables reading, sending, archiving, and managing Gmail emails and labels through Google OAuth authentication, acting as an OAuth proxy to the Gmail API.20511MIT
- FlicenseNot gradedqualityDmaintenanceEnables sending emails through Gmail using Google's Gmail API. Requires OAuth authentication setup through Google Cloud Console.
- AlicenseNot gradedqualityDmaintenanceEnables programmatic interaction with Gmail using OAuth 2.0 authentication, allowing users to search, read, send, and manage emails through a standardized interface.MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/ganeshhgupta/gmail-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server