PG

paulfidika/gmail-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

22 stars 14 forks 质量 61 趋势 0MIT

一个单文件MCP服务器,用于与Gmail交互。支持Claude桌面和光标。

概览

一个MCP服务器,允许AI代理搜索Gmail线程,了解你的邮件写作风格,并创建草稿邮件。 1. 进入 Google Cloud 控制台 2.点击顶部 3 的“选择项目”下拉菜单。点击“新项目” 4.输入项目名称(例如,“Gmail MCP 服务器”)5.点击“创建” 1. 在你的新项目中,进入“API & Services”→“Library” 2.搜索“Gmail API” 3.点击“Gmail API”并点击“启用” 1. 进入“API与服务”→“凭证” 2.点击“创建凭证”→“OAuth 客户端ID” 3.如果被提示,配置OAuth同意界面: - 选择“外部”用户类型 - 填写必填项(应用名称、用户支持邮箱、开发者邮箱) - 将您的邮箱添加到“测试用户”部分 - 保存并继续完成所有步骤 4.回到凭证中,点击“创建凭据”→“OAuth 客户端ID” 5.选择“桌面应用程序”作为应用类型 6.输入名称(例如,“Gmail MCP客户端”) 7.点击“创建” 8.

概述(AI 翻译)

一个MCP服务器,允许AI代理搜索Gmail线程,了解你的邮件写作风格,并创建草稿邮件。

1.获取谷歌认证

第一步:创建谷歌云项目

  1. 访问谷歌云控制台
  2. 点击顶部的“选择项目”下拉菜单
  3. 点击“新项目”
  4. 输入项目名称(例如,“Gmail MCP Server”)
  5. 点击“创建”

步骤2:启用Gmail API

  1. 在你的新项目中,进入“APIS & Services”→“Library”
  2. 搜索“Gmail API”
  3. 点击“Gmail API”并点击“启用”

步骤3:创建OAuth2凭证

  1. 进入“API & Services”→“凭证”
  2. 点击“创建凭据”→“OAuth 客户端ID”
  3. 如果被提示,配置OAuth同意界面:
  • 选择“外部”用户类型
  • 填写必填字段(应用名称、用户支持邮箱、开发者邮箱)
  • 将您的邮箱添加到“测试用户”部分
  • 保存并继续完成所有步骤
  1. 回到凭据中,点击“创建凭据”→“OAuth 客户端ID”
  2. 选择“桌面应用”作为应用类型
  3. 输入名称(例如,“Gmail MCP 客户端”)
  4. 点击“创建”

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Gmail MCP Server

An MCP server that lets AI agents search Gmail threads, understand your email writing style, and create draft emails.

1. Get Google Authentication

Step 1: Create a Google Cloud Project

  1. Go to Google Cloud Console
  2. Click “Select a project” dropdown at the top
  3. Click “New Project”
  4. Enter a project name (e.g., “Gmail MCP Server”)
  5. Click “Create”

Step 2: Enable Gmail API

  1. In your new project, go to “APIs & Services” → “Library”
  2. Search for “Gmail API”
  3. Click on “Gmail API” and click “Enable”

Step 3: Create OAuth2 Credentials

  1. Go to “APIs & Services” → “Credentials”
  2. Click “Create Credentials” → “OAuth Client ID”
  3. If prompted, configure the OAuth consent screen:
    • Choose “External” user type
    • Fill in required fields (App name, User support email, Developer email)
    • Add your email to “Test users” section
    • Save and continue through all steps
  4. Back in Credentials, click “Create Credentials” → “OAuth Client ID”
  5. Choose “Desktop application” as the application type
  6. Enter a name (e.g., “Gmail MCP Client”)
  7. Click “Create”
  8. Important: Copy the Client ID and Client Secret from the confirmation dialog (you’ll need these for configuration)

Step 4: Grant OAuth Scopes

When you first run the server, it will open your browser for authorization. The server requests only these minimal permissions:

What We Request:

  • ✅ Gmail Readonly Access (gmail.readonly)

    • Search and read your email messages
    • Download email attachments
    • View email metadata (subjects, senders, dates)
  • ✅ Gmail Compose Access (gmail.compose)

    • Create email drafts
    • Update existing drafts
    • Delete drafts
    • Send emails (permission granted but not used by this server)

What This Server Actualy Implements:

  • ✅ Search and read emails - Full search capabilities
  • ✅ Extract attachment text - Safe PDF/DOCX/TXT text extraction
  • ✅ Create/update drafts - Smart draft management with thread awareness
  • ❌ Send emails - Server doesn’t implement sending (though permission is granted)
  • ❌ Delete emails - Server doesn’t implement deletion
  • ❌ Modify labels - Server doesn’t implement label management

2. Add to MCP Clients

Build the server first: go build .

You’ll want to add this to your agent’s configuration file:

{
  "mcpServers": {
    "gmail": {
      "command": "C:/path/to/your/auto-gmail.exe",
      "env": {
        "GMAIL_CLIENT_ID": "your_client_id_here.apps.googleusercontent.com",
        "GMAIL_CLIENT_SECRET": "your_client_secret_here",
        "OPENAI_API_KEY": "your_openai_api_key_here"
      }
    }
  }
}

⚡ Persistent HTTP Mode (Recommended to Avoid OAuth Popups)

Problem: In stdio mode, Cursor starts a fresh server process each time (and for each tab), causing OAuth popup spam.

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "gmail": { "command": "C:/path/to/your/auto-gmail.exe", "env": { "GMAIL_CLIENT_ID": "your_client_id_here.apps.googleusercontent.com", "GMAIL_CLIENT_SECRET": "your_client_secret_here", "OPENAI_API_KEY": "your_openai_api_key_here" } } } }