Agent Registry 通过注册和管理 Model Context Protocol (MCP) 服务器端点及其公开的 特定 工具,充当集中式目录。
本文档介绍了如何在 Agent Registry 中注册 MCP 服务器,以及如何管理其工具规范。
自动发现 Google Cloud MCP 服务器
Google 官方 MCP 服务器和 Google Cloud 远程 MCP 服务器会自动注册 并提取到 Agent Registry 中。Google 官方 MCP 服务器和 Google Cloud 远程 MCP 服务器的可用性列在 MCP 服务器文档的支持的产品中。Google Cloud
当您在项目中启用受支持的 Google Cloud API(例如 Compute Engine API)时,相应的 MCP 服务器及其工具会立即注册,并可在 Agent Registry 中被发现。您无需为这些服务器手动配置或上传工具规范。
从 GKE 注册 MCP 服务器
您可以通过将 registry.gke.io/functional-type: "MCP_SERVER" 标签添加到
GKE 部署中,为部署在
Google Kubernetes Engine (GKE)
上的自定义 MCP 服务器配置自动注册。
registry.gke.io/functional-type: "MCP_SERVER"如需让 Agent Registry 执行内省扫描并发现您的 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 文件来提供工具规范。
准备工作
在开始之前,请设置 Agent Registry。您需要 项目 ID 才能执行 这些任务。
如需使用本文档中的 gcloud CLI 命令,请确保您已 设置 Google Cloud CLI 环境。
所需的角色
如需获得在 Agent Registry 中手动注册 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 服务器并上传工具定义:
控制台
在 Google Cloud 控制台中,前往 Agent Registry:
在项目选择器中,选择您在其中 设置 Agent Registry的 Google Cloud 项目。
选择 MCP 服务器 标签页。
点击添加 MCP 服务器 。
在 MCP 服务器详细信息 面板中,输入显示名称、说明和地理区域。
在工具规范 部分中,输入 MCP 服务器端点网址,然后粘贴
toolspec.json文件的内容。(可选)点击此面板中的导入工具 ,从网址导入 MCP 工具。仅当 MCP 服务器的端点网址在互联网上公开托管时,此选项才有效。您无法使用此功能从私下托管的 MCP 服务器导入工具。
点击下一步 。
选择 MCP 工具 面板会显示 MCP 服务器中的工具列表,其中包含名称和说明。
选择您要包含的所有 MCP 工具。您可以按名称或值过滤列表中的工具。
点击保存 。
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:端点的协议绑定。 有效值为JSONRPC、HTTP_JSON或GRPC。对于 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 = "NO_SPEC"
}
}
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 服务器已成功注册,您可以 列出注册表中的服务器。