mcp-gsuite MCP服务器
示例提示
目前,此MCP服务器支持Gmail和日历集成,具备以下功能:
- 常规
- 多个Google账户
- Gmail
- 获取您的Gmail用户信息
- 使用灵活的搜索查询邮件(例如,未读、来自特定发件人、日期范围、带附件)
- 通过ID检索完整邮件内容
- 创建新的草稿邮件,包含收件人、主题、正文和抄送选项
- 删除草稿邮件
- 回复现有邮件(可以立即发送或保存为草稿)
- 通过其ID一次性检索多封邮件。
- 将邮件中的多个附件保存到您的本地系统。
- 日历
- 管理多个日历
- 获取指定时间范围内的日历事件
- 创建日历事件,包含:
- 标题、开始/结束时间
- 可选的位置和描述
- 可选的与会者
- 自定义时区支持
- 通知偏好设置
- 删除日历事件
您可以尝试以下示例提示:
-
检索我最新的未读消息
-
搜索来自Scrum Master的邮件
-
检索来自会计的所有邮件
-
检索关于ABC的邮件并总结
-
为Alice的最后一封邮件写一封友好的回复,并上传草稿。
-
回复Bob的邮件并附上感谢便条。保存为草稿
-
明天我的日程安排是什么?
-
检查我私人账户的家庭日程安排下周
-
我需要为Tim计划下周一个2小时的会议。建议一些时间段。
快速入门
安装
通过Smithery安装
要自动通过Smithery为Claude桌面安装mcp-gsuite:
npx -y @smithery/cli install mcp-gsuite --client claude
OAuth 2
Google Workspace (G Suite) API需要OAuth2授权。按照以下步骤设置认证:
-
创建OAuth2凭证:
- 前往Google Cloud Console
- 创建一个新项目或选择一个现有项目
- 为您的项目启用Gmail API和Google Calendar API
- 转到“凭证”→“创建凭证”→“OAuth客户端ID”
- 选择“桌面应用”或“Web应用”作为应用类型
- 配置OAuth同意屏幕,包含必要信息
- 添加授权重定向URI(本地开发时包含
http://localhost:4100/code)
-
必要的OAuth2范围:
[
"openid",
"https://mail.google.com/",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/userinfo.email"
]
- 然后在您的 working directory 中创建一个
.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"
}
}
- 创建一个
.accounts.json文件,包含账户信息
{
"accounts": [
{
"email": "alice@bob.com",
"account_type": "personal",
"extra_info": "您想要告诉Claude的额外信息:例如 '包含家庭日历'"
}
]
}
您可以指定多个账户。确保它们在您的Google Auth应用中有访问权限。extra_info字段尤其有趣,您可以在这里添加您想要告诉AI的关于账户的信息(例如,它是否有一个特定的日程)
注意:当您首次执行特定账户的工具时,浏览器将打开,将您重定向到Google并要求您的凭证、范围等。成功登录后,它将凭证存储在一个名为.oauth.{email}.json的本地文件中。一旦您获得授权,将使用刷新令牌。
Claude桌面
在MacOS上:~/Library/Application\ Support/Claude/claude_desktop_config.json
在Windows上:%APPDATA%/Claude/claude_desktop_config.json
开发/未发布服务器配置
{
"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"
]
}
}
}
已发布服务器配置
{
"mcpServers": {
"mcp-gsuite": {
"command": "uvx",
"args": [
"mcp-gsuite",
"--accounts-file",
"/path/to/custom/.accounts.json",
"--credentials-dir",
"/path/to/custom/credentials"
]
}
}
}
配置选项
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
此配置特别适用于您运行多个服务器实例且具有不同配置,或部署到默认路径不适用环境的情况。
开发
构建和发布
为分发准备包:
- 同步依赖项并更新锁文件:
uv sync
- 构建包分发:
uv build
这将创建源和轮包在dist/目录中。
- 发布到PyPI:
uv publish
注意:您需要通过环境变量或命令标志设置PyPI凭证:
- 令牌:
--token或UV_PUBLISH_TOKEN - 或者用户名/密码:
--username/UV_PUBLISH_USERNAME和--password/UV_PUBLISH_PASSWORD
调试
由于MCP服务器通过stdio运行,调试可能具有挑战性。为获得最佳调试体验,我们强烈建议使用MCP Inspector。
您可以通过 npm 使用此命令启动MCP Inspector:
npx @modelcontextprotocol/inspector uv --directory /path/to/mcp-gsuite run mcp-gsuite
启动后,Inspector将显示一个URL,您可以在浏览器中访问以开始调试。
您还可以使用此命令查看服务器日志:
tail -n 20 -f ~/Library/Logs/Claude/mcp-server-mcp-gsuite.log