Google Workspace 提供遠端 Model Context Protocol (MCP) 伺服器,可讓 AI 代理安全地與 Google Workspace 資料互動。設定 Google Workspace MCP 伺服器後,AI 應用程式 (例如 Gemini CLI、Claude 或 IDE) 就能在 Gmail、Google 雲端硬碟、Google 日曆和 Google Chat 等 Google Workspace 應用程式中執行動作。每項 Google Workspace 產品都有專屬的 MCP 伺服器。
Google Workspace MCP 伺服器提供標準化方式,讓 AI 代理執行下列操作:
- 讀取資料:搜尋電子郵件、擷取檔案及列出日曆活動。
- 採取行動:撰寫電子郵件草稿、上傳檔案及安排會議。
- 尊重安全性:沿用與使用者相同的權限和資料治理控制項。
必要條件
Google Cloud 專案。如要建立專案,請參閱「建立專案」一文。
MCP 用戶端,例如 Gemini CLI。
如要在本頁執行指令,請按照下列步驟,在本地開發環境中設定 gcloud CLI:
- 安裝 Google Cloud CLI。
如果您先前已安裝 gcloud CLI,請執行
gcloud components update,確認您使用的是最新版本。 - 如果您使用外部識別資訊提供者 (IdP),請使用聯合身分登入 gcloud CLI。詳情請參閱「使用聯合身分登入 gcloud CLI」。
- 初始化 gcloud CLI。
- 安裝 Google Cloud CLI。
如果您先前已安裝 gcloud CLI,請執行
設定 Google Workspace MCP 伺服器
如要使用 Google Workspace MCP 伺服器,您必須在 Google Cloud 雲端專案中啟用這些伺服器,然後設定 MCP 用戶端以連線至伺服器。
啟用 API
如要使用 Google Workspace MCP 伺服器,您必須在 Google Cloud 雲端專案中啟用下列 API:
- Gmail API
- Google Drive API
- Google Calendar API
- Google Chat API
People API
CLI
gcloud services enable gmail.googleapis.com \
drive.googleapis.com \
calendar-json.googleapis.com \
chat.googleapis.com \
people.googleapis.com --project=PROJECT_ID
將 PROJECT_ID 替換為您的 Google Cloud 專案 ID。
控制台
在 Google Cloud 控制台中啟用 API:
啟用 MCP 服務
如要為各項 Google Workspace 產品啟用 MCP 元件,您必須在 Google Cloud 專案中啟用下列服務:
- Gmail MCP API
- Google Drive MCP API
- Google Calendar MCP API
- Google Chat MCP API
People MCP API
CLI
gcloud services enable gmailmcp.googleapis.com \
drivemcp.googleapis.com \
calendarmcp.googleapis.com \
chatmcp.googleapis.com \
people.googleapis.com --project=PROJECT_ID
將 PROJECT_ID 替換為您的 Google Cloud 專案 ID。
控制台
在 Google Cloud 控制台中啟用 MCP 服務:
設定 Chat 應用程式
如要使用 Google Chat MCP 伺服器,您必須在 Google Cloud 雲端專案中設定 Chat 應用程式。
在 Google Cloud 控制台中搜尋「Google Chat API」,然後依序點選「Google Chat API」>「管理」>「設定」。
設定 Chat 應用程式:
- 取消勾選「將這個 Chat 擴充應用程式建構為 Google Workspace 外掛程式」。系統會開啟對話方塊,要求您確認。按一下對話方塊中的「停用」。
- 在「App name」(應用程式名稱) 欄位中輸入
Chat MCP。 - 在「Avatar URL」(顯示圖片網址) 欄位中輸入
https://developers.google.com/chat/images/quickstart-app-avatar.png。 - 在「Description」(說明) 中輸入
Chat MCP server。 - 在「功能」下方,將「啟用互動功能」切換為關閉,即可停用互動功能。
- 在「瀏覽權限」下方,選取「將這個 Chat 應用程式提供給網域中的特定使用者和群組」,然後輸入電子郵件地址。
- 在「記錄」下方,選取「將錯誤記錄至 Logging」。
按一下 [儲存]。
如要進一步瞭解如何建構 Chat 應用程式,請參閱「選擇 Google Chat 應用程式架構」。
設定 OAuth 同意畫面
Google Workspace MCP 伺服器會使用 OAuth 2.0 進行驗證和授權。 您必須先設定 OAuth 同意畫面,才能建立 OAuth 用戶端 ID。
在 Google Cloud 控制台中,依序前往「Google Auth Platform」>「Branding」。
如果您已設定 Google 驗證平台,可以在「品牌」、「目標對象」和「資料存取權」中設定下列 OAuth 同意畫面設定。如果看到「尚未設定 Google 驗證平台」訊息,請按一下「開始使用」:
- 在「App Information」(應用程式資訊) 下方的「App name」(應用程式名稱) 中,輸入
Workspace MCP Servers。 - 在「使用者支援電子郵件」中,選取您的電子郵件地址或適當的 Google 群組。
- 點選 [下一步]。
- 在「目標對象」下方,選取「內部」。如果無法選取「內部」,請選取「外部」。
- 點選 [下一步]。
- 在「聯絡資訊」下方,輸入可接收專案異動通知的電子郵件地址。
- 點選 [下一步]。
- 在「完成」部分,請詳閱《Google API 服務使用者資料政策》,然後選取「我同意《Google API 服務:使用者資料政策》」。
- 按一下「繼續」。
- 點選「建立」。
- 如果為使用者類型選取「外部」,請新增測試使用者:
- 按一下「目標對象」。
- 在「測試使用者」下方,按一下「新增使用者」。
- 輸入您的電子郵件地址和任何其他授權測試使用者,然後按一下「儲存」。
- 在「App Information」(應用程式資訊) 下方的「App name」(應用程式名稱) 中,輸入
依序按一下「資料存取權」>「新增或移除範圍」。系統會顯示面板,列出您在 Google Cloud 雲端專案中啟用的各項 API 範圍。
在「手動新增範圍」下方,貼上要使用的 MCP 伺服器範圍:
- Gmail:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.compose
- Google 雲端硬碟:
https://www.googleapis.com/auth/drive.readonlyhttps://www.googleapis.com/auth/drive.file
- Google 日曆:
https://www.googleapis.com/auth/calendar.calendarlist.readonlyhttps://www.googleapis.com/auth/calendar.events.freebusyhttps://www.googleapis.com/auth/calendar.events.readonly
- Google Chat:
https://www.googleapis.com/auth/chat.spaces.readonlyhttps://www.googleapis.com/auth/chat.memberships.readonlyhttps://www.googleapis.com/auth/chat.messages.readonlyhttps://www.googleapis.com/auth/chat.users.readstate.readonly
- People API:
https://www.googleapis.com/auth/directory.readonlyhttps://www.googleapis.com/auth/userinfo.profilehttps://www.googleapis.com/auth/contacts.readonly
- Gmail:
按一下「新增至表格」。
按一下「更新」。
選取應用程式所需的範圍後,在「資料存取」頁面中,按一下「儲存」。
設定 MCP 用戶端
如要將 Google Workspace 遠端 MCP 伺服器新增至 MCP 用戶端,請按照用戶端的操作說明進行。
Gemini CLI
如要將 Google Workspace 遠端 MCP 伺服器新增至 Gemini CLI,請將伺服器設定新增至 settings.json 檔案。
建立 OAuth 2.0 用戶端 ID 和密鑰:
在 Google Cloud 控制台中,依序前往「Google Auth Platform」>「Clients」>「Create Client」。
將應用程式類型設為「Desktop app」(電腦應用程式)。
輸入名稱。
按一下「建立」,並複製「用戶端 ID」和「用戶端密鑰」。
開啟或建立設定檔
~/.gemini/settings.json。將
mcpServers設定新增至settings.json:{ "mcpServers": { "gmail": { "httpUrl": "https://gmailmcp.googleapis.com/mcp/v1", "oauth": { "enabled": true, "clientId": "OAUTH_CLIENT_ID", "clientSecret": "OAUTH_CLIENT_SECRET", "scopes": [ "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.compose" ] } }, "drive": { "httpUrl": "https://drivemcp.googleapis.com/mcp/v1", "oauth": { "enabled": true, "clientId": "OAUTH_CLIENT_ID", "clientSecret": "OAUTH_CLIENT_SECRET", "scopes": [ "https://www.googleapis.com/auth/drive.readonly", "https://www.googleapis.com/auth/drive.file" ] } }, "calendar": { "httpUrl": "https://calendarmcp.googleapis.com/mcp/v1", "oauth": { "enabled": true, "clientId": "OAUTH_CLIENT_ID", "clientSecret": "OAUTH_CLIENT_SECRET", "scopes": [ "https://www.googleapis.com/auth/calendar.calendarlist.readonly", "https://www.googleapis.com/auth/calendar.events.freebusy", "https://www.googleapis.com/auth/calendar.events.readonly" ] } }, "people": { "httpUrl": "https://people.googleapis.com/mcp/v1", "oauth": { "enabled": true, "clientId": "OAUTH_CLIENT_ID", "clientSecret": "OAUTH_CLIENT_SECRET", "scopes": [ "https://www.googleapis.com/auth/directory.readonly", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/contacts.readonly" ] } }, "chat": { "httpUrl": "https://chatmcp.googleapis.com/mcp/v1", "oauth": { "enabled": true, "clientId": "OAUTH_CLIENT_ID", "clientSecret": "OAUTH_CLIENT_SECRET", "scopes": [ "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.users.readstate.readonly" ] } } } }更改下列內容:
OAUTH_CLIENT_ID:您建立的用戶端 ID。OAUTH_CLIENT_SECRET:您建立的用戶端密鑰。
現省
settings.json。啟動 Gemini CLI:
gemini在 Gemini CLI 中執行下列指令,向每個 MCP 伺服器進行驗證:
/mcp auth gmail- 系統提示時,請按下
1,在瀏覽器中開啟驗證頁面。如果透過 SSH 工作,請按照 CLI 中的指示操作。 - 登入 Google 帳戶。
- 查看要求的 OAuth 範圍,然後按一下「允許」。
- 系統會顯示訊息,確認驗證成功。
針對每個 MCP 伺服器重複執行下列步驟:
/mcp auth drive/mcp auth calendar/mcp auth people/mcp auth chat
- 系統提示時,請按下
在 Gemini CLI 中執行
/mcp list,即可查看設定的 MCP 伺服器及其工具。回覆內容大致如下:
🟢 gmail - Ready (10 tools) Tools: - create_draft - create_label - get_thread - label_message - label_thread - list_drafts - list_labels - search_threads - unlabel_message - unlabel_thread 🟢 drive - Ready (7 tools) Tools: - create_file - download_file_content - get_file_metadata - get_file_permissions - list_recent_files - read_file_content - search_files 🟢 calendar - Ready (8 tools) Tools: - create_event - delete_event - get_event - list_calendars - list_events - respond_to_event - suggest_time - update_event 🟢 people - Ready (3 tools) Tools: - get_user_profile - search_contacts - search_directory_people 🟢 chat - Ready (2 tools) Tools: - search_conversations - list_messages
現在可以在 Gemini CLI 中使用遠端 MCP 伺服器。
Claude
如要搭配 Claude.ai 或 Claude Desktop 使用 Google Workspace 遠端 MCP 伺服器,您必須訂閱 Claude Enterprise、Pro、Max 或 Team 方案。
如要將 Google Workspace 遠端 MCP 伺服器新增至 Claude,請使用 OAuth 用戶端 ID 和密碼設定自訂連接器。
建立 OAuth 2.0 用戶端 ID 和密鑰:
在 Google Cloud 控制台中,依序前往「Google Auth Platform」>「Clients」>「Create Client」。
將應用程式類型設為「Web application」(網頁應用程式)。
輸入名稱。
在「已授權的重新導向 URI」部分,按一下「+ 新增 URI」,然後在「URI」欄位中新增
https://claude.ai/api/mcp/auth_callback。按一下「建立」,並複製「用戶端 ID」和「用戶端密鑰」。
在 Claude 中設定 MCP 伺服器:
- 在 Claude.ai 或 Claude Desktop 中,依序前往「設定」 (或「管理設定」) >「連結器」。
- 按一下「新增自訂連結器」。
- 輸入要新增的 Google Workspace 產品連線詳細資料:
- 伺服器名稱:伺服器的名稱,例如
Gmail。 - 遠端 MCP 伺服器網址:Google Workspace 產品的網址,例如下列其中一個:
- Gmail:
https://gmailmcp.googleapis.com/mcp/v1 - Google 雲端硬碟:
https://drivemcp.googleapis.com/mcp/v1 - Google 日曆:
https://calendarmcp.googleapis.com/mcp/v1 - Google Chat:
https://chatmcp.googleapis.com/mcp/v1 - People API:
https://people.googleapis.com/mcp/v1
- Gmail:
- 伺服器名稱:伺服器的名稱,例如
- 在「進階設定」中,輸入 OAuth 用戶端 ID 和 OAuth 用戶端密鑰。
- 按一下 [新增]。
- 針對要新增的每個 Google Workspace 產品重複執行上述步驟。
其他
許多 AI 應用程式都能連線至遠端 MCP 伺服器。您通常需要輸入伺服器的詳細資料,例如名稱、端點、傳輸通訊協定和驗證方法。如果是 Google Workspace 遠端 MCP 伺服器,請輸入下列內容:
伺服器名稱:
googleworkspace伺服器:每個 Google Workspace 產品都有專屬的伺服器網址:
- Gmail:
https://gmailmcp.googleapis.com/mcp/v1 - Google 雲端硬碟:
https://drivemcp.googleapis.com/mcp/v1 - Google 日曆:
https://calendarmcp.googleapis.com/mcp/v1 - Google Chat:
https://chatmcp.googleapis.com/mcp/v1 - People API:
https://people.googleapis.com/mcp/v1
- Gmail:
傳輸:HTTP
驗證:Google Workspace 遠端 MCP 伺服器使用 OAuth 2.0。詳情請參閱「瞭解驗證和授權」。
如要進一步瞭解如何連線不同類型的用戶端,請參閱「在 AI 應用程式中設定 MCP」。
測試 Google Workspace MCP 伺服器
設定 MCP 用戶端後,您可以執行一些測試提示詞,驗證連線。
請嘗試詢問 MCP 用戶端下列問題:
「根據我的 Google 個人資料,我的名字是什麼?」
用戶端會使用
people.get_user_profile擷取您的 Google Workspace 個人資料資訊。「提供『行銷計畫』檔案內容摘要。」
用戶端會呼叫
drive.search_files來尋找「行銷計畫」,然後使用drive.read_file_content擷取並摘要其內容。「Ariel 在上一封電子郵件中,對我們的行銷計畫有什麼看法?」
用戶端會使用
gmail.search_threads篩選來自 Ariel 的電子郵件、使用gmail.get_thread擷取最新討論串的內容,然後為您摘要。「草擬一封電子郵件給 ariel@example.com,說明我已核准行銷計畫。」
用戶端會使用
gmail.create_draft在草稿資料夾中建立電子郵件,方便您在 Gmail 中檢查及傳送郵件。「我與 Ariel 的下一場會議是什麼時候?」
用戶端會使用
calendar.list_events檢查您的行程,並詳細列出您與 Ariel 的下一次會議。
如果工具執行成功,且您收到相關回應,表示 Google Workspace MCP 伺服器已正確設定。
疑難排解
如果無法連線至 MCP 伺服器,請檢查 OAuth 記錄檔是否有錯誤。 請管理員在安全調查工具中查看 OAuth 記錄事件。
支援的產品
下列 Google Workspace 產品支援 Google Workspace MCP 伺服器,並提供下列工具:
重要安全考量:間接提示詞注入
如果將不受信任的資料提供給語言模型,可能會發生間接提示詞注入攻擊。由於 Gemini CLI 等 MCP 用戶端可透過 Google Workspace MCP 伺服器存取強大的工具和 API,因此能夠讀取、修改及刪除 Google 帳戶中的資料。
為降低這些風險,請遵循下列最佳做法:
- 只使用信任的工具。請勿將 Google Workspace MCP 伺服器連線至不受信任或未經驗證的應用程式。
- 請謹慎處理不受信任的輸入內容。請避免要求 MCP 用戶端處理來自未經驗證來源的電子郵件、文件或其他資源。這些輸入內容可能含有隱藏指令,可劫持您的工作階段,讓攻擊者修改、竊取或刪除您的資料。
- 查看所有動作。請務必仔細檢查 AI 用戶端代表您執行的動作,確保這些動作正確無誤,且符合您的意圖。