本文說明如何使用 Resource Manager 遠端 Model Context Protocol (MCP) 伺服器,連線至 AI 應用程式,包括 Gemini CLI、ChatGPT、Claude,以及您開發的自訂應用程式。Resource Manager 遠端 MCP 伺服器可讓您搜尋並找出您有權存取的所有 Google Cloud 專案,確保您在嘗試更具體的資源設定前,已取得正確的 ID。
這項工具會傳回結構化清單,其中包含專案 ID、專案編號和專案的生命週期狀態。啟用 Resource Manager API 時,系統會啟用 Resource Manager 遠端 MCP 伺服器。
Model Context Protocol (MCP) 規範大型語言模型 (LLM) 和 AI 應用程式/代理程式連結外部資料來源的標準方式。MCP 伺服器可讓您使用工具、資源和提示,從後端服務執行動作及取得更新資料。
本機和遠端 MCP 伺服器有何不同?
- 本機 MCP 伺服器
- 通常在本機上執行,並使用標準輸入和輸出串流 (stdio),在同一部裝置上的服務之間進行通訊。
- 遠端 MCP 伺服器
- 在服務的基礎架構上執行,並為 AI 應用程式提供 HTTP 端點,供 AI MCP 用戶端與 MCP 伺服器之間的通訊。如要進一步瞭解 MCP 架構,請參閱「MCP 架構」。
無狀態核心
在 MCP 2026-07-28 版中,MCP 從雙向有狀態通訊協定變更為無狀態通訊協定。每個 MCP 要求都包含自我描述,並可使用標頭轉送。由於每個要求都包含 HTTP 標頭或 _meta 參數中所需的所有資訊,因此不需要 initialize/initialized 交握或 Mcp-Session-Id。MCP 伺服器可透過多來回要求 (MRTR),要求工具所需的額外資訊。
為協助系統在不剖析要求主體的情況下,轉送及處理要求,您必須提供部分 MCP 標頭,包括:
- MCP 規格要求的標頭,例如通訊協定版本標頭和標準要求標頭。
- MCP 伺服器定義的自訂標頭。這些標頭會使用
x-mcp-header屬性,從工具的輸入結構定義鏡像到 HTTP 標頭。舉例來說,MCP 伺服器可能會定義自訂標頭,以指定 Google Cloud 區域或專案 ID。
如要進一步瞭解 MCP 架構,請參閱 MCP 2026-07-28 版的規格和主要變更。
Google 和 Google Cloud 遠端 MCP 伺服器
Google 和 Google Cloud 遠端 MCP 伺服器具備下列功能和優點:- 簡化集中式探索作業
- 受管理的全域或區域 HTTP 端點
- 精細授權
- 使用 Model Armor 保護機制,選擇性確保提示詞和回覆安全無虞
- 集中稽核記錄
如要瞭解其他 MCP 伺服器,以及 Google Cloud MCP 伺服器適用的安全性與控管控制項,請參閱「Google Cloud MCP 伺服器總覽」。
限制
您可以使用 IAM 拒絕政策,封鎖傳送至 Resource Manager 服務及其 MCP 伺服器的流量。不過,MCP 專屬的 IAM 屬性和 toolUser 權限無法用於限制這個伺服器的工具存取權。
事前準備
- 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. - 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.
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
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.
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Resource Manager API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. 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.
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
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
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.
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Resource Manager API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. 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.
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
驗證及授權
Resource Manager 遠端 MCP 伺服器會使用 OAuth 2.0 通訊協定搭配 Identity and Access Management (IAM) 進行驗證和授權。MCP 伺服器支援所有Google Cloud 身分驗證。Resource Manager MCP 伺服器不接受 API 金鑰進行驗證。
建議您使用 MCP 工具為代理建立獨立身分,以便控管及監控資源存取權。如要進一步瞭解驗證,請參閱「向 MCP 伺服器驗證」。
Resource Manager MCP OAuth 範圍
OAuth 2.0 會使用範圍和憑證,判斷通過驗證的主體是否有權對資源執行特定動作。如要進一步瞭解 Google 的 OAuth 2.0 範圍,請參閱「使用 OAuth 2.0 存取 Google API」。
Resource Manager 具有下列 MCP 工具 OAuth 範圍:
| gcloud CLI 的範圍 URI | 說明 |
|---|---|
https://www.googleapis.com/auth/cloudresourcemanager.read-only |
只能讀取資料。 |
https://www.googleapis.com/auth/cloudresourcemanager.read-write |
可讀取及修改資料。 |
在工具呼叫期間存取的資源可能需要額外範圍。如要查看 Resource Manager 的必要範圍清單,請參閱 Resource Manager API。
設定 MCP 用戶端,以便使用 Resource Manager MCP 伺服器
AI 應用程式和代理 (例如 Claude 或 Antigravity) 可以例項化 MCP 用戶端,並連至單一 MCP 伺服器。AI 應用程式可有多個用戶端,連線至不同的 MCP 伺服器。如果用戶端專屬指南中未列出您的應用程式,則可使用下列資訊,從大多數應用程式連線。
在 AI 應用程式中,尋找新增或連線至遠端 MCP 伺服器的方法。 針對 Resource Manager MCP 伺服器,請視需要輸入下列資訊:
- 伺服器名稱:Resource Manager MCP 伺服器
- 伺服器網址或端點:https://cloudresourcemanager.googleapis.com/mcp
- 傳輸:可串流的 HTTP
- 驗證詳細資料:視您要採用的驗證方式而定,您可以輸入 Google Cloud 憑證、OAuth 用戶端 ID 和密鑰,或代理身分和憑證。如要進一步瞭解驗證,請參閱「向 MCP 伺服器進行驗證」。
- OAuth 範圍:連線至 Resource Manager MCP 伺服器時要使用的 OAuth 2.0 範圍。
重新導向 URI
如果是網路應用程式和部分桌面應用程式,您必須在建立驗證用的用戶端 ID 和密鑰時,將重新導向 URI 加入許可清單。授權伺服器會使用重新導向 URI 將權杖傳送至應用程式。應用程式的說明文件應指定您必須使用的重新導向 URI。不支援自訂重新導向 URI。
如需設定及連線至 MCP 伺服器的應用程式專屬指引,請參閱用戶端專屬指引。
如需一般指引,請參閱下列資源:
可用的工具
如要查看 Resource Manager MCP 伺服器的可用 MCP 工具詳細資料和說明,請參閱 Resource Manager MCP 參考資料。
清單工具
使用 MCP 檢查器列出工具,或直接將 tools/list HTTP 要求傳送至 Resource Manager 遠端 MCP 伺服器。tools/list 方法不需要驗證。
curl -X POST https://cloudresourcemanager.googleapis.com/TOOLSET_ENDPOINT \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'MCP-Protocol-Version: MCP_PROTOCOL_VERSION' \
-H 'Mcp-Method: tools/list' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "MCP_PROTOCOL_VERSION",
"io.modelcontextprotocol/clientCapabilities": {
"extensions": {
"io.modelcontextprotocol/ui": {
"mimeTypes": ["text/html;profile=mcp-app"]
}
}
}
}
}
}'
更改下列內容:
TOOLSET_ENDPOINT:服務名稱後方的 MCP 端點其餘部分。舉例來說,如果是 Resource Manager,這可能是mcp/toolset-name。MCP_PROTOCOL_VERSION:MCP 通訊協定版本。例如:2026-07-28。
應用實例
AI 代理可透過資源管理工具遠端 MCP 伺服器中的 search_projects 工具,動態探索及識別您有權存取的所有 Google Cloud 專案,以便在其他工具中執行指令。
這項工具會傳回結構化清單,其中包含專案 ID、專案編號和專案的生命週期狀態。以下是 Resource Manager MCP 伺服器的範例用途:
資源清單和無障礙稽核:列出並彙整您可存取的有效雲端專案。
使用者提示:「列出我所有進行中的 Google Cloud 專案。」
代理程式動作:代理程式會將搜尋查詢傳送至 MCP 伺服器,以擷取並顯示您憑證下所有有效專案的摘要清單。
以父項為目標的搜尋:擷取特定資料夾或機構中的專案,縮小要求範圍。
使用者提示:「Find all projects under Folder 223.」(找出資料夾 223 中的所有專案)。
代理動作:代理使用查詢
parent:folders/223執行工具呼叫,傳回該行政邊界內的專案清單。隱含式內容解析:當您要求資源相關資訊,但未提供特定專案 ID 時,代理程式可以自動解析內容。
使用者提示:「檢查『payment-processor』服務的狀態。」
代理動作:代理辨識出 Cloud Run 工具缺少
project_id。系統會使用search_projects工具尋找名稱中含有payment的專案,找出可能的專案 (例如payment-prod-123),並在繼續操作前要求您確認。特定環境探索:您可以在不離開對話介面的情況下,依特定環境或機構結構篩選專案。
使用者提示:「我在測試環境中可以存取哪些專案?」
代理程式動作:代理程式會搜尋標示或命名為
staging的所有專案,並傳回特定專案 ID。
自訂 LLM 行為
search_projects 工具用途廣泛,但 LLM 不一定知道何時該查詢 Google Cloud 階層。如要在特定情境中呼叫工具,請在 Markdown 檔案中提供自訂脈絡,例如 ~/.gemini/GEMINI.md 或專案層級的 AGENTS.md。
後續步驟
- 請參閱 Resource Manager MCP 參考文件。
- 進一步瞭解 Google Cloud MCP 伺服器。