返回市场
MCP-G套件服务器

MCP-G套件服务器

作者:MarkusPfundstein460 星标更新:2025-04-14

项目介绍

mcp-gsuite MCP服务器

smithery徽章 与Google产品交互的MCP服务器。

示例提示

目前,此MCP服务器支持Gmail和日历集成,具有以下功能:

  1. 通用
  • 多个Google账户
  1. Gmail
  • 获取您的Gmail用户信息
  • 使用灵活搜索查询邮件(例如,未读邮件,来自特定发件人,日期范围,带有附件)
  • 通过ID检索完整的邮件内容
  • 创建新的草稿邮件,包括收件人、主题、正文和抄送选项
  • 删除草稿邮件
  • 回复现有邮件(可以选择立即发送或保存为草稿)
  • 通过它们的ID一次性检索多封邮件。
  • 将邮件中的多个附件保存到本地系统。
  1. 日历
  • 管理多个日历
  • 获取指定时间范围内的日历事件
  • 创建日历事件,包括:
    • 标题、开始/结束时间
    • 可选位置和描述
    • 可选参会者
    • 自定义时区支持
    • 通知偏好设置
  • 删除日历事件

您可以尝试的示例提示:

  • 检索我最新的未读邮件

  • 从Scrum Master那里搜索我的邮件

  • 检索来自会计的所有邮件

  • 查看关于ABC的邮件并总结它

  • 写一封友好的回复给Alice的最后一封邮件,并上传草稿。

  • 对Bob的邮件回复感谢信。将其保存为草稿

  • 我明天的日程是什么?

  • 检查我的私人账户下周的家庭日程

  • 我需要在下周与Tim安排一个两小时的活动。建议一些时间段。

快速入门

安装

通过Smithery安装

要通过Smithery自动安装mcp-gsuite到Claude Desktop:

npx -y @smithery/cli install mcp-gsuite --client claude

OAuth 2

Google Workspace(G Suite)APIs需要OAuth2授权。按照以下步骤设置身份验证:

  1. 创建OAuth2凭证:

    • 访问Google Cloud Console
    • 创建新项目或选择现有项目
    • 为您的项目启用Gmail API和Google Calendar API
    • 转到“凭证”→“创建凭证”→“OAuth客户端ID”
    • 选择“桌面应用”或“网络应用”作为应用程序类型
    • 配置OAuth同意屏幕所需的详细信息
    • 添加授权重定向URI(包括http://localhost:4100/code用于本地开发)
  2. 所需的OAuth2范围:

   [
     "openid",
     "https://mail.google.com/",
     "https://www.googleapis.com/auth/calendar",
     "https://www.googleapis.com/auth/userinfo.email"
   ]
  1. 在工作目录中创建一个.gauth.json文件,包含客户端信息:
{
    "web": {
        "client_id": "$your_client_id",
        "client_secret": "$your_client_secret",
        "redirect_uris": ["http://localhost:4100/code"],
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token"
    }
}
  1. 创建一个.accounts.json文件,包含账户信息:
{
    "accounts": [
        {
            "email": "alice@bob.com",
            "account_type": "personal",
            "extra_info": "您想告诉Claude的额外信息:例如'包含家庭日历'"
        }
    ]
}

您可以指定多个账户。确保它们在您的Google Auth应用中有访问权限。extra_info字段特别有用,因为您可以在此处添加有关账户的信息(例如,是否具有特定日程)。

注意:当您首次执行特定账户的工具时,浏览器会打开,重定向到Google并请求您的凭据、范围等。成功登录后,它会在名为.oauth.{email}.json的本地文件中存储凭据。一旦授权,将使用刷新令牌。

Claude Desktop

在MacOS上:~/Library/Application\ Support/Claude/claude_desktop_config.json

在Windows上:%APPDATA%/Claude/claude_desktop_config.json

<details> <summary>开发/未发布的服务器配置</summary>
{
  "mcpServers": {
    "mcp-gsuite": {
      "command": "uv",
      "args": [
        "--directory",
        "<dir_to>/mcp-gsuite",
        "run",
        "mcp-gsuite"
      ]
    }
  }
}

注意:您还可以使用uv run mcp-gsuite --accounts-file /path/to/custom/.accounts.json来指定不同的账户文件或--credentials-dir /path/to/custom/credentials来指定不同的凭据目录。

{
  "mcpServers": {
    "mcp-gsuite": {
      "command": "uv",
      "args": [
        "--directory",
        "<dir_to>/mcp-gsuite",
        "run",
        "mcp-gsuite",
        "--accounts-file",
        "/path/to/custom/.accounts.json",
        "--credentials-dir",
        "/path/to/custom/credentials"
      ]
    }
  }
}
</details> <details> <summary>已发布的服务器配置</summary>
{
  "mcpServers": {
    "mcp-gsuite": {
      "command": "uvx",
      "args": [
        "mcp-gsuite",
        "--accounts-file",
        "/path/to/custom/.accounts.json",
        "--credentials-dir",
        "/path/to/custom/credentials"
      ]
    }
  }
}
</details>

配置选项

MCP服务器可以通过几个命令行选项进行配置,以指定认证和账户信息的自定义路径:

  • --gauth-file:指定包含OAuth2客户端配置的.gauth.json文件的路径。默认是./.gauth.json
  • --accounts-file:指定包含Google账户信息的.accounts.json文件的路径。默认是./.accounts.json
  • --credentials-dir:指定成功认证后存储OAuth凭据的目录。默认是在当前工作目录下,每个账户有一个子目录.oauth.{email}.json

这些选项允许在管理不同环境或多个凭据集和账户时具有灵活性,特别是在开发和测试场景中非常有用。

示例用法:

uv run mcp-gsuite --gauth-file /path/to/custom/.gauth.json --accounts-file /path/to/custom/.accounts.json --credentials-dir /path/to/custom/credentials

此配置在您运行多个具有不同配置的服务器实例或部署到默认路径不适用的环境中时特别有用。

开发

构建和发布

为了准备分发的包:

  1. 同步依赖项并更新锁文件:
uv sync
  1. 构建包分布:
uv build

这将在dist/目录中创建源和轮子分布。

  1. 发布到PyPI:
uv publish

注意:您需要通过环境变量或命令标志设置PyPI凭据:

  • Token:--tokenUV_PUBLISH_TOKEN
  • 或用户名/密码:--username/UV_PUBLISH_USERNAME--password/UV_PUBLISH_PASSWORD

调试

由于MCP服务器通过标准I/O运行,调试可能具有挑战性。为了获得最佳的调试体验,我们强烈推荐使用MCP Inspector

您可以通过npm使用以下命令启动MCP Inspector:

npx @modelcontextprotocol/inspector uv --directory /path/to/mcp-gsuite run mcp-gsuite

启动后,Inspector将显示一个URL,您可以在浏览器中访问该URL以开始调试。

您也可以使用以下命令监视服务器日志:

tail -n 20 -f ~/Library/Logs/Claude/mcp-server-mcp-gsuite.log