註冊 MCP 伺服器

Agent Registry 會註冊及管理 Model Context Protocol (MCP) 伺服器端點,以及這些端點公開的特定工具,做為集中式目錄。

本文說明如何註冊 MCP 伺服器,以及如何在 Agent Registry 中管理工具規格。

自動探索 Google Cloud MCP 伺服器

系統會自動註冊官方 Google 和 Google Cloud 遠端 MCP 伺服器,並將其資料匯入 Agent Registry。如要查看可用的 Google 和 Google Cloud 遠端 MCP 伺服器,請參閱Google Cloud MCP 伺服器說明文件中的「支援的產品」

在專案中啟用支援的 Google Cloud API (例如 Compute Engine API) 時,系統會立即註冊對應的 MCP 伺服器及其工具,並在 Agent Registry 中提供探索功能。您不必手動設定或上傳這些伺服器的工具規格。

Google 代管 MCP 伺服器的範圍和繫結

Google 代管的遠端 MCP 伺服器會自動在專案位置註冊。global由於這些內建 Google 伺服器位於全球各地,您必須指定 --region=global 標記,在全域範圍套用這些伺服器的任何 Identity and Access Management (IAM) 繫結。這些全域遠端 MCP 伺服器不支援區域 IAM 繫結 (例如 --region=us-central1),且會傳回 NOT_FOUND 錯誤。

從 GKE 註冊 MCP 伺服器

如要為部署在 Google Kubernetes Engine (GKE) 上的自訂 MCP 伺服器設定自動註冊功能,請將 registry.gke.io/functional-type: "MCP_SERVER" 標籤新增至 GKE 部署作業。

如要讓代理程式登錄執行內省掃描並探索 MCP 工具,部署作業也必須包含註解,宣告伺服器的端點網址和功能詳細資料。此外,請使用 iam.gke.io/spiffe-identity-type: agent-identity 註解設定 Workload Identity,協助啟用安全驗證通訊。

以下範例顯示使用這些設定的 GKE MCP 伺服器部署資訊清單。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-mcp-server
  labels:
    # GKE takes this label and registers the deployment as an MCP server to the registry
    registry.gke.io/functional-type: "MCP_SERVER"
  annotations:
    # A list of endpoint URLs where the GKE controller can access this MCP server
    modelcontextprotocol.info/urls: |
      - https://my-mcp-server.default.svc.cluster.local/mcp
    # Defines structural capabilities for the MCP server card
    modelcontextprotocol.info/capabilities: |
      card:
        endpoint: "/mcp"
        protocol: "HTTP"
spec:
  selector:
    matchLabels:
      app: my-mcp-server
  template:
    metadata:
      annotations:
        # Workload Identity annotation for identity and access management
        iam.gke.io/spiffe-identity-type: agent-identity
      labels:
        app: my-mcp-server
    spec:
      containers:
      - name: server
        image: gcr.io/my-project/my-mcp-server:1.0.0

套用部署作業時,GKE 會自動嘗試從伺服器取得工具規格,並直接將工具註冊到 Agent Registry 資料模型中。

註冊外部 MCP 伺服器

如要管理及重複使用外部伺服器或自訂 API 提供的工具,您必須明確註冊 MCP 伺服器。

手動註冊 MCP 伺服器時,Agent Registry 會註冊端點。不過,這項功能不會自動內省伺服器,判斷可用的工具。如要讓使用者瞭解 MCP 伺服器上提供的確切工具,您必須在上傳 toolspec.json 檔案時提供工具規格。

事前準備

開始之前,請先設定代理程式登錄。您需要專案 ID 才能執行這些工作。

如要使用本文中的 gcloud CLI 指令,請務必設定 Google Cloud CLI 環境

必要的角色

如要取得在 Agent Registry 中手動註冊 MCP 伺服器所需的權限,請要求管理員授予專案的Agent Registry API 編輯者 (roles/agentregistry.editor) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

準備工具規格

建立 toolspec.json 檔案,列出伺服器提供的工具。這個規格檔案的大小上限為 10 KB。

JSON 檔案必須符合工具結構定義的 MCP 規格,例如:

