大模型
cloud.google.com ·
在 Gemini 中实现 MCP Apps 的开发者指南
Google Cloud 发布开发者指南,介绍 MCP Apps(SEP-1865)开放扩展:将工具与实时 UI 配对,在 Gemini Enterprise 聊天流中以沙箱 iframe 渲染,可全屏或侧栏展开,编辑在本地执行并与助手保持同步。架构分三层:浏览器客户端、Gemini Enterprise(工具调用、AppBridge 代理、OAuth 连接器)以及托管在私有 Cloud Run 上的 MCP 服务器(单一 JSON-RPC 端点 /mcp)。鉴权采用 Cloud Run IAM 与 In-App OAuth 双层机制,分别校验调用服务与终端用户。
AI推荐理由 Google Cloud 官方开发者指南,介绍 MCP Apps(SEP-1865)这一开放 MCP 扩展:工具与实时 UI 配对,在 Gemini Enterprise 聊天流中以沙箱 iframe 渲染,支持本地编辑与工作区同步。文中给出三层架构(浏览器、Gemini Enterprise、Cloud Run 上的 MCP 服务器)和双层 OAuth 鉴权细节,对 Agent 交互式应用开发有实际参考价值;但属厂商教程,未提供性能数据或第三方验证。
82
正文
Enterprise assistants still respond mostly in text. However, that can break down for visual, multi-step work, where every adjustment costs another slow chat turn. MCP Apps (SEP-1865) solves this. This open Model Context Protocol (MCP) extension pairs a tool with a live UI. In Gemini Enterprise, that UI renders directly in the chat flow inside a sandboxed iframe, and can expand to fullscreen or a side panel. Edits run locally while the workspace and assistant stay synchronized. You also avoid rebuilding core foundations: Gemini provides workforce sign-in, governed data access, and the Default Assistant, while you host your MCP server on a private Cloud Run service. Why we need MCP Apps Enterprise assistants have evolved through three generations: Generation 1 (Text chatbots): Returns static markdown with no interactive controls. Generation 2 (Standard MCP tools): Invokes live APIs, but outputs static text. Every change requires another model turn. Generation 3 (Interactive MCP Apps): Pairs each tool with a live workspace. Adjustments happen in the widget without a model turn, while the assistant stays in sync. Building MCP Apps in Gemini delivers six benefits: Responsive user experience: Single-click actions execute directly in the panel without round-tripping through the chat. Purpose-built workflows: Deliver visual redaction views for legal review, 3D viewers for CAD, or sensitivity models for finance. Enterprise security: Workforce OAuth sign-in, private Cloud Run ingress, and a sandboxed iframe protect every layer. Human-in-the-loop governance: Experts inspect and approve high-stakes actions before execution. Open standard: Portable across compatible hosts, with automatic text fallback. Broad connectivity: Connect to BigQuery, Agent Platform, Cloud Storage, or internal ERP and CRM systems. High-level architecture Three decoupled tiers work together: Client browser: Shows the chat alongside the MCP App widget in the side panel. Gemini Enterprise: The default assistant calls tools, the AppBridge proxy relays widget messages, and the connector manages OAuth. Google Cloud (your project): You deploy and host the MCP server on Cloud Run, which exposes one JSON-RPC endpoint (/mcp), runs background jobs, and serves the single-file HTML widget. Each tier talks only to its neighbor, letting Gemini Enterprise enforce security and routing. Authentication with two independent layers Each user signs in through OAuth 2.0. On every call, Gemini Enterprise sends its service agent token alongside the user's OAuth token: Layer 1 (Cloud Run IAM): Enforced at Google's edge, this answers "which service may call?" Public access is disabled; unauthorized callers receive HTTP 403. Layer 2 (In-App OAuth): Enforced inside the application, this answers "which user is calling?" Failed verification returns HTTP 401, prompting the user to sign in again. Cloud Run IAM cannot distinguish end users, so both layers are required. Outbound calls use a least-privilege service account. Build, deploy on Google Cloud, and register in Gemini Enterprise First, build your custom MCP server (exposing POST /mcp and a bundled ui:// HTML widget) using the MCP Apps SDK, or use Google Antigravity to scaffold and deploy your MCP App with this starter prompt: Build an MCP App for Gemini Enterprise using the create-mcp-app skill (https://github.com/modelcontextprotocol/ext-apps/tree/main/plugins/mcp-apps/skills/create-mcp-app). Workflow: [describe your input data, side-panel UI controls, and approval or export actions]. Generate a single-file HTML widget, a Streamable HTTP backend (POST /mcp) with Data stores > Create data store, select Custom MCP Server and register the connector: Configuration field Value MCP Server URL https://.run.app/mcp Authorization URL https://accounts.google.com/o/oauth2/v2/auth Token URL https://oauth2.googleapis.com/token Client ID and Secret Your Web OAuth 2.0 Client ID and Secret Scopes openid email profile Enable PKCE Support Checked (recommended) Use HTTP Basic Auth Unchecked (avoids invalid_client errors) Step 6: Enable actions on your data store. Gemini Enterprise imports your MCP server's tools as actions and disables them by default. In the Cloud Console, open Gemini Enterprise > Data stores > [Your MCP Data Store] > Actions, click Reload custom actions (which calls tools/list on your server), select your model-visible tools, and click Enable actions. Step 7: Connect the data store to your app. Open Gemini Enterprise > Apps > [Your App] > Connected data stores > Add existing data stores, and select your MCP data store. Connecting it as a data store gives the built-in Default Assistant access to your MCP tools and UI widget directly in main chat ( do not use "Add Agent," which is for external sub-agents rather than MCP data stores). Build your own An MCP App pairs backend tools with a live workspace in Gemini Enterprise. You do not build a chat frontend or identity pipeline; you deploy one Cloud Run container and attach it as a Data Store, making Gemini Enterprise where enterprise work gets done. Try Gemini here Co-build with Google Antigravity here Build on Google Cloud: MCP Apps Specification (SEP-1865), Cloud Run, and Google Cloud AI.