借助 Agent Registry,您可以自动或手动注册 Model Context Protocol (MCP) 服务器,以便开发者和编排器智能体在整个 AI 生态系统中发现和调用标准化工具。
为部署在 Google Kubernetes Engine (GKE) 或 Cloud Run 上的自定义 MCP 服务器启用自动注册后,系统只会发现在启用了 Agent Registry 的治理项目中部署的资源。如需注册部署在单独 Google Cloud 项目中或托管在外部的自定义 MCP 服务器,请参阅注册外部 MCP 服务器。
自动发现 MCP 服务器
Google 和 Google Cloud 远程 MCP 服务器会自动注册并注入到 Agent Registry 中。
在项目中启用 Google Cloud 支持 MCP 的 API(例如 Compute Engine API)后,相应的 MCP 服务器及其工具会立即注册,并可在 Agent Registry 中发现。您无需为这些服务器手动配置或上传工具规范。
位置和条件
当 Agent Registry 自动注册 Google 或 Google Cloud远程 MCP 服务器时,它仅在 global 位置创建 McpServer 资源,而不会在 us-central1 等单个区域中创建。如果服务提供区域级端点 (REP),Agent Registry 会在该 global McpServer 资源的 interfaces 字段中列出这些区域级网址。
由于自动注册的资源仅存在于 global 中,因此在查询服务器或配置 Identity-Aware Proxy (IAP) 访问权限政策时,请注意以下条件:
- 对自动注册的服务器使用
global:在 Agent Registry 中使用--location=global查询服务器或使用--region=global向其应用 IAP 政策时,请指定global位置。如果您指定us-central1等区域,该命令会返回NOT_FOUND错误,因为默认情况下该区域不存在区域级McpServer资源。 - 在某个区域中手动注册以实现数据驻留:如果您需要将注册表元数据保留在特定区域中,请在该区域中手动注册 MCP 服务器及其区域端点网址,然后在该区域中应用 IAP 政策。
如需了解详情,请参阅跨区域和全球位置的治理范围和在区域位置中找不到远程 MCP 服务器。
准备工作
- 设置 Agent Registry。
如需使用本文档中的 Google Cloud CLI 命令,请设置 gcloud CLI 环境。
所需的角色
如需获得在 Agent Registry 中注册 MCP 服务器所需的权限,请让管理员为您授予已启用 Agent Registry 的治理项目的 Agent Registry API Editor (roles/agentregistry.editor) IAM 角色。
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
从 GKE 注册 MCP 服务器
如需注册部署在 GKE 上的自定义 MCP 服务器,请在部署清单中添加所需的 Kubernetes 标签和注解。以下示例展示了配置为自动注册的 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
registry.gke.io/functional-type: "MCP_SERVER"
annotations:
# 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:
labels:
app: my-mcp-server
annotations:
# Agent Identity annotation for identity and access management
iam.gke.io/spiffe-identity-type: agent-identity
spec:
containers:
- name: server
image: gcr.io/PROJECT_ID/my-mcp-server:1.0.0
将 PROJECT_ID 替换为您的 Google Cloud 项目 ID。
如需配置和应用部署清单,请执行以下操作:
在
Deployment清单的metadata.labels中,添加registry.gke.io/functional-type: "MCP_SERVER"标签。在
Deployment清单的metadata.annotations中,通过提供modelcontextprotocol.info/urls和modelcontextprotocol.info/capabilities注解来声明服务器的端点网址和功能详细信息,从而启用 MCP 工具的自动发现功能。在 Pod 模板的
spec.template.metadata.annotations中,通过使用iam.gke.io/spiffe-identity-type: agent-identity注解配置代理身份来启用经过身份验证的通信。将部署清单应用到您的集群。
应用部署后,GKE 会自动尝试从服务器获取工具规范,并将服务器及其工具直接注册到 Agent Registry 中的只读
McpServer发现资源中。Agent Registry 会将您的部署名称用作 MCP 服务器的显示名称。
注册 Cloud Run 中的 MCP 服务器
将自定义 MCP 服务器部署为 Cloud Run 服务时,您可以通过指定 --functional-type=mcp-server 标志来自动注册这些服务器。--functional-type=mcp-server 标志会将 Cloud Run 服务标识为 MCP 服务器,而不是标准的容器化工作负载,从而指示 Cloud Run 向 Agent Registry 注册该服务器。在注册期间,Cloud Run 会自动将服务器的名称和 MCP_SERVER 类型添加到注册表中。
您还可以使用 --identity-type 标志指定身份类型。例如,指定 agent-identity 或 service-account 身份。如果未指定,则工作负载默认使用服务账号身份。
如需在新的或现有的 Cloud Run 服务上配置自动注册,请参阅为 Cloud Run 配置 Gemini Enterprise Agent Platform 功能。如需在 Cloud Run 上部署和保护 MCP 服务器,请参阅在 Cloud Run 上托管 MCP 服务器和对 MCP 服务器进行身份验证。
注册外部 MCP 服务器
如需管理和重复使用外部服务器或自定义 API 提供的工具,您必须手动注册 MCP 服务器。
手动注册 MCP 服务器时,Agent Registry 会注册端点。不过,它不会自动检查服务器以确定哪些工具可用。为了让用户能够发现 MCP 服务器上可用的确切工具,您必须在注册期间上传 toolspec.json 文件,以提供工具规范。
准备工具规范
创建一个 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 服务器并上传工具定义:
控制台
在 Google Cloud 控制台中,前往 Agent Registry:
在项目选择器中,选择您设置 Agent Registry 的 Google Cloud 项目。
选择 MCP 服务器标签页。
点击添加 MCP 服务器。
在 MCP 服务器详细信息面板中,输入显示名称、说明和地理区域。
在工具规范部分中,输入 MCP 服务器端点网址,并粘贴
toolspec.json文件的内容。(可选)点击此面板中的导入工具,从网址导入 MCP 工具。仅当 MCP 服务器的端点网址通过互联网公开托管时,此选项才有效。您无法使用此功能从私有托管的 MCP 服务器导入工具。
点击下一步。
选择 MCP 工具面板会显示 MCP 服务器中的工具列表,其中包含名称和说明。
选择要添加的所有 MCP 工具。您可以按名称或值从列表中过滤工具。
点击保存。
gcloud
您使用的规范标志决定了组件所属的资源集合。如需查看标志与资源集合的完整映射,请参阅 [服务资源和发现资源](/agent-registry/data-model#service-resources)。
使用 gcloud agent-registry services create 命令向工具规范注册 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。名称必须包含 4 到 63 个字符,并且只能包含小写字母、数字和连字符。PROJECT_ID:项目 ID。REGION:注册表区域。DISPLAY_NAME:您要为服务器提供的人类可读名称,例如Custom MCP Server。SERVER_URL:MCP 服务器的端点网址,例如https://api.example.com/mcp。PROTOCOL:端点的协议绑定。 有效值为jsonrpc、http-json或grpc。对于 MCP 服务器,此值通常为jsonrpc。
Terraform
您配置的规范块决定了组件所属的资源集合。如需查看规范与资源集合的完整映射,请参阅 [服务资源和发现资源](/agent-registry/data-model#service-resources)。
如需注册 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 McpServer resource name."
value = google_agent_registry_service.mcp_server.registry_resource
}
替换以下内容:
REGION:注册表区域。SERVER_NAME:您要为 MCP 服务器指定的名称,例如custom-mcp-server。名称必须包含 4 到 63 个字符,并且只能包含小写字母、数字和连字符。DISPLAY_NAME:您要为服务器提供的人类可读名称,例如Custom MCP Server。SERVER_URL:MCP 服务器的端点网址,例如https://api.example.com/mcp。
验证注册
列出、过滤和查看新注册的 MCP 服务器的详细信息。 如需确认 MCP 服务器已成功注册,您可以列出注册表中的服务器。