Model Context Protocol (MCP) 規範大型語言模型 (LLM) 和 AI 應用程式/代理程式連結外部資料來源的標準方式。MCP 伺服器可讓您使用工具、資源和提示,從後端服務執行動作及取得更新資料。
本機和遠端 MCP 伺服器有何不同?
- 本機 MCP 伺服器
- 通常在本機電腦上執行,並使用標準輸入和輸出串流 (stdio),在同一部裝置上的服務之間進行通訊。
- 遠端 MCP 伺服器
- 在服務的基礎架構上執行,並為 AI 應用程式提供 HTTP 端點,供 AI MCP 用戶端與 MCP 伺服器之間的通訊。如要進一步瞭解 MCP 架構,請參閱 MCP 架構。
Google 和 Google Cloud 遠端 MCP 伺服器
Google 和 Google Cloud 遠端 MCP 伺服器具有下列功能和優點:- 簡化集中式探索作業
- 代管全域或區域 HTTP 端點
- 精細授權
- 使用 Model Armor 保護機制,選擇性確保提示詞和回覆安全無虞
- 集中式稽核記錄
如要瞭解其他 MCP 伺服器,以及 Google Cloud MCP 伺服器適用的安全性與控管措施,請參閱 Google Cloud MCP 伺服器總覽。
事前準備
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Enable the Identity and Access Management API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Enable the Identity and Access Management API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.
必要的角色
如要取得使用 Identity and Access Management MCP 伺服器所需的權限,請要求管理員授予下列 IAM 角色:
-
呼叫 MCP 工具:
MCP 工具使用者 (
roles/mcp.toolUser) 在專案中 -
管理自訂角色:
專案的角色管理員 (
roles/iam.roleAdmin) -
管理拒絕政策:
機構的拒絕管理員 (
roles/iam.denyAdmin)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
這些預先定義的角色具備使用 Identity and Access Management MCP 伺服器所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:
所需權限
如要使用 Identity and Access Management MCP 伺服器,必須具備下列權限:
-
呼叫 MCP 工具:
mcp.tools.call -
管理自訂角色:
-
iam.roles.create -
iam.roles.delete -
iam.roles.get -
iam.roles.list -
iam.roles.undelete -
iam.roles.update
-
-
管理拒絕政策:
-
iam.denypolicies.create -
iam.denypolicies.delete -
iam.denypolicies.get -
iam.denypolicies.list -
iam.denypolicies.update
-
驗證及授權
Identity and Access Management 遠端 MCP 伺服器會使用 OAuth 2.0 通訊協定搭配 Identity and Access Management (IAM) 進行驗證和授權。所有Google Cloud 身分都支援 MCP 伺服器的驗證。Identity and Access Management MCP 伺服器不支援 API 金鑰。
建議您為使用 MCP 工具的代理商建立個別身分,以便控管及監控資源存取權。如要進一步瞭解驗證,請參閱「向 MCP 伺服器進行驗證」。
身分與存取權管理 MCP OAuth 範圍
OAuth 2.0 會使用範圍和憑證,判斷經過驗證的主體是否有權對資源執行特定動作。如要進一步瞭解 Google 的 OAuth 2.0 範圍,請參閱「使用 OAuth 2.0 存取 Google API」。
Identity and Access Management 具有下列 MCP 工具 OAuth 範圍:
| gcloud CLI 的範圍 URI | 說明 |
|---|---|
https://www.googleapis.com/auth/cloud-platform |
查看、編輯、設定及刪除您的 Google Cloud 資料,以及查看您的 Google 帳戶電子郵件地址。 |
https://www.googleapis.com/auth/iam |
授予權限,可查看及管理 IAM 政策,這項服務可控管哪些人能存取特定 Google Cloud 資源。 |
在工具呼叫期間存取的資源可能需要額外範圍。如要查看 Identity and Access Management 所需的範圍清單,請參閱「Identity and Access Management API」。
設定 MCP 用戶端,以便使用身分與存取權管理 MCP 伺服器
AI 應用程式和代理 (例如 Claude 或 Antigravity) 可以例項化 MCP 用戶端,並連至單一 MCP 伺服器。AI 應用程式可有多個連線至不同 MCP 伺服器的用戶端。如果您的應用程式未列在特定用戶端指南中,則可以使用下列資訊,從大多數應用程式連線。
在 AI 應用程式中,尋找新增或連線至遠端 MCP 伺服器的方法。 如果是 Identity and Access Management MCP 伺服器,請視需要輸入下列資訊:
- 伺服器名稱:身分與存取權管理 MCP 伺服器
- 伺服器網址或端點:
https://iam.googleapis.com/mcp - 傳輸:HTTP
- 驗證詳細資料:視驗證方式而定,您可以輸入 Google Cloud 憑證、OAuth 用戶端 ID 和密鑰,或是代理程式身分和憑證。如要進一步瞭解驗證,請參閱「向 MCP 伺服器進行驗證」。
- OAuth 範圍:如要存取 Identity and Access Management MCP 伺服器,請使用
https://www.googleapis.com/auth/cloud-platform或https://www.googleapis.com/auth/iamOAuth 2.0 範圍。
重新導向 URI
如果是網頁應用程式和部分桌面應用程式,您必須在建立驗證用的用戶端 ID 和密鑰時,將重新導向 URI 加入允許清單。授權伺服器會使用重新導向 URI 將權杖傳送至應用程式。應用程式的說明文件應指定您必須使用的重新導向 URI。系統不支援自訂重新導向 URI。
如需設定及連線至 MCP 伺服器的應用程式專屬指引,請參閱用戶端專屬指引。
如需更多一般指引,請參閱下列資源:
可用的工具
如要查看 Identity and Access Management MCP 伺服器的可用 MCP 工具詳細資料和說明,請參閱「Identity and Access Management MCP 參考資料」。
清單工具
使用 MCP 檢查器列出工具,或直接將 tools/list HTTP 要求傳送至身分與存取權管理遠端 MCP 伺服器。tools/list 方法不需要驗證。
POST /mcp HTTP/1.1
Host: iam.googleapis.com
Content-Type: application/json
{
"jsonrpc": "2.0",
"method": "tools/list",
}
應用實例
透過 IAM 遠端 MCP 伺服器,您可以管理資源的 IAM 存取權設定。包括列出、建立、更新、刪除及還原角色、IAM 政策和繫結等工作。
以下是 Identity and Access Management MCP 伺服器的應用實例:
| 用途 | 提示範例 |
|---|---|
| 列出、搜尋及擷取專案中自訂 IAM 角色的中繼資料。 | 「我們新來的 DevOps 實習生需要查看 Cloud Storage 值區,並在預先發布專案中重新啟動 Google Kubernetes Engine 執行個體。請檢查這個專案中是否有符合這些需求的現有預先定義或自訂角色,還是需要建立新的自訂角色?" |
| 在專案中建立、更新、刪除或還原自訂 IAM 角色。 | 「我們需要在 security-audit 專案中為稽核團隊建立新角色,這個角色應命名為 LogViewerAndBucketReader,並包含下列權限:logging.logEntries.list、logging.privateLogEntries.list 和 storage.buckets.list。此外,請刪除專案中已淘汰的自訂角色「OldAuditRole」。」 |
| 列出及擷取專案中的明確拒絕政策。 | 「我需要稽核 secure-data-folders 資料夾。請列出直接附加至這個資料夾的所有拒絕政策。請顯示每項政策的詳細資料,特別是拒絕資料存取權或資源建立權限的任何規則。」 |
| 在專案中建立、更新或刪除拒絕政策。 | 「confidential-data 專案中可能發生資料外洩。建立新的拒絕政策,拒絕 suspicious-sa@confidential-data.iam.gserviceaccount.com 服務帳戶對這個專案中所有 BigQuery 資料集和 Cloud Storage bucket 的所有權限。在同一個專案中,刪除 example_deny 政策。 |
選用的安全防護設定
由於 MCP 工具可執行各種動作,因此會帶來新的安全風險和考量。為盡量降低及管理這些風險,Google Cloud 提供預設設定和可自訂的政策,控管機構或專案中 MCP 工具的使用情形。 Google Cloud
如要進一步瞭解 MCP 安全性和控管措施,請參閱「AI 安全性」。
使用 Model Armor
Model Armor 是一項Google Cloud 服務,旨在提升 AI 應用程式的安全性。這項功能會主動篩選 LLM 提示詞和回覆,防範各種風險並支援負責任的 AI 做法。無論您是在雲端環境或外部雲端供應商部署 AI,Model Armor 都能協助您防範惡意輸入、驗證內容安全性、保護敏感資料、維持法規遵循狀態,以及在多元的 AI 環境中,持續落實 AI 安全政策。
啟用 Model Armor 並啟用記錄功能後,Model Armor 會記錄整個酬載。這可能會導致記錄中出現私密資訊。
MCP 要求轉送至 Model Armor
Model Armor 僅在特定區域推出。啟用 Model Armor 後,如果您在 Model Armor 不支援的管轄區使用 MCP 伺服器,不同 MCP 伺服器的呼叫路徑行為可能不同,且可能會違反使用中和傳輸中資料的資料落地法規。如要進一步瞭解個別 MCP 伺服器的行為,請參閱「Model Armor 支援的產品」。啟用 Model Armor
您必須先啟用 Model Armor API,才能使用 Model Armor。
控制台
gcloud
開始前,請使用 Google Cloud CLI 搭配 Model Armor API 執行下列步驟:
在 Google Cloud 控制台中啟用 Cloud Shell。
控制台底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。 Google Cloud Cloud Shell 是已安裝 Google Cloud CLI 的殼層環境,並已針對您目前的專案設定好相關值。工作階段可能要幾秒鐘的時間才能初始化。
-
執行下列指令,為 Model Armor 服務設定 API 端點。
gcloud config set api_endpoint_overrides/modelarmor "https://modelarmor.LOCATION.rep.googleapis.com/"
將
LOCATION替換為要使用 Model Armor 的區域。
設定 Google 和 Google Cloud 遠端 MCP 伺服器的防護功能
如要保護 MCP 工具呼叫和回應,可以使用 Model Armor 底限設定。底限設定會定義適用於整個專案的最低安全性篩選條件。這項設定會對專案中的所有 MCP 工具呼叫和回覆套用一致的篩選器。
設定 Model Armor 底限設定,並啟用 MCP 清理功能。詳情請參閱「設定 Model Armor 底價」。
請參閱下列指令範例:
gcloud model-armor floorsettings update \ --full-uri='projects/PROJECT_ID/locations/global/floorSetting' \ --enable-floor-setting-enforcement=TRUE \ --add-integrated-services=GOOGLE_MCP_SERVER \ --google-mcp-server-enforcement-type=INSPECT_AND_BLOCK \ --enable-google-mcp-server-cloud-logging \ --malicious-uri-filter-settings-enforcement=ENABLED \ --add-rai-settings-filters='[{"confidenceLevel": "MEDIUM_AND_ABOVE", "filterType": "DANGEROUS"}]'
將 PROJECT_ID 替換為 Google Cloud 專案 ID。
請注意下列設定:
INSPECT_AND_BLOCK:強制執行類型,可檢查 Google MCP 伺服器的內容,並封鎖符合篩選條件的提示和回應。ENABLED:啟用篩選器或強制執行的設定。MEDIUM_AND_ABOVE:負責任的 AI 技術 - 危險篩選器設定的信心水準。您可以修改這項設定,但較低的值可能會導致更多誤判。詳情請參閱「Model Armor 信心水準」。
停用使用 Model Armor 掃描 MCP 流量
如要停止 Model Armor 根據專案的底限設定,自動掃描往返 Google MCP 伺服器的流量,請執行下列指令:
gcloud model-armor floorsettings update \
--full-uri='projects/PROJECT_ID/locations/global/floorSetting' \
--remove-integrated-services=GOOGLE_MCP_SERVER
將 PROJECT_ID 替換為 Google Cloud 專案 ID。Model Armor 不會自動將這個專案底限設定中定義的規則,套用至任何 Google MCP 伺服器流量。
Model Armor 底限設定和一般設定的影響範圍不只 MCP,由於 Model Armor 會與 Vertex AI 等服務整合,因此您對底限設定所做的任何變更,都會影響所有整合服務 (不只是 MCP) 的流量掃描和安全行為。
使用 Identity and Access Management 拒絕政策控管 MCP 使用情形
身分與存取權管理 (IAM) 拒絕政策和允許政策可協助您保護 Google Cloud 和 Google MCP 伺服器。
您可以組合多項條件,根據下列項目允許或拒絕存取權,建立自訂的安全性和控管政策:
- 本金。
- 工具屬性,例如唯讀屬性。
- 服務名稱或工具名稱。
- 應用程式的 OAuth 用戶端 ID。
詳情請參閱「使用身分與存取權管理功能控管 MCP 使用情形」。