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 工具,您的部署还必须包含声明服务器端点网址和功能详细信息的注释。
以下示例展示了使用这些配置的 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:
labels:
app: my-mcp-server
spec:
containers:
- name: server
image: gcr.io/my-project/my-mcp-server:1.0.0
应用部署时,GKE 会自动尝试从服务器获取工具规范,并将工具直接注册到 Agent Registry 数据模型中。
注册来自 Cloud Run 的 MCP 服务器
您可以在部署自定义 MCP 服务器时指定 --functional-type=mcp-server 标志,以配置自动注册功能,从而在 Cloud Run 中部署这些服务器。
当您部署具有 --functional-type=mcp-server 的 Cloud Run 服务时,该服务会注册到 Agent Registry 中的 MCP 服务器目录。
您还可以使用 --identity-type 标志指定身份类型。例如,指定 agent-identity 或 service-account 身份。如果未指定,工作负载默认使用服务账号身份。
如需了解如何在 Cloud Run 中部署 MCP 服务器服务,请参阅为 Cloud Run 配置 Agent Platform 功能。
如需了解详情,请参阅在 Cloud Run 上托管 MCP 服务器和对 MCP 服务器进行身份验证。
自动注册仅发现部署在同一Google Cloud 项目中的资源。
注册外部 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 服务器并上传工具定义:
控制台
在 Google Cloud 控制台中,前往 Agent Registry:
在项目选择器中,选择 Google Cloud 项目,您在其中设置 Agent Registry。
选择 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 = "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 服务器已成功注册,您可以列出注册表中的服务器。