Skip to main content
Glama
Quantum-369

Gmail MCP Server

by Quantum-369

Gmail MCP 服务器

铁匠徽章

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

特征

  • 阅读来自多个 Gmail 帐户的电子邮件

  • 发送带附件的电子邮件

  • 使用高级查询选项搜索电子邮件

  • 下载电子邮件附件

  • 处理电子邮件对话和主题

  • 实时电子邮件监控

  • 支持多个 Gmail 帐户

Related MCP server: Systemprompt MCP Gmail Server

先决条件

在运行 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

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

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/Quantum-369/Gmail-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server