Gmail MCP Server
Gmail MCPサーバー
Gmailへの読み取り専用アクセスを提供するModel Context Protocol (MCP) サーバーです。Claude Codeが安全にGmailの受信トレイを検索、読み取り、分析できるようにします。
機能
search_emails - Gmailのクエリ構文を使用して検索
list_unread - 未読メールを一覧表示
get_message - 添付ファイルメタデータを含むメッセージの全内容を取得
get_thread - 会話スレッド内の全メッセージを取得
draft_reply - 返信ドラフトの内容を準備(送信は行いません)
Related MCP server: Gmail MCP Server
前提条件
Node.js 18以上
Gmail APIが有効なGoogle Cloudプロジェクト
OAuth 2.0 デスクトップアプリの認証情報
Google Cloudの設定
1. Google Cloudプロジェクトの作成
Google Cloud Console にアクセスします
「プロジェクトを選択」→「新しいプロジェクト」をクリックします
プロジェクト名を入力します(例: "Gmail MCP Server")
「作成」をクリックします
2. Gmail APIの有効化
プロジェクト内で「APIとサービス」→「ライブラリ」に移動します
「Gmail API」を検索します
クリックして「有効にする」を押します
3. OAuth同意画面の設定
「APIとサービス」→「OAuth同意画面」に移動します
「外部」(Google Workspaceを使用している場合は「内部」)を選択します
必須フィールドを入力します:
アプリ名: "Gmail MCP Server"
ユーザーサポートメール: あなたのメールアドレス
デベロッパーの連絡先情報: あなたのメールアドレス
「保存して次へ」をクリックします
スコープを追加します:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.compose
テストユーザーとして自分のメールアドレスを追加します(外部の場合)
設定を完了します
4. OAuth認証情報の作成
「APIとサービス」→「認証情報」に移動します
「認証情報を作成」→「OAuthクライアントID」をクリックします
アプリケーションの種類として「デスクトップアプリ」を選択します
名前を付けます(例: "Gmail MCP Desktop")
「作成」をクリックします
クライアントIDとクライアントシークレットをダウンロードまたはコピーします
インストール
# Clone or navigate to the project
cd gmail-mcp
# Install dependencies
npm install
# Build the project
npm run build設定
サンプル環境ファイルをコピーします:
cp .env.example .envOAuth認証情報を使用して
.envを編集します:
CLIENT_ID=your-client-id.apps.googleusercontent.com
CLIENT_SECRET=your-client-secret初回実行(認証)
サーバーを初めて実行すると、以下の処理が行われます:
Google認証のためにブラウザが開きます
サインインと権限の付与を求められます
トークンがローカルの
token.jsonに保存されます
以降の実行では、保存されたトークンが自動的に再利用されます。
Claude Codeでの使用
MCPサーバーの追加
claude mcp add gmail node ./dist/index.jsまたは、Claude Codeの設定に手動で追加します:
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["./dist/index.js"],
"cwd": "/path/to/gmail-mcp"
}
}
}利用可能なツール
search_emails
Gmailのクエリ構文を使用してメールを検索します。
Query examples:
- "from:user@example.com"
- "subject:meeting"
- "is:unread"
- "after:2024/01/01 before:2024/12/31"
- "has:attachment filename:pdf"
- "in:inbox -category:promotions"list_unread
未読メールを一覧表示します(is:unread 検索のショートカット)。
get_message
メッセージIDを指定して、特定のメールの全内容を取得します。
get_thread
スレッドIDを指定して、会話スレッド内の全メッセージを取得します。
draft_reply
スレッドへの返信ドラフトを準備します。返信を作成するためのコンテキストを提供しますが、メールの送信は行いません。
開発
# Run in development mode (with hot reload)
npm run dev
# Type check
npm run typecheck
# Build for production
npm run build
# Run production build
npm startセキュリティに関する注意点
OAuthトークンはローカルの
token.jsonに保存されます.envやtoken.jsonをバージョン管理にコミットしないでくださいサーバーは読み取りと作成の権限のみを要求します
メールは送信されません -
draft_replyは内容を準備するだけですメールの内容はログに記録されません
トラブルシューティング
"Missing CLIENT_ID or CLIENT_SECRET"
.env ファイルが存在し、有効な認証情報が含まれていることを確認してください。
"Authorization timeout"
OAuthフローには5分間のタイムアウトがあります。サーバーを再起動し、速やかに認証を完了してください。
"Token refresh failed"
token.json を削除して、再度認証を行ってください。
"Access blocked: This app's request is invalid"
OAuth同意画面が適切に設定されていること、およびテストユーザーとしてメールアドレスが追加されていることを確認してください。
This server cannot be deployed
Maintenance
Related MCP Connectors
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Read email/chat conversations, messages, contacts and teams; draft, send and update threads.
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
Never-stored live email: read, send, organize, schedule and auto-triage Gmail or any IMAP mailbox.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA read-only MCP server that enables users to interact with the Gmail API to search messages, retrieve threads, and download attachments. It supports standard Gmail query operators and requires OAuth authentication for secure read-only access to mailbox data.1MIT
- AlicenseNot gradedqualityCmaintenanceProvides secure, read-only access to Gmail for Claude CLI with label-based filtering for enhanced privacy and control. It enables users to search, list, and summarize email content while ensuring no modification or deletion of messages is possible.134 npm1MIT
- AlicenseNot gradedqualityDmaintenanceRead-only MCP server for Gmail that enables searching threads, reading messages, and listing labels without any write access.134 npmMIT
- AlicenseAqualityAmaintenanceEnables read-only, provider-agnostic email access over IMAP, allowing users to list folders, search and read messages, and download attachments without ever marking messages as read.6MIT