{
  "tools": [
    {
      "name": "get_customer_info",
      "description": "Retrieves customer details from the database.",
      "annotations": {
        "title": "Get Customer Info",
        "readOnlyHint": true,
        "idempotentHint": true
      }
    },
    {
      "name": "create_support_ticket",
      "description": "Creates a new support ticket in the issue tracking system.",
      "annotations": {
        "title": "Create Support Ticket",
        "destructiveHint": true,
        "idempotentHint": false,
        "openWorldHint": true
      }
    }
  ]
}

如需詳細的結構規定,請參閱 JSON 結構定義REST 參考資料

註冊伺服器和工具

同時註冊 MCP 伺服器並上傳工具定義:

控制台

  1. 前往 Google Cloud 控制台的「Agent Registry」

    前往 Agent Registry

  2. 在專案選擇工具中,選取 Google Cloud 您設定代理程式登錄的專案。

  3. 選取「MCP 伺服器」分頁標籤。

  4. 按一下「新增 MCP 伺服器」

  5. 在「MCP server details」(MCP 伺服器詳細資料) 面板中,輸入顯示名稱、說明和地理區域。

  6. 在「工具規格」部分,輸入 MCP 伺服器端點網址,並貼上 toolspec.json 檔案的內容。

    (選用) 按一下這個面板中的「匯入工具」,從網址匯入 MCP 工具。只有在 MCP 伺服器的端點網址透過網際網路公開代管時,這個選項才會生效。您無法使用這項功能,從私有代管的 MCP 伺服器匯入工具。

  7. 點選「下一步」

    「選取 MCP 工具」面板會顯示 MCP 伺服器中的工具清單,以及名稱和說明。

  8. 選取要納入的所有 MCP 工具。您可以依名稱或值篩選清單中的工具。

  9. 按一下 [儲存]

gcloud

使用工具規格註冊 MCP 伺服器:

gcloud agent-registry services create SERVER_NAME \
  --project=PROJECT_ID \
  --location=REGION \
  --display-name="DISPLAY_NAME" \
  --mcp-server-spec-type=tool-spec \
  --mcp-server-spec-content=@toolspec.json \
  --interfaces=url=SERVER_URL,protocolBinding=PROTOCOL

更改下列內容:

  • SERVER_NAME:您要授予 MCP 伺服器的名稱,例如 custom-mcp-server
  • PROJECT_ID:專案 ID。
  • REGION:登錄檔區域。
  • DISPLAY_NAME:您要為伺服器命名的人類可讀名稱,例如 Custom MCP Server
  • SERVER_URL:MCP 伺服器的端點網址,例如 https://api.example.com/mcp
  • PROTOCOL:端點的通訊協定繫結。有效值為 jsonrpchttp-jsongrpc。如果是 MCP 伺服器,這個值通常是 jsonrpc

Terraform

如要註冊 MCP 伺服器並指定其工具,請使用 mcp_server_spec 區塊設定 google_agent_registry_service 資源:

resource "google_agent_registry_service" "mcp_server" {
  location     = "REGION"
  service_id   = "SERVER_NAME"
  display_name = "DISPLAY_NAME"
  description  = "An external MCP server registered using Terraform."

  interfaces {
    url              = "SERVER_URL"
    protocol_binding = "JSONRPC"
  }

  mcp_server_spec {
    type    = "TOOL_SPEC"
    content = file("toolspec.json")
  }
}

output "server_resource_name" {
  description = "The generated read-only Server resource name."
  value       = google_agent_registry_service.mcp_server.registry_resource
}

更改下列內容:

  • REGION:登錄檔區域。
  • SERVER_NAME:您要授予 MCP 伺服器的名稱,例如 custom-mcp-server
  • DISPLAY_NAME:您要為伺服器命名的人類可讀名稱,例如 Custom MCP Server
  • SERVER_URL:MCP 伺服器的端點網址,例如 https://api.example.com/mcp

驗證註冊

列出、篩選及查看新註冊 MCP 伺服器的詳細資料。 如要確認 MCP 伺服器是否已成功註冊,可以列出登錄檔中的伺服器