Gmail MCP Server

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Enables sending, reading, trashing, and managing emails through Gmail. Provides tools for retrieving unread emails, viewing email content, marking emails as read, sending new emails, and opening emails in a browser.

  • Uses Google Cloud for authentication and API access to Gmail services through OAuth credentials and token management.

モデルコンテキストプロトコル(MCP)用の Gmail サーバー

この MCP サーバーは Gmail と統合され、電子メールの送信、削除、読み取り、下書き、返信が可能になります。

注: このサーバーは、MCPクライアントによるメールの閲覧、削除、送信を可能にします。ただし、これらの操作を実行する前に、クライアントはユーザーに確認メッセージを表示します。

https://github.com/user-attachments/assets/5794cd16-00d2-45a2-884a-8ba0c3a90c90

コンポーネント

ツール

  • メールを送信
    • メールアドレスの受信者にメールを送信します
    • 入力:
      • recipient_id (文字列): 受信者のメールアドレス
      • subject (文字列):メールの件名
      • message (文字列): メールの内容
    • ステータスとmessage_idを返します
  • ゴミ箱メール
    • メールをゴミ箱に移動する
    • 入力:
      • email_id (文字列): メールの自動生成されたID
    • 成功メッセージを返す
  • メールを既読にする
    • メールを既読にする
    • 入力:
      • email_id (文字列): メールの自動生成されたID
    • 成功メッセージを返す
  • 未読メールを取得する
    • 未読メールを取得します
    • メールIDを含むメールのリストを返します
  • メールを読む
    • 指定されたメールの内容を取得します
    • 入力:
      • email_id (文字列): メールの自動生成されたID
    • メールのメタデータの辞書を返し、メールを既読としてマークします
  • オープンメール
    • ブラウザでメールを開く
    • 入力:
      • email_id (文字列): メールの自動生成されたID
    • 成功メッセージを返し、指定されたメールをデフォルトのブラウザで開きます

設定

Gmail API のセットアップ

  1. 新しい Google Cloud プロジェクトを作成する
  2. Gmail APIを有効にする
  3. OAuth同意画面を設定する
    • 「外部」を選択してください。ただし、アプリは公開されません。
    • 個人のメールアドレスを「テストユーザー」として追加します。
  4. OAuth スコープを追加しますhttps://www.googleapis.com/auth/gmail/modify
  5. アプリケーションタイプ「デスクトップアプリ」のOAuth クライアント ID を作成します
  6. クライアントのOAuthキーのJSONファイルをダウンロードします
  7. キーファイルの名前を変更し、ローカルマシンの安全な場所に保存してください。保存場所をメモしておいてください。
    • このファイルへの絶対パスは、サーバーの起動時にパラメーター--creds-file-pathとして渡されます。

認証

サーバーが起動すると、システムブラウザで認証フローが開始されます。トークンの認証情報は、パラメータ--token-pathに渡された絶対ファイルパスに保存され、後で取得されます。

たとえば、ホーム フォルダー内のドット ディレクトリを使用して、 [your-home-folder]を置き換えます。

パラメータ
--creds-file-path/[your-home-folder]/.google/client_creds.json
--token-path/[your-home-folder]/.google/app_tokens.json

デスクトップアプリでの使用

uvの使用をお勧めします。

このサーバーをMCPクライアントとしてClaude Desktopと統合するには、アプリのサーバー構成に以下のコードを追加してください。デフォルトでは、 ~/Library/Application\ Support/Claude/claude_desktop_config.jsonに保存されています。

{ "mcpServers": { "gdrive": { "command": "uv", "args": [ "--directory", "[absolute-path-to-git-repo]", "run", "gmail", "--creds-file-path", "[absolute-path-to-credentials-file]", "--token-path", "[absolute-path-to-access-tokens-file]" ] } } }

以下のパラメータを設定する必要があります

パラメータ
--directoryサーバーを含むgmailディレクトリへの絶対パス
--creds-file-pathGmail API セットアップで作成された認証情報ファイルへの絶対パス。
--token-pathアプリケーションのアクセス トークンとリフレッシュ トークンを保存および取得するための絶対パス。

MCP Inspectorによるトラブルシューティング

サーバーをテストするには、 MCP Inspectorを使用します。gitリポジトリから、以下のコマンドを実行し、パラメータ引数を適宜変更してください。

npx @modelcontextprotocol/inspector uv run [absolute-path-to-git-repo]/src/gmail/server.py --creds-file-path [absolute-path-to-credentials-file] --token-path [absolute-path-to-access-tokens-file]
-
security - not tested
A
license - permissive license
-
quality - not tested

Gmail と統合され、send-email、trash-email、get-unread-emails、read-email などのツールを通じてメールの送信、読み取り、管理を可能にする MCP サーバー。

  1. Components
    1. Tools
  2. Setup
    1. Gmail API Setup
    2. Authentication
    3. Usage with Desktop App
    4. Troubleshooting with MCP Inspector
ID: ghsycs61i7