Gmail MCP Server

local-only server

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

Integrations

  • Allows reading, sending, removing, drafting, and responding to emails through Gmail. Features include retrieving unread emails, marking emails as read, trashing emails, and opening emails in a browser.

  • Used for creating projects and setting up the OAuth authentication required for Gmail API access.

用于模型上下文协议 (MCP) 的 Gmail 服务器

该 MCP 服务器与 Gmail 集成,可实现发送、删除、阅读、起草和回复电子邮件。

注意:此服务器允许 MCP 客户端阅读、删除和发送电子邮件。但是,客户端会在执行这些操作之前提示用户。

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

成分

工具

  • 发送电子邮件
    • 发送电子邮件至电子邮件地址收件人
    • 输入:
      • recipient_id (字符串):收件人的电子邮件地址
      • subject (字符串):电子邮件主题
      • 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

与桌面应用程序一起使用

建议使用紫外线

要将此服务器与 Claude Desktop 集成为 MCP 客户端,请将以下内容添加到应用的服务器配置中。默认情况下,此配置存储在~/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-path在 Gmail 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 集成,实现通过模型上下文协议 (MCP) 发送、阅读、起草和管理电子邮件,允许用户通过自动客户端提示与电子邮件任务进行交互。

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