使用遠端 MCP 伺服器,從 AI 應用程式連線至 Memorystore for Redis Cluster

本文說明如何使用 Memorystore for Redis Cluster 遠端 Model Context Protocol (MCP) 伺服器,連結 AI 應用程式,包括 Antigravity、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 伺服器
通常在本機電腦上執行,並使用標準輸入內容和輸出串流 (stdio),在同一部裝置上的服務之間通訊。
遠端 MCP 伺服器
在服務的基礎架構上執行,並為 AI 應用程式提供 HTTP 端點,以便 AI MCP 用戶端與 MCP 伺服器之間通訊。如要進一步瞭解 MCP 架構,請參閱「MCP 架構」。

無狀態核心

在 MCP 2026-07-28 版中,MCP 從雙向有狀態通訊協定變更為無狀態通訊協定。每項 MCP 要求都包含自我描述,並可使用標頭轉送。由於每個要求都包含 HTTP 標頭或 _meta 參數中所需的所有資訊,因此不需要 initialize/initialized 握手或 Mcp-Session-Id。MCP 伺服器可透過多來回要求 (MRTR),要求工具所需的額外資訊。

為協助轉送及處理要求,而不剖析要求主體,必須提供部分 MCP 標頭,包括:

  • MCP 規格要求的標頭,例如通訊協定版本標頭和標準要求標頭。
  • MCP 伺服器定義的自訂標頭。這些標頭會使用 x-mcp-header 屬性,從工具的輸入結構定義鏡像至 HTTP 標頭。舉例來說,MCP 伺服器可能會定義自訂標頭,指定 Google Cloud 區域或專案 ID。

如要進一步瞭解 MCP 架構,請參閱 MCP 2026-07-28 版規格和主要異動。

Google 和 Google Cloud 遠端 MCP 伺服器

Google 和 Google Cloud 遠端 MCP 伺服器具有下列功能和優點:

  • 簡化集中探索
  • 代管的全域或區域 HTTP 端點
  • 精細授權
  • 選用 Model Armor 保護提示詞和回覆
  • 集中化稽核記錄

如要瞭解其他 MCP 伺服器,以及 Google Cloud MCP 伺服器的安全性和管理控制項,請參閱「Google Cloud MCP 伺服器總覽」。

事前準備

  1. 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎 建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
  2. 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

  3. 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.

  4. Enable the Memorystore for Redis Cluster API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. 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

  9. 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.

  10. Enable the Memorystore for Redis Cluster API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  11. Install the Google Cloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init

必要的角色

如要取得使用 Memorystore for Redis Cluster MCP 伺服器所需的權限,請要求管理員在您要使用 Memorystore for Redis Cluster MCP 伺服器的專案中,授予下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

這些預先定義的角色具備使用 Memorystore for Redis Cluster MCP 伺服器所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

必須具備下列權限,才能使用 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 伺服器

AI 應用程式和代理 (例如 Claude 或 Antigravity) 可例項化 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 和密鑰,或代理身分和憑證。如要進一步瞭解驗證,請參閱「向 MCP 伺服器驗證」。
  • OAuth 範圍:連線至 Memorystore for Redis Cluster MCP 伺服器時,要使用的 OAuth 2.0 範圍。

如需設定及連線至 MCP 伺服器的應用程式專屬指引,請參閱「用戶端專屬指引」。

如需一般指引,請參閱下列資源:

重新導向 URI

如果是網頁式應用程式和部分電腦應用程式,您必須在建立用於驗證的用戶端 ID 和密鑰時,將重新導向 URI 加入許可清單。授權伺服器會使用重新導向 URI,將權杖傳送至應用程式。應用程式說明文件應指定您必須使用的重新導向 URI。不支援自訂重新導向 URI。

可用的工具

如要查看 Memorystore for Redis Cluster MCP 伺服器的可用 MCP 工具詳細資料和說明,請參閱「Memorystore for Redis Cluster MCP 參考資料」。

清單工具

使用 MCP 檢查器列出工具,或直接傳送 tools/list HTTP 要求至 Memorystore for Redis Cluster 遠端 MCP 伺服器。tools/list 方法不需要驗證。

curl -X POST https://redis.googleapis.com/TOOLSET_ENDPOINT \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'MCP-Protocol-Version: MCP_PROTOCOL_VERSION' \
    -H 'Mcp-Method: tools/list' \
    -d '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "tools/list",
      "params": {
        "_meta": {
          "io.modelcontextprotocol/protocolVersion": "MCP_PROTOCOL_VERSION",
          "io.modelcontextprotocol/clientCapabilities": {
            "extensions": {
              "io.modelcontextprotocol/ui": {
                "mimeTypes": ["text/html;profile=mcp-app"]
              }
            }
          }
        }
      }
    }'

更改下列內容:

  • TOOLSET_ENDPOINT:服務名稱後方的 MCP 端點其餘部分。舉例來說,如果是 Memorystore for Redis Cluster,這可能是 mcp/toolset-name。
  • MCP_PROTOCOL_VERSION:MCP 通訊協定版本。例如:2026-07-28。## 應用實例

以下是 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 工具擷取叢集相關資訊,例如探索端點、shard 數量和副本數量。

「如何針對資料密集型應用程式,最佳化 Memorystore for Redis Cluster?」

如要大幅提高這些應用程式的 CPU 容量和記憶體處理量,可以增加叢集的 shard 數量,藉此擴充叢集。Memorystore for Redis Cluster MCP 伺服器的 AI 代理會使用 update_cluster MCP 工具,更新叢集的 shard 數量。

「如何保護資料,避免叢集或所在區域發生故障?」

建立叢集備份。如果發生區域或叢集故障,您可以將資料還原至新叢集,以便恢復作業。Memorystore for Redis Cluster MCP 伺服器的 AI 代理會使用 backup_cluster MCP 工具建立叢集備份。

選用安全性和安全防護設定

MCP 工具可執行的動作繁多,因此會帶來新的安全風險和考量。為盡可能降低及管理這些風險,Google Cloud 提供預設設定和可自訂的政策,控管 Google Cloud組織或專案中的 MCP 工具使用情形。

如要進一步瞭解 MCP 安全性和管理,請參閱「AI 安全性」。

使用 Model Armor

Model Armor 是一項Google Cloud 服務,可提高 AI 應用程式的安全性。這項服務會主動篩選 LLM 提示詞和回覆,防範各種風險,並確保採行負責任的 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。

控制台

  1. 啟用 Model Armor API (如果尚未啟用)。

    啟用 API 所需的角色

    您必須具備 serviceusage.services.enable 權限,才能啟用 API。如果您建立了專案,可能已透過「擁有者」角色 (roles/owner) 取得這項權限。否則,您可以透過「Service Usage 管理員」角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。

    啟用 API

  2. 選取要啟用 Model Armor 的專案。

gcloud

開始之前,請按照下列步驟,搭配使用 Google Cloud CLI 和 Model Armor API:

  1. 在 Google Cloud 控制台啟用 Cloud Shell。

    啟用 Cloud Shell

    Google Cloud 控制台底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。Cloud Shell 是已安裝 Google Cloud CLI 的殼層環境,並已設定適用於您目前專案的值。工作階段可能要幾秒鐘的時間才能初始化。

  2. 執行下列指令,設定 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 工具呼叫和回覆,套用一組一致的篩選器。

設定 Model Armor 底限,並啟用 MCP 清理功能。詳情請參閱「設定 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:負責任 AI - 危險篩選器設定的信心水準。您可以修改這項設定,但較低的值可能會導致更多偽陽性。詳情請參閱「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 使用情形」。

後續步驟