Gmail MCP Server

by Quantum-369
Apache 2.0
8
  • Apple
  • Linux

Integrations

  • Allows reading, sending, and managing emails from multiple Gmail accounts, including searching emails, downloading attachments, and handling email conversations and threads.

  • Requires a Google Cloud Project with Gmail API enabled and OAuth 2.0 credentials for authentication and authorization.

Gmail MCP 服务器

一个强大而灵活的 Gmail 集成服务器,基于 MCP(消息控制协议)框架构建。该服务器提供强大的接口,可与 Gmail API 交互,并提供以编程方式阅读、发送和管理电子邮件的功能。

特征

  • 阅读来自多个 Gmail 帐户的电子邮件
  • 发送带附件的电子邮件
  • 使用高级查询选项搜索电子邮件
  • 下载电子邮件附件
  • 处理电子邮件对话和主题
  • 实时电子邮件监控
  • 支持多个 Gmail 帐户

先决条件

在运行 Gmail MCP 服务器之前,请确保您具备以下条件:

  1. Python 3.12 或更高版本
  2. 已启用 Gmail API 的 Google Cloud 项目
  3. OAuth 2.0 客户端 ID 凭证
  4. 所需的 Python 包(在 pyproject.toml 中指定)

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 Gmail 集成服务器:

npx -y @smithery/cli install @Quantum-369/Gmail-mcp-server --client claude
  1. 克隆存储库:
git clone <your-repository-url> cd gmail-mcp-server
  1. 创建并激活虚拟环境:
python -m venv venv # On Windows venv\Scripts\activate # On Unix/MacOS source venv/bin/activate
  1. 安装依赖项:
pip install .

设置 Google Cloud 项目

  1. 前往Google Cloud Console
  2. 创建新项目或选择现有项目
  3. 为您的项目启用 Gmail API
  4. 创建 OAuth 2.0 凭据:
    • 前往“API 和服务”>“凭证”
    • 点击“创建凭证”>“OAuth 客户端 ID”
    • 选择“桌面应用”作为应用程序类型
    • 下载客户端配置文件
  5. 将下载的文件重命名为client_secret.json并放置在项目根目录下

配置

  1. gmail_token_creator.py中设置电子邮件标识符:
email_identifier = 'your.email@gmail.com' # Change this for each account
  1. 运行令牌创建器来验证您的 Gmail 帐户:
python gmail_token_creator.py
  1. 对要集成的每个 Gmail 帐户重复此过程

服务器结构

  • gmail_server.py :主要 MCP 服务器实现
  • gmail_api.py :Gmail API 交互函数
  • google_apis.py API 身份验证实用程序
  • 支持文件:
    • read_emails.py :电子邮件阅读功能
    • search_emails.py :电子邮件搜索功能
    • send_emails.py :电子邮件发送功能

用法

启动服务器

python gmail_server.py

可用工具

  1. 发送电子邮件:
await send_gmail( email_identifier="your.email@gmail.com", to="recipient@example.com", subject="Test Subject", body="Email body content", attachment_paths=["path/to/attachment"] )
  1. 搜索电子邮件:
await search_email_tool( email_identifier="your.email@gmail.com", query="from:someone@example.com", max_results=30, include_conversations=True )
  1. 阅读最新电子邮件:
await read_latest_emails( email_identifier="your.email@gmail.com", max_results=5, download_attachments=False )
  1. 下载附件:
await download_email_attachments( email_identifier="your.email@gmail.com", msg_id="message_id", download_all_in_thread=False )

安全注意事项

  • 安全地存储client_secret.json并且永远不要将其提交到版本控制
  • 确保令牌文件的安全并将其添加到.gitignore
  • 使用环境变量来获取敏感信息
  • 定期轮换 OAuth 凭证
  • 监控 API 使用情况并设置适当的配额

错误处理

该服务器包括全面的错误处理和日志记录:

  • 日志写入gmail_mcp.log
  • 文件和控制台日志记录均已启用
  • 用于调试的详细错误消息

贡献

  1. 分叉存储库
  2. 创建功能分支
  3. 提交你的更改
  4. 推送到分支
  5. 创建拉取请求

执照

Apache许可证2.0

支持

对于问题和功能请求,请使用 GitHub 问题跟踪器。

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

通过 Gmail API 与 Gmail 交互,阅读、发送和管理电子邮件。支持多个 Gmail 帐户,并提供实时监控以及电子邮件搜索和附件处理的高级功能。

  1. 特征
    1. 先决条件
      1. 安装
        1. 通过 Smithery 安装
      2. 设置 Google Cloud 项目
        1. 配置
          1. 服务器结构
            1. 用法
              1. 启动服务器
              2. 可用工具
            2. 安全注意事项
              1. 错误处理
                1. 贡献
                  1. 执照
                    1. 支持

                      Related MCP Servers

                      • -
                        security
                        F
                        license
                        -
                        quality
                        Enables users to manage Gmail accounts using AI agent-assisted operations via an MCP protocol, supporting email search, reading, deletion, and sending with a voice-powered interface.
                        Last updated -
                        2
                        5
                        TypeScript
                      • -
                        security
                        A
                        license
                        -
                        quality
                        Integrates with Gmail to enable sending, reading, drafting, and managing emails via the Model Context Protocol (MCP), allowing users to interact with email tasks through automated client prompts.
                        Last updated -
                        Python
                        GPL 3.0
                      • -
                        security
                        A
                        license
                        -
                        quality
                        An MCP server that enables Gmail integration, allowing users to manage emails (send, receive, read, trash, mark as read) directly through MCP clients like Claude Desktop.
                        Last updated -
                        Python
                        MIT License
                      • -
                        security
                        F
                        license
                        -
                        quality
                        Enables AI assistants to interact with Gmail accounts via IMAP, allowing them to list, search, read, and send emails, manage labels and folders, and access attachments through the Model Context Protocol.
                        Last updated -
                        Python
                        • Linux
                        • Apple

                      View all related MCP servers

                      ID: mkugelscaj