使用 Resource Manager 远程 MCP 服务器

本文档介绍了如何使用 Resource Manager 远程 Model Context Protocol (MCP) 服务器连接到 AI 应用,包括 Gemini CLI、ChatGPT、Claude 和您正在开发的自定义应用。借助 Resource Manager 远程 MCP 服务器,您可以搜索并识别您拥有必要权限的所有项目,确保在尝试进行更具体的资源配置之前拥有正确的标识符。 Google Cloud

该工具会返回一个结构化列表,其中包含项目 ID、项目编号和项目的生命周期状态。 当您启用 Resource Manager API 时,系统会启用 Resource Manager 远程 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 服务器概览

准备工作

    登录您的 Google Cloud 账号。如果您是 Google Cloud新手, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。

    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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    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.

    Verify that billing is enabled for your Google Cloud project.

    Enable the Cloud Resource Manager API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

    安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI: 初始化 Google Cloud CLI:

    gcloud init

    如果您使用的是外部身份提供方 (IdP),则必须先 使用联合身份登录 gcloud CLI

    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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    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.

    Verify that billing is enabled for your Google Cloud project.

    Enable the Cloud Resource Manager API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

    安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI: 初始化 Google Cloud CLI:

    gcloud init

    如果您使用的是外部身份提供方 (IdP),则必须先 使用联合身份登录 gcloud CLI

身份验证和授权

Resource Manager 远程 MCP 服务器使用 OAuth 2.0 协议和 Identity and Access Management (IAM) 进行身份验证和授权。支持所有 Google Cloud 身份 用于向 MCP 服务器进行身份验证。

Resource Manager MCP 服务器使用 OAuth 2.0 协议和 Identity and Access Management (IAM) 进行身份验证和授权。支持所有 Google Cloud 身份 用于向 MCP 服务器进行身份验证。

Resource Manager MCP 服务器不接受使用 API 密钥进行身份验证。

我们建议为使用 MCP 工具的智能体创建单独的身份,以便控制和监控对资源的访问权限。如需详细了解 身份验证,请参阅向 MCP 服务器进行身份验证

Resource Manager MCP OAuth 范围

OAuth 2.0 使用范围和凭证来确定经过身份验证的主账号是否有权对资源执行特定操作。如需详细了解 Google 的 OAuth 2.0 范围,请参阅 使用 OAuth 2.0 访问 Google APIs

Resource Manager 具有以下 MCP 工具 OAuth 范围:

gcloud CLI 的范围 URI 说明
https://www.googleapis.com/auth/cloudresourcemanager.read-only 仅允许访问读取数据。
https://www.googleapis.com/auth/cloudresourcemanager.read-write 允许访问读取和修改数据。

在工具调用期间访问的资源可能需要其他范围。如需查看 Resource Manager 所需的范围列表,请参阅 Resource Manager API

配置 MCP 客户端以使用 Resource Manager MCP 服务器

Claude 或 Gemini CLI 等 AI 应用和智能体可以实例化连接到单个 MCP 服务器的 MCP 客户端。AI 应用可以有多个客户端,这些客户端连接到不同的 MCP 服务器。如需连接到远程 MCP 服务器,MCP 客户端必须至少知道远程 MCP 服务器的网址。

在 AI 应用中,找到连接到远程 MCP 服务器的方法。系统会提示您输入有关服务器的详细信息,例如其名称和网址。

对于 Resource Manager MCP 服务器,请根据需要输入以下内容:

  • 服务器名称:Resource Manager MCP 服务器
  • 服务器网址端点:https://cloudresourcemanager.googleapis.com/mcp
  • 传输:HTTP
  • 身份验证详细信息:您可以根据所需的身份验证方式,输入 Google Cloud 凭证、OAuth 客户端 ID 和密钥,或代理身份和凭证。如需详细了解 身份验证,请参阅向 MCP 服务器进行身份验证
  • OAuth 范围:您在连接到 Resource Manager MCP 服务器时要使用的 OAuth 2.0 范围

如需查看特定于主机的指导,请参阅以下内容:

如需更一般的指导,请参阅以下资源:

可用的工具

如需查看 Resource Manager MCP 服务器的可用 MCP 工具的详细信息及其说明,请参阅 Resource Manager MCP 参考文档

列出工具

使用 MCP 检查器 列出工具,或直接向 Resource Manager 远程 MCP 服务器发送 tools/list HTTP 请求。tools/list 方法不需要进行身份验证。

POST /mcp HTTP/1.1
Host: cloudresourcemanager.googleapis.com
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "method": "tools/list",
}

示例应用场景

借助 Resource Manager 远程 MCP 服务器中的 search_projects 工具,AI 智能体可以动态发现并识别您拥有必要权限的所有 Google Cloud 项目,以便在其他工具中执行命令。

该工具会返回一个结构化列表,其中包含项目 ID、项目编号和项目的生命周期状态。以下是 Resource Manager MCP 服务器的示例应用场景:

  • 资源清单和无障碍功能审核:列出并汇总您可以访问的活跃 Cloud 项目。

    用户提示:“列出我的所有活跃 Google Cloud 项目。”

    智能体操作:智能体向 MCP 服务器发送搜索查询,以检索并显示您的凭据下的所有活跃项目的汇总列表。

  • 基于父项的定向搜索:检索位于 特定文件夹或组织内的项目,以缩小请求的范围。

    用户提示:“查找文件夹 223 下的所有项目。”

    智能体操作:智能体使用查询 parent:folders/223 执行工具调用,以返回该管理边界内的项目列表。

  • 隐式上下文解析:当您请求有关资源的 信息但未提供特定项目 ID 时,智能体可以自动解析上下文。

    用户提示:“检查我的‘payment-processor’服务的状态。”

    智能体操作:智能体识别出 Cloud Run 工具缺少 project_id。它使用 search_projects 工具查找名称中包含 payment 的项目 ,识别可能的项目(例如 payment-prod-123),并在继续之前要求您确认。

  • 特定于环境的发现:您无需离开聊天 聊天界面 ,即可找到按特定环境或组织结构过滤的项目。

    用户提示:“在暂存环境中,我可以访问哪些项目?”

    智能体操作:智能体对您有权查看的所有标记为或命名为 staging 的项目执行搜索操作,并返回特定项目 ID。

自定义 LLM 行为

search_projects 工具用途广泛,但 LLM 可能并不总是知道何时 查询您的 Google Cloud 层次结构。如需在特定场景中调用该工具,请在 Markdown 文件(例如 ~/.gemini/GEMINI.md 或项目级 AGENTS.md)中提供自定义上下文。

使用 IAM 拒绝政策控制 MCP 的使用

Identity and Access Management (IAM) 拒绝政策 有助于 保护 Google Cloud 远程 MCP 服务器。配置这些政策以阻止不必要的 MCP 工具访问。

例如,您可以根据以下条件拒绝或允许访问:

  • 正文
  • 工具属性,例如只读
  • 应用的 OAuth 客户端 ID

如需了解详情,请参阅使用 Identity and Access Management 控制 MCP 的使用

后续步骤