注册 MCP 服务器

Agent Registry 通过注册和管理 Model Context Protocol (MCP) 服务器端点及其公开的特定工具,充当集中式目录。

本文档介绍了如何注册 MCP 服务器,以及如何在 Agent Registry 中管理其工具规范。

自动发现 Google Cloud MCP 服务器

官方 Google 和 Google Cloud 远程 MCP 服务器会自动注册并提取到 Agent Registry 中。Google Cloud MCP 服务器文档的支持的产品中列出了可用的 Google 和 Google Cloud 远程 MCP 服务器。

在项目中启用受支持的 Google Cloud API(例如 Compute Engine API)后,相应的 MCP 服务器及其工具会立即注册并可在代理注册表中发现。您无需手动配置或上传这些服务器的工具规范。

Google 管理的 MCP 服务器的范围和绑定

由 Google 管理的远程 MCP 服务器会自动注册到您项目的 global 位置。由于这些内置的 Google 服务器位于全球各地,因此您必须通过指定 --region=global 标志,在全局范围内为它们应用任何 Identity and Access Management (IAM) 绑定。这些全局远程 MCP 服务器不支持区域级 IAM 绑定(例如 --region=us-central1),并且会返回 NOT_FOUND 错误。

注册来自 GKE 的 MCP 服务器

您可以向 GKE 部署添加 registry.gke.io/functional-type: "MCP_SERVER" 标签,为部署在 Google Kubernetes Engine (GKE) 上的自定义 MCP 服务器配置自动注册。

为了让 Agent Registry 执行自省扫描并发现您的 MCP 工具,您的 Deployment 还必须包含声明服务器端点网址和能力详细信息的注解。此外,您还可以使用 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 环境

所需的角色

如需获得在代理注册表中手动注册 MCP 服务器所需的权限,请让管理员向您授予项目的 Agent Registry API Editor (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 项目,您在其中设置 Agent Registry

  3. 选择 MCP 服务器标签页。

  4. 点击添加 MCP 服务器

  5. 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 服务器已成功注册,您可以列出注册表中的服务器