使用 Managed Service for Apache Spark MCP 伺服器

本文說明如何使用 Managed Service for Apache Spark 遠端 Model Context Protocol (MCP) 伺服器,連線至 AI 應用程式,包括 Gemini CLI、ChatGPT、Claude 和您開發的自訂應用程式。透過 Managed Service for Apache Spark 遠端 MCP 伺服器,您可以從 AI 應用程式執行叢集作業,例如建立叢集、提交工作或建立自動調度政策。啟用 Managed Service for Apache Spark API 時,系統會啟用 Managed Service for Apache Spark 遠端 MCP 伺服器。

Model Context Protocol (MCP) 規範大型語言模型 (LLM) 和 AI 應用程式/代理程式連結外部資料來源的標準方式。MCP 伺服器可讓您使用工具、資源和提示,從後端服務採取行動及取得更新資料。

本機和遠端 MCP 伺服器有何不同?

本機 MCP 伺服器
通常在本機電腦上執行,並使用標準輸入和輸出串流 (stdio),在同一部裝置上的服務之間進行通訊。
遠端 MCP 伺服器
在服務的基礎架構上執行,並為 AI 應用程式提供 HTTP 端點,供 AI MCP 用戶端與 MCP 伺服器之間的通訊。如要進一步瞭解 MCP 架構,請參閱 MCP 架構

如要瞭解 Managed Service for Apache Spark 本機 MCP 伺服器,請參閱「MCP Toolbox for Databases 簡介」。

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. Verify that you have the permissions required to complete this guide.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Managed Service for Apache Spark, Cloud Storage, and BigQuery APIs.

    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 APIs

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

  7. Verify that you have the permissions required to complete this guide.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Managed Service for Apache Spark, Cloud Storage, and BigQuery APIs.

    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 APIs

必要的角色

如要執行本頁的範例,您必須具備特定的 IAM 角色。視機構政策而定,系統可能已授予這些角色。如要檢查角色授予情形,請參閱「是否需要授予角色?」一節。

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

使用者角色

如要取得使用 Managed Service for Apache Spark 所需的權限,請要求管理員授予您下列 IAM 角色:

如要取得使用 Managed Service for Apache Spark MCP 伺服器所需的權限,請要求管理員授予您專案的下列 IAM 角色:

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

所需權限

如要使用 Managed Service for Apache Spark MCP 伺服器,您必須具備下列權限:

  • 發出 MCP 工具呼叫: mcp.tools.call

服務帳戶角色

為確保 Compute Engine 預設服務帳戶具備建立叢集及提交工作所需的權限,請要求管理員在專案中,將 Dataproc 工作站 (roles/dataproc.worker) IAM 角色授予 Compute Engine 預設服務帳戶。

這個預先定義的角色具備建立叢集及提交工作所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

如要建立叢集及提交工作,您必須具備下列權限:

  • 發出 MCP 工具呼叫: mcp.tools.call

驗證及授權

Managed Service for Apache Spark 遠端 MCP 伺服器會使用 OAuth 2.0 通訊協定搭配 Identity and Access Management (IAM) 進行驗證及授權。驗證 MCP 伺服器時,系統支援所有Google Cloud 身分

Managed Service for Apache Spark 遠端 MCP 伺服器不接受 API 金鑰。

建議您為使用 MCP 工具的代理程式建立個別身分,以便控管及監控資源存取權。如要進一步瞭解驗證,請參閱「向 MCP 伺服器進行驗證」。

Managed Service for Apache Spark MCP OAuth 範圍

OAuth 2.0 會使用範圍和憑證,判斷經過驗證的主體是否有權對資源執行特定動作。如要進一步瞭解 Google 的 OAuth 2.0 範圍,請參閱「使用 OAuth 2.0 存取 Google API」。

Managed Service for Apache Spark 具有下列 MCP 工具 OAuth 範圍:

gcloud CLI 的範圍 URI 說明
https://www.googleapis.com/auth/dataproc 查看及管理 Managed Service for Apache Spark 中的資料,以及查看您 Google 帳戶的電子郵件地址

在工具呼叫期間存取的資源可能需要額外範圍。如要查看 Managed Service for Apache Spark 的必要範圍清單,請參閱 Managed Service for Apache Spark API

設定 MCP 用戶端,以使用 Managed Service for Apache Spark MCP 伺服器

AI 應用程式和代理 (例如 Claude 或 Antigravity) 可以例項化 MCP 用戶端,連線至單一 MCP 伺服器。AI 應用程式可以有多個用戶端,連線至不同的 MCP 伺服器。如果您的應用程式未列在特定用戶端指引中,則可以使用下列資訊,從大多數應用程式連線。

在 AI 應用程式中,尋找新增或連線至遠端 MCP 伺服器的方法。如果是 Managed Service for Apache Spark MCP 伺服器,請視需要輸入下列內容:

  • 伺服器名稱:Managed Service for Apache Spark MCP 伺服器
  • 伺服器網址端點https://dataproc-us-central1.googleapis.com/mcp
  • 傳輸:HTTP
  • 驗證詳細資料:視驗證方式而定,您可以輸入 Google Cloud 憑證、OAuth 用戶端 ID 和密鑰,或是代理程式身分和憑證。如要進一步瞭解驗證,請參閱「向 MCP 伺服器進行驗證」。
  • OAuth 範圍:連線至 Managed Service for Apache Spark MCP 伺服器時要使用的 OAuth 2.0 範圍。詳情請參閱「Managed Service for Apache Spark MCP OAuth 範圍」。

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

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

可用的工具

唯讀 MCP 工具的 MCP 屬性會設為 true。您可能只想透過機構政策,在特定環境中允許唯讀工具。mcp.tool.isReadOnly

如要查看 Managed Service for Apache Spark MCP 伺服器的可用 MCP 工具詳細資料和說明,請參閱 Managed Service for Apache Spark MCP 參考資料

列出工具

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

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

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

應用實例

以下是 Managed Service for Apache Spark MCP 伺服器的範例用途:

  • 「列出 PROJECT_IDREGION 中的 Managed Service for Apache Spark 叢集。」
  • 「Get the latest status for CLUSTER_NAME cluster in PROJECT_ID and REGION.」(取得 CLUSTER_NAME 叢集在 PROJECT_IDREGION 的最新狀態)。
  • 「Delete CLUSTER_NAME in PROJECT_ID and REGION and poll till completion. 如果失敗,請回報任何錯誤。"

更改下列內容:

  • PROJECT_ID:專案 ID。 Google Cloud 專案 ID 會列在 Google Cloud 控制台資訊主頁的「專案資訊」部分。
  • REGION:Managed Service for Apache Spark 叢集所在的 Compute Engine 區域
  • CLUSTER_NAME:現有 Managed Service for Apache Spark 叢集的名稱。

選用的安全防護設定

由於 MCP 工具可執行的動作種類繁多,因此會帶來新的安全風險和考量。為盡量減少及管理這些風險,Google Cloud 提供預設設定和可自訂的政策,以控管機構或專案中的 MCP 工具使用情形。 Google Cloud

如要進一步瞭解 MCP 安全性和控管措施,請參閱這篇文章

使用 Model Armor

Model Armor 是一項Google Cloud 服務,可提高 AI 應用程式的安全性。這項功能會主動篩選 LLM 提示詞和回覆,防範各種風險並支援負責任的 AI 做法。無論您是在雲端環境或外部雲端供應商部署 AI,Model Armor 都能協助您防範惡意輸入、驗證內容安全性、保護私密資料、維持法規遵循狀態,並在多元的 AI 環境中,持續強制執行 AI 安全政策。

啟用 Model Armor 並啟用記錄功能後,Model Armor 會記錄整個酬載。這可能會導致記錄中出現私密資訊。

啟用 Model Armor

您必須先啟用 Model Armor API,才能使用 Model Armor。

控制台

  1. 啟用 Model Armor API。

    啟用 API 時所需的角色

    如要啟用 API,您需要具備服務使用情形管理員 IAM 角色 (roles/serviceusage.serviceUsageAdmin),其中包含 serviceusage.services.enable 權限。瞭解如何授予角色

    啟用 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 和遠端 MCP 伺服器的防護功能 Google Cloud

如要保護 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:負責任的 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 使用情形

身分與存取權管理 (IAM) 拒絕政策可協助您保護 Google Cloud 遠端 MCP 伺服器。設定這些政策,即可封鎖不必要的 MCP 工具存取權。

舉例來說,您可以根據下列條件拒絕或允許存取:

  • 主體
  • 工具屬性 (例如唯讀)
  • 應用程式的 OAuth 用戶端 ID

詳情請參閱「使用 Identity and Access Management 控制 MCP 使用情形」。

後續步驟