本文档介绍了如何使用 Memorystore for Redis Cluster 远程 Model Context Protocol (MCP) 服务器连接到 AI 应用,包括 Gemini CLI、ChatGPT、Claude 和您正在开发的自定义应用。 借助 Memorystore for Redis Cluster 远程 MCP 服务器,您可以在支持 AI 的开发环境和 AI 智能体平台中管理 Memorystore for Redis Cluster 中的集群和备份。 当您启用 Memorystore for Redis Cluster API 时,Memorystore for Redis Cluster 远程 MCP 服务器也会启用。
Model Context Protocol (MCP) 规范了大语言模型 (LLM) 以及 AI 应用或 智能体连接到外部数据源的方式。借助 MCP 服务器,您可以使用其工具、资源和提示来执行操作,并从其后端服务获取更新后的数据。
本地 MCP 服务器与远程 MCP 服务器有何区别?
- 本地 MCP 服务器
- 通常在本地机器上运行,并使用标准输入和输出流 (stdio) 在同一设备上的服务之间进行通信。
- 远程 MCP 服务器
- 在服务的基础设施上运行,并向 AI 应用提供 HTTP 端点,以便在 AI MCP 客户端和 MCP 服务器之间进行通信。如需详细了解 MCP 架构,请参阅 MCP 架构。
Google 和 Google Cloud 远程 MCP 服务器
Google 和 Google Cloud 远程 MCP 服务器具有以下 特性和优势:- 简化、集中式发现
- 托管式全球或区域 HTTP 端点
- 细粒度授权
- 使用 Model Armor 保护提示和回答(可选)
- 集中式审核日志记录
如需了解其他 MCP 服务器以及适用于 Google Cloud MCP 服务器的安全 和治理控制措施, 请参阅 Google Cloud MCP 服务器概览。
准备工作
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Enable the Memorystore for Redis Cluster API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
安装 Google Cloud CLI。
-
配置 gcloud CLI 以使用您的联合身份。
如需了解详情,请参阅使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
所需的角色
如需获得使用 Memorystore for Redis Cluster MCP 服务器所需的权限,请让您的管理员为您授予要在其中使用 Memorystore for Redis Cluster MCP 服务器的项目的以下 IAM 角色:
-
进行 MCP 工具调用:
MCP Tool User (
roles/mcp.toolUser) -
在 Memorystore for Redis Cluster 中创建集群:
Redis Admin (
roles/redis.admin) -
获取集群或列出项目中的所有集群:
Redis Viewer (
roles/redis.viewer) -
管理服务使用政策:
Service Usage Admin (
roles/serviceusage.serviceUsageAdmin)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
这些预定义角色包含 使用 Memorystore for Redis Cluster MCP 服务器所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
使用 Memorystore for Redis Cluster MCP 服务器需要以下权限:
-
获取有关服务使用政策的信息:
serviceusage.mcppolicy.get -
更新服务使用政策:
serviceusage.mcppolicy.update -
进行 MCP 工具调用:
mcp.tools.call -
创建集群:
redis.clusters.create -
列出集群:
redis.clusters.list -
获取有关集群的信息:
redis.clusters.get -
克隆集群:
redis.clusters.create -
更新集群:
redis.clusters.update -
备份集群:
redis.clusters.backup -
删除集群:
redis.clusters.delete -
创建用户:
redis.users.create -
列出用户:
redis.users.list -
获取有关用户的信息:
redis.users.get -
更新用户:
redis.users.update -
删除用户:
redis.users.delete
身份验证和授权
Memorystore for Redis Cluster MCP 服务器使用 OAuth 2.0 协议和 Identity and Access Management (IAM) 进行身份验证和授权。支持所有 Google Cloud 身份 用于向 MCP 服务器进行身份验证。
Memorystore for Redis Cluster 远程 MCP 服务器接受 API 密钥。
我们建议为使用 MCP 工具的智能体创建单独的身份,以便控制和监控对资源的访问权限。如需详细了解 身份验证,请参阅向 Google 和 Google Cloud MCP 服务器进行身份验证。
Memorystore for Redis Cluster MCP OAuth 范围
OAuth 2.0 使用范围和凭证来确定经过身份验证的主账号是否有权对资源执行特定操作。如需详细了解 Google 的 OAuth 2.0 范围,请参阅使用 OAuth 2.0 访问 Google API。
Memorystore for Redis Cluster 具有以下 MCP 工具 OAuth 范围:
| 范围 URI | 说明 |
|---|---|
https://www.googleapis.com/auth/redis.read-write
|
创建、列出、备份、更新和删除集群。 |
配置 MCP 客户端以使用 Memorystore for Redis Cluster MCP 服务器
Claude 或 Antigravity 等 AI 应用和智能体可以实例化连接到单个 MCP 服务器的 MCP 客户端。一个 AI 应用可以有多个客户端,这些客户端连接到不同的 MCP 服务器。 如果您的应用未列在 特定于客户端的指南中,则可以使用 以下信息从大多数应用进行连接。
在 AI 应用中,找到添加或连接到远程 MCP 服务器的方法。 对于 Memorystore for Redis Cluster MCP 服务器,请根据需要输入以下信息:
- 服务器名称:Memorystore for Redis Cluster MCP 服务器
- 服务器网址 或 端点:https://redis.googleapis.com/mcp
- 传输:HTTP
- 身份验证详细信息:您可以根据所需的身份验证方式, 输入 Google Cloud 凭证、OAuth 客户端 ID 和密钥,或 代理身份和凭证。如需详细了解身份验证,请参阅 向 Google 和 Google Cloud MCP 服务器进行身份验证。
- OAuth 范围:您在连接到 OAuth 2.0 范围 时要 使用的 OAuth 2.0 范围,该范围用于连接到 Memorystore for Redis Cluster MCP 服务器。
如需了解有关设置和连接到 MCP 服务器的应用专用指南, 请参阅 特定于客户端的指南。
如需了解更通用的指南,请参阅以下资源:
重定向 URI
对于基于 Web 的应用和某些桌面应用,您必须在创建客户端 ID 和密钥以进行身份验证时,将重定向 URI 列入许可名单。 授权服务器使用重定向 URI 将令牌发送到您的应用。应用的文档应指定您必须使用的重定向 URI。自定义重定向 URI 不受支持。
可用工具
如需查看 Memorystore for Redis Cluster MCP 服务器的可用 MCP 工具的详细信息及其说明,请参阅 Memorystore for Redis Cluster MCP 参考文档。
列出工具
使用 MCP Inspector 列出工具,或直接向 Memorystore for Redis Cluster
远程 MCP 服务器发送
tools/list HTTP 请求。tools/list 方法不需要身份验证。
POST /mcp HTTP/1.1
Host: redis.googleapis.com
Content-Type: application/json
{
"jsonrpc": "2.0",
"method": "tools/list",
}
示例应用场景
以下是 Memorystore for Redis Cluster MCP 服务器的示例应用场景:
“为什么要创建启用了 IAM 身份验证的区域集群?”
创建此类集群可消除静态密码,转而使用集中式短期凭据,以实现高度安全的区域工作负载。
Memorystore for Redis Cluster MCP 服务器的 AI 智能体使用 create_cluster MCP 工具创建集群。
“为什么要查看特定区域中的所有有效集群?”
通过列出这些集群,您可以确保资源与当前架构匹配。Memorystore for Redis Cluster MCP 服务器的 AI 智能体使用 list_clusters MCP 工具检索指定区域中集群的格式化列表。
“为什么要从特定区域中的集群检索连接端点和运营元数据?”
您需要此信息进行应用集成和系统维护。
Memorystore for Redis Cluster MCP 服务器的 AI 智能体使用 get_cluster MCP 工具检索有关集群的信息,例如其发现端点、分片数和副本数。
“如何针对数据密集型应用优化 Memorystore for Redis Cluster?”
如需显著提高这些应用的 CPU 容量和内存吞吐量,您可以通过增加集群的分片数来扩缩集群。Memorystore for Redis Cluster MCP 服务器的 AI 智能体使用 update_cluster MCP 工具更新集群的分片数。
“如何保护数据免受集群或其所在区域可能发生的故障的影响?”
创建集群的备份。如果发生区域或集群故障,您可以将数据恢复到新集群以恢复运营。Memorystore for Redis Cluster MCP 服务器的 AI 智能体使用 backup_cluster MCP 工具创建集群的备份。
可选的安全配置
由于 MCP 工具可执行各种操作,因此 MCP 会引发新的安全风险和注意事项。为了最大限度地降低这些风险并进行管理, Google Cloud 提供了默认设置和可自定义的 政策,用于控制 MCP 工具在您的 Google Cloud 组织或项目中的使用。
如需详细了解 MCP 安全性和治理,请参阅 AI 安全性。
使用 Model Armor
Model Armor 是一项旨在增强 AI 应用安全性和 安全性的 Google Cloud 服务。它通过主动筛选 LLM 提示和回答来防范各种风险,并支持 Responsible AI 实践。无论您是在云环境还是外部云服务提供商中部署 AI,Model Armor 都能帮助您防止恶意输入、验证内容安全性、保护敏感数据、保持合规性,并在各种 AI 环境中以一致的方式实施 AI 安全政策。
当 Model Armor 启用且 日志记录也启用时,Model Armor 会记录整个 载荷。这可能会在日志中公开敏感信息。
将 MCP 请求路由到 Model Armor
Model Armor 在 某些区域提供。当 Model Armor 启用且您在 Model Armor 不支持的司法管辖区中使用 MCP 服务器时,调用的路由行为可能因 MCP 服务器而异,并且可能会违反使用中和传输中数据的数据驻留合规性。如需详细了解各个 MCP 服务器的行为 ,请参阅 Model Armor 支持的产品。启用 Model Armor
您必须先启用 Model Armor API,然后才能使用 Model Armor。
控制台
gcloud
在开始之前,请使用 Google Cloud CLI 和 Model Armor API 按照以下步骤操作:
安装 Google Cloud CLI,然后 使用联合身份登录 gcloud CLI。 登录后, 运行以下命令来初始化 Google Cloud CLI:
gcloud init-
运行以下命令,为 Model Armor 服务设置 API 端点。
gcloud config set api_endpoint_overrides/modelarmor "https://modelarmor.LOCATION.rep.googleapis.com/"
将
LOCATION替换为您要使用 Model Armor 的区域。
为 Google 和 Google Cloud 远程 MCP 服务器配置保护
为了帮助保护 MCP 工具调用和响应,您可以使用 Model Armor 下限设置。下限设置定义了适用于整个项目的最低安全过滤条件。此配置会将一组一致的过滤条件应用于项目中的所有 MCP 工具调用和响应。
设置启用了 MCP 清理的 Model Armor 下限设置。如需了解详情,请参阅配置 Model Armor 下限 设置。
请参阅以下示例命令:
gcloud model-armor floorsettings update \ --full-uri='projects/PROJECT_ID/locations/global/floorSetting' \ --enable-floor-setting-enforcement=TRUE \ --add-integrated-services=GOOGLE_MCP_SERVER \ --google-mcp-server-enforcement-type=INSPECT_AND_BLOCK \ --enable-google-mcp-server-cloud-logging \ --malicious-uri-filter-settings-enforcement=ENABLED \ --add-rai-settings-filters='[{"confidenceLevel": "MEDIUM_AND_ABOVE", "filterType": "DANGEROUS"}]'
请将 PROJECT_ID 替换为您的 Google Cloud 项目 ID。
请注意以下设置:
INSPECT_AND_BLOCK:一种强制执行类型,用于 检查 Google MCP 服务器的内容,并屏蔽与 过滤条件匹配的提示和回答。ENABLED:用于启用过滤条件或 强制执行的设置。MEDIUM_AND_ABOVE:Responsible AI - Dangerous 过滤条件设置的置信度。您可以修改此设置, 但较低的值可能会导致更多误报。如需了解详情,请参阅 Model Armor 置信度。
停用使用 Model Armor 扫描 MCP 流量
如需阻止 Model Armor 根据项目的下限设置自动扫描进出 Google MCP 服务器的流量,请运行以下命令:
gcloud model-armor floorsettings update \
--full-uri='projects/PROJECT_ID/locations/global/floorSetting' \
--remove-integrated-services=GOOGLE_MCP_SERVER
将 PROJECT_ID 替换为 Google Cloud 项目
ID。Model Armor 不会自动将此项目的下限设置中定义的规则应用于任何 Google MCP 服务器流量。
Model Armor 下限设置和常规配置不仅会影响 MCP。由于 Model Armor 与 Vertex AI 等服务集成,因此您对下限设置所做的任何更改都会影响所有集成服务的流量扫描和安全行为,而不仅仅是 MCP。
使用 IAM 政策控制 MCP 的使用
Identity and Access Management (IAM) 拒绝政策 和 允许政策 可帮助您 保护 Google Cloud Google MCP 服务器。
您可以组合多个条件来构建自定义安全和治理政策,方法是根据以下条件允许或拒绝访问:
- 主账号。
- 工具属性,例如只读属性。
- 服务名称或工具名称。
- 应用的 OAuth 客户端 ID。
如需了解详情,请参阅 使用 Identity and Access Management 控制 MCP 的使用。
后续步骤
- 详细了解 Google Cloud MCP 服务器。