使用 Resource Manager 遠端 MCP 伺服器

本文說明如何使用 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 架構

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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    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.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

    安裝 Google Cloud CLI。 完成後,執行下列指令來初始化 Google Cloud CLI:

    gcloud init

    若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

    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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    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.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

    安裝 Google Cloud CLI。 完成後,執行下列指令來初始化 Google Cloud CLI:

    gcloud init

    若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

驗證及授權

Resource Manager 遠端 MCP 伺服器會使用 OAuth 2.0 通訊協定搭配 Identity and Access Management (IAM) 進行驗證及授權。MCP 伺服器支援所有Google Cloud 身分驗證。

Resource Manager MCP 伺服器會使用 OAuth 2.0 通訊協定搭配 Identity and Access Management (IAM) 進行驗證及授權。所有Google Cloud 身分皆支援 MCP 伺服器的驗證。

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 或 Gemini CLI) 可以例項化 MCP 用戶端,連線至單一 MCP 伺服器。AI 應用程式可有多個連至不同 MCP 伺服器的用戶端。如要連線至遠端 MCP 伺服器,MCP 用戶端至少須知道遠端 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 範圍

如需特定主機的指引,請參閱下列文章:

如需更多一般指引,請參閱下列資源:

可用的工具

如要查看 Resource Manager MCP 伺服器的可用 MCP 工具詳細資料和說明,請參閱 Resource Manager MCP 參考資料

列出工具

使用 MCP 檢查器列出工具,或直接將 tools/list HTTP 要求傳送至 Resource Manager 遠端 MCP 伺服器。tools/list 方法不需要驗證。

POST /mcp HTTP/1.1
Host: cloudresourcemanager.googleapis.com
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "method": "tools/list",
}

應用實例

Resource Manager 遠端 MCP 伺服器中的 search_projects 工具可讓 AI 代理動態探索及識別您有權存取的所有 Google Cloud 專案,以便在其他工具中執行指令。

這項工具會傳回結構化清單,其中包含專案 ID、專案編號和專案的生命週期狀態。以下是 Resource Manager MCP 伺服器的範例用途:

  • 資源清單和無障礙稽核:列出並彙整您可存取的有效雲端專案。

    使用者提示:「列出我所有進行中的 Google Cloud 專案。」

    代理程式動作:代理程式會將搜尋查詢傳送至 MCP 伺服器,以擷取並顯示您憑證下的所有有效專案摘要清單。

  • 以父項為目標的搜尋:擷取特定資料夾或機構中的專案,縮小要求範圍。

    使用者提示:「Find all projects under Folder 223.」(找出資料夾 223 中的所有專案)。

    代理程式動作:代理程式會使用查詢 parent:folders/223 執行工具呼叫,傳回該行政邊界內的專案清單。

  • 隱含式內容解析:要求資源相關資訊時,不必提供特定專案 ID,代理程式會自動解析內容。

    使用者提示:「Check the status of my 'payment-processor' service.」(檢查我的「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

使用 IAM 拒絕政策控管 MCP 使用情形

身分與存取權管理 (IAM) 拒絕政策可協助您保護遠端 MCP 伺服器。 Google Cloud 設定這些政策,封鎖不必要的 MCP 工具存取權。

舉例來說,您可以根據下列條件拒絕或允許存取:

  • 主體
  • 工具屬性 (例如唯讀)
  • 應用程式的 OAuth 用戶端 ID

詳情請參閱「使用 Identity and Access Management 控制 MCP 使用情形」。

後續步驟