使用 Resource Manager 遠端 MCP 伺服器

本文說明如何使用 Resource Manager 遠端 Model Context Protocol (MCP) 伺服器,連結 AI 應用程式,包括 Antigravity、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 權限無法用於限制這個伺服器的工具存取權。

事前準備

    登入 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, 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.

    Enable the API

    Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

    gcloud init

    If 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

    • 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, 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.

    Enable the API

    Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

    gcloud init

    If 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) 進行驗證和授權。所有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 或 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 代理可透過 Resource Manager 遠端 MCP 伺服器中的 search_projects 工具,動態探索及識別您有權存取的所有 Google Cloud 專案,以便在其他工具中執行指令。

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

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

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

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

  • 指定上層搜尋:擷取特定資料夾或組織中的專案,縮小要求範圍。

    使用者提示:「找出資料夾 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。

後續步驟