Google Workspace MCP
在 LibreChat 中配置用于 Gmail、Drive、Calendar、People 和 Chat 的 Google 远程 Workspace MCP 服务器。
Google 为 Google Workspace 产品提供了远程 Model Context Protocol (MCP) 服务器。在 LibreChat 中,每个 Google Workspace 产品都被配置为各自启用了 OAuth 的远程 MCP 服务器。
开发者预览版
Google 将 Workspace MCP 服务器标记为 Google Workspace 开发者预览计划的一部分。 在广泛部署之前,请查阅 Google 的最新文档,因为可用的产品、范围和验证要求可能会发生变化。
您将配置的内容
Google Workspace MCP 并非一个组合式服务器。请仅配置您希望向用户公开的产品:
| 产品 | MCP 服务器 URL |
|---|---|
| Gmail | https://gmailmcp.googleapis.com/mcp/v1 |
| Google Drive | https://drivemcp.googleapis.com/mcp/v1 |
| Google Calendar | https://calendarmcp.googleapis.com/mcp/v1 |
| People API | https://people.googleapis.com/mcp/v1 |
| Google Chat | https://chatmcp.googleapis.com/mcp/v1 |
每个用户都从 LibreChat UI 连接到各个服务器。LibreChat 会按用户存储 OAuth 令牌,因此 Gmail、Drive、Calendar、People 和 Chat 的访问权限将遵循授权连接的 Google 账户。
先决条件
- 一个 Google Cloud 项目。
- 在该项目中启用 API 和创建 OAuth 客户端的权限。
- 已安装并完成身份验证的
gcloud,或拥有 Google Cloud 控制台的访问权限。 - 一个正在运行的 LibreChat 实例,且已挂载或以其他方式加载了
librechat.yaml。 - 用户用于打开 LibreChat 的公共基础 URL,例如用于本地开发的
http://localhost:3080或用于生产环境的https://chat.example.com。
OAuth 回调路径
LibreChat 的 MCP OAuth 回调路径为 BASE_URL/api/mcp/SERVER_NAME/oauth/callback。
SERVER_NAME 是 librechat.yaml 中 mcpServers 下的键,例如 gmail 或 drive。
设置
启用 Google Workspace API
将 PROJECT_ID 替换为您的 Google Cloud 项目 ID:
gcloud services enable gmail.googleapis.com \
drive.googleapis.com \
calendar-json.googleapis.com \
chat.googleapis.com \
people.googleapis.com \
--project=PROJECT_ID启用 Google Workspace MCP 服务
为计划配置的产品启用 MCP 服务:
gcloud services enable gmailmcp.googleapis.com \
drivemcp.googleapis.com \
calendarmcp.googleapis.com \
chatmcp.googleapis.com \
people.googleapis.com \
--project=PROJECT_ID如有需要,配置 Google Chat
Google Chat MCP server 需要在同一个 Google Cloud 项目中拥有一个 Chat 应用。
在 Google Cloud 控制台中,打开 Google Chat API > Manage > Configuration 并创建一个 Chat 应用:
- 应用名称:
Chat MCP - 头像 URL:
https://developers.google.com/chat/images/quickstart-app-avatar.png - 描述:
Chat MCP server - 功能性:关闭 Enable interactive features
- 日志 (Logs):选择 将错误记录到日志 (Log errors to Logging)
点击 Save。
聊天需要工作区账户
Google Chat 应用配置可能无法用于个人 Google 账户。如果控制台显示 Google Chat API 仅适用于 Google Workspace 用户,请省略 chat MCP 服务器或使用由 Workspace 支持的项目/账户。
配置 Google Auth 平台
在 Google Cloud 控制台中,前往 Google Auth Platform。
如果尚未配置 Google Auth Platform,请点击 Get Started 并提供:
- App name: 使用一个清晰的名称,例如
LibreChat Google Workspace MCP。 - 用户支持邮箱:您的支持邮箱或 Google 群组。
- Audience:对于 Google Workspace 组织,请选择 Internal;如果用户在您的组织之外,或者您使用的是个人 Google 帐户,请选择 External。
- 开发者联系信息:Google 可用于就该项目与您联系的电子邮件地址。
如果您选择 External 并将应用保持在测试模式,请在 Audience > Test users 下添加您自己及任何其他允许的用户。
添加数据访问范围 (Data Access scopes)
打开 Data Access > Add or Remove Scopes。在 Manually add scopes 下,粘贴您想要使用的服务器的 scope。
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.compose
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/calendar.calendarlist.readonly
https://www.googleapis.com/auth/calendar.events.freebusy
https://www.googleapis.com/auth/calendar.events.readonly
https://www.googleapis.com/auth/directory.readonly
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/contacts.readonly
https://www.googleapis.com/auth/chat.spaces.readonly
https://www.googleapis.com/auth/chat.memberships.readonly
https://www.googleapis.com/auth/chat.messages.readonly
https://www.googleapis.com/auth/chat.messages.create
https://www.googleapis.com/auth/chat.users.readstate.readonly点击 Add to Table,Update,然后点击 Save。
敏感和受限范围
Gmail、Drive、Chat、Contacts 和 Directory 范围可能会触发 Google 的敏感或受限范围审查。对于个人或有限的开发用途,用户可能会看到未经验证的应用警告以及 100 人的用户上限。对于公开或组织范围内的使用,请完成 Google 的 OAuth 验证流程以及任何必要的受限范围审查。
创建 Web 应用程序 OAuth 客户端
在 Google Auth Platform > Clients 中,创建一个 OAuth 客户端:
- 应用类型:
Web application - Name: 使用描述性名称,例如
LibreChat Google Workspace MCP
为每个您配置的服务器添加一个授权重定向 URI。对于本地开发:
http://localhost:3080/api/mcp/gmail/oauth/callback
http://localhost:3080/api/mcp/drive/oauth/callback
http://localhost:3080/api/mcp/calendar/oauth/callback
http://localhost:3080/api/mcp/people/oauth/callback
http://localhost:3080/api/mcp/chat/oauth/callback对于生产环境,请将 http://localhost:3080 替换为您的 LibreChat URL:
https://chat.example.com/api/mcp/gmail/oauth/callback点击 Create,然后复制 Client ID 和 Client secret。
将 OAuth 凭据添加到 .env
将 OAuth 客户端值添加到您的 LibreChat .env 文件中:
GOOGLE_WORKSPACE_MCP_CLIENT_ID=your-oauth-client-id
GOOGLE_WORKSPACE_MCP_CLIENT_SECRET=your-oauth-client-secret如果您同时更新了 librechat.yaml 中的引用,则可以使用不同的环境变量名称。
将 MCP 服务器添加到 librechat.yaml
在 mcpServers 下添加您想要的服务器。此示例使用了目前所有已记录的 Google Workspace MCP 服务器:
mcpServers:
gmail:
type: streamable-http
url: 'https://gmailmcp.googleapis.com/mcp/v1'
timeout: 60000
initTimeout: 150000
requiresOAuth: true
startup: false
oauth:
authorization_url: 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent'
token_url: 'https://oauth2.googleapis.com/token'
client_id: '${GOOGLE_WORKSPACE_MCP_CLIENT_ID}'
client_secret: '${GOOGLE_WORKSPACE_MCP_CLIENT_SECRET}'
scope: 'https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.compose'
redirect_uri: 'http://localhost:3080/api/mcp/gmail/oauth/callback'
token_exchange_method: default_post
token_endpoint_auth_methods_supported: ['client_secret_post']
drive:
type: streamable-http
url: 'https://drivemcp.googleapis.com/mcp/v1'
timeout: 60000
initTimeout: 150000
requiresOAuth: true
startup: false
oauth:
authorization_url: 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent'
token_url: 'https://oauth2.googleapis.com/token'
client_id: '${GOOGLE_WORKSPACE_MCP_CLIENT_ID}'
client_secret: '${GOOGLE_WORKSPACE_MCP_CLIENT_SECRET}'
scope: 'https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/drive.file'
redirect_uri: 'http://localhost:3080/api/mcp/drive/oauth/callback'
token_exchange_method: default_post
token_endpoint_auth_methods_supported: ['client_secret_post']
calendar:
type: streamable-http
url: 'https://calendarmcp.googleapis.com/mcp/v1'
timeout: 60000
initTimeout: 150000
requiresOAuth: true
startup: false
oauth:
authorization_url: 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent'
token_url: 'https://oauth2.googleapis.com/token'
client_id: '${GOOGLE_WORKSPACE_MCP_CLIENT_ID}'
client_secret: '${GOOGLE_WORKSPACE_MCP_CLIENT_SECRET}'
scope: 'https://www.googleapis.com/auth/calendar.calendarlist.readonly https://www.googleapis.com/auth/calendar.events.freebusy https://www.googleapis.com/auth/calendar.events.readonly'
redirect_uri: 'http://localhost:3080/api/mcp/calendar/oauth/callback'
token_exchange_method: default_post
token_endpoint_auth_methods_supported: ['client_secret_post']
people:
type: streamable-http
url: 'https://people.googleapis.com/mcp/v1'
timeout: 60000
initTimeout: 150000
requiresOAuth: true
startup: false
oauth:
authorization_url: 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent'
token_url: 'https://oauth2.googleapis.com/token'
client_id: '${GOOGLE_WORKSPACE_MCP_CLIENT_ID}'
client_secret: '${GOOGLE_WORKSPACE_MCP_CLIENT_SECRET}'
scope: 'https://www.googleapis.com/auth/directory.readonly https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/contacts.readonly'
redirect_uri: 'http://localhost:3080/api/mcp/people/oauth/callback'
token_exchange_method: default_post
token_endpoint_auth_methods_supported: ['client_secret_post']
chat:
type: streamable-http
url: 'https://chatmcp.googleapis.com/mcp/v1'
timeout: 60000
initTimeout: 150000
requiresOAuth: true
startup: false
oauth:
authorization_url: 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent'
token_url: 'https://oauth2.googleapis.com/token'
client_id: '${GOOGLE_WORKSPACE_MCP_CLIENT_ID}'
client_secret: '${GOOGLE_WORKSPACE_MCP_CLIENT_SECRET}'
scope: 'https://www.googleapis.com/auth/chat.spaces.readonly https://www.googleapis.com/auth/chat.memberships.readonly https://www.googleapis.com/auth/chat.messages.readonly https://www.googleapis.com/auth/chat.messages.create https://www.googleapis.com/auth/chat.users.readstate.readonly'
redirect_uri: 'http://localhost:3080/api/mcp/chat/oauth/callback'
token_exchange_method: default_post
token_endpoint_auth_methods_supported: ['client_secret_post']如果 LibreChat 部署在公共 URL 上,请更新每个 redirect_uri 以匹配在 Google Cloud 中注册的确切重定向 URI。
严格的 MCP 域允许列表
如果你的 librechat.yaml 也配置了 mcpSettings.allowedDomains,请添加你所使用的 Google MCP 主机,例如 gmailmcp.googleapis.com、drivemcp.googleapis.com、calendarmcp.googleapis.com、chatmcp.googleapis.com 和 people.googleapis.com。
重启 LibreChat
重启 LibreChat 以便重新加载 .env 和 librechat.yaml。
| 部署 | 命令 |
|---|---|
| Docker | docker compose up -d |
| Local | 停止服务器,然后重新启动 |
要确认 Docker 中加载的服务器,请检查 API 日志:
docker logs LibreChat --tail 200 | grep MCP在 LibreChat 中连接每个服务器
打开 LibreChat,然后打开 MCP Settings 或聊天输入框中的 MCP Servers 下拉菜单。
对于每个 Google Workspace 服务器:
- 点击 Connect。
- 在浏览器中完成 Google OAuth 流程。
- 查看请求的范围。
- 点击 Allow。
OAuth 成功后,服务器的工具即可在聊天和 Agent Builder 中使用。
测试
尝试针对单个服务器的提示词:
| 服务器 | 提示词 |
|---|---|
| People | "According to my Google profile, what's my name?" |
| Drive | "Find a file named Marketing Plan and summarize it." |
| Gmail | "Find my latest email about the marketing plan." |
| Gmail | "Draft an email to [email protected] saying I approve the marketing plan." |
| Calendar | "When is my next meeting with Ariel?" |
| Chat | "Search recent Google Chat messages about the marketing plan." |
故障排除
| 症状 | 检查项 |
|---|---|
Google 提示 redirect_uri_mismatch | Google OAuth 客户端的重定向 URI 必须与 librechat.yaml 中的 redirect_uri 完全一致,包括协议、主机名、端口、服务器名称和路径。 |
| LibreChat 显示了服务器但没有工具 | 从 LibreChat UI 连接服务器。启用了 OAuth 的远程服务器会在用户完成身份验证后公开工具。 |
| Google 显示未验证应用警告 | 对于请求敏感或受限范围的未验证应用,这是预期行为。对于个人或有限的开发用途,用户可以忽略该警告继续操作,直到项目达到 Google 的未验证用户上限。 |
| OAuth 在测试时有效但随后过期 | 测试模式下的外部应用可能会收到 7 天后过期的刷新令牌。将应用发布到生产环境以获取长期有效的刷新令牌,或在开发过程中重新进行身份验证。 |
| Google Chat 配置被禁用 | 请使用 Google Workspace 支持的项目/账户进行 Chat,或省略 chat 服务器。 |
| MCP 请求被 LibreChat 域策略阻止 | 如果配置了 mcpSettings.allowedDomains,请添加您所使用的 Google MCP 服务器主机名。 |
安全注意事项
- 仅将 Google Workspace MCP 服务器连接到您信任的 LibreChat 实例。
- 仅请求用户实际需要的产品和范围。
- 在发送电子邮件、发布 Chat 消息、上传文件或更改日历事件之前,请先审查助手建议的操作。
- 将电子邮件、文档和聊天消息视为不可信输入。它们可能包含试图影响助手的间接提示注入(indirect prompt injection)尝试。
- 对于公共或组织范围内的部署,请完成 Google OAuth 验证并遵循贵组织的第三方应用访问控制。
相关页面
这篇指南怎么样?