docs: improve MCP Apps integration guide with step-by-step walkthrough#1062
docs: improve MCP Apps integration guide with step-by-step walkthrough#1062zeroasterisk wants to merge 4 commits intogoogle:mainfrom
Conversation
Issues found and fixed: - Wrong agent path: contact_multiple_surfaces -> contact_lookup - Wrong Lit client path: samples/client/lit/contact/ has no package.json; actual commands run from samples/client/lit/ - Missing prerequisite steps (npm install, build:renderer, build:sandbox) - No mention of Python version requirements (contact_lookup needs 3.13+) - No mention that multiple terminals are needed - Missing GEMINI_API_KEY setup instructions (.env vs export) - Added demo:contact shortcut for Lit sample - Added troubleshooting table - Fixed mcp-apps-component.ts link path (contact -> custom-components-example) - Clarified build:sandbox requirement for Angular sample
There was a problem hiding this comment.
Code Review
This pull request updates the documentation for MCP Apps in A2UI, providing comprehensive prerequisites, step-by-step execution guides for the Lit and Angular samples, and a troubleshooting section. A security review identified critical discrepancies between the documentation's security model and the actual implementation in the linked Lit sample code, specifically regarding iframe sandboxing and the use of the allow-same-origin attribute.
|
|
||
| 1. **[Sandbox Proxy (`sandbox.html`)](https://github.com/google/A2UI/blob/main/samples/client/shared/mcp_apps_inner_iframe/sandbox.html)**: An intermediate `iframe` served from the same origin. It isolates raw DOM injection from the main app while maintaining a structured JSON-RPC channel. | ||
| - Permissions: **Do not sandbox** in the host template (e.g., [`mcp-app.ts`](https://github.com/google/A2UI/blob/main/samples/client/angular/projects/mcp_calculator/src/a2ui-catalog/mcp-app.ts) or [`mcp-apps-component.ts`](https://github.com/google/A2UI/blob/main/samples/client/lit/contact/ui/custom-components/mcp-apps-component.ts)). | ||
| - Permissions: **Do not sandbox** in the host template (e.g., [`mcp-app.ts`](https://github.com/google/A2UI/blob/main/samples/client/angular/projects/mcp_calculator/src/a2ui-catalog/mcp-app.ts) or [`mcp-apps-component.ts`](https://github.com/google/A2UI/blob/main/samples/client/lit/custom-components-example/ui/custom-components/mcp-apps-component.ts)). |
There was a problem hiding this comment.
The linked Lit example (mcp-apps-component.ts) contains two discrepancies with the security model described in this guide:
- Outer Iframe Sandboxing: The guide states that the host template should not sandbox the proxy iframe (line 24). However, the Lit component includes a
sandboxattribute withallow-same-origin(line 79 of that file). - Inner Iframe Isolation: The guide emphasizes that the inner iframe MUST NOT include
allow-same-origin(lines 19 and 27). However, the Lit component explicitly includes it when callingsendSandboxResourceReady(line 179 of that file).
These should be corrected in the sample code to ensure it serves as a secure and consistent reference implementation. The Angular example (mcp-app.ts) correctly follows these principles.
There was a problem hiding this comment.
Good catch — verified this is a real issue.
Angular sample correctly passes sandbox: 'allow-scripts' to sendSandboxResourceReady() (line ~89 of mcp-app.ts), so the inner iframe ends up with only allow-scripts.
Lit sample passes sandbox: 'allow-scripts allow-forms allow-popups allow-modals allow-same-origin' (line ~179 of mcp-apps-component.ts), which violates the guide's security model.
Additionally:
- The outer iframe in Lit has
sandbox="allow-scripts allow-forms allow-popups allow-modals allow-same-origin"(line 79) — the guide says the proxy iframe should not be sandboxed. - The shared
sandbox.ts(line 66) sets an initial default ofallow-scripts allow-same-origin allow-formson the inner iframe beforesendSandboxResourceReadyoverrides it — this means there's a brief window where the inner iframe hasallow-same-origin.
This is a docs PR so fixing the Lit sample code is out of scope here, but it should be filed as a separate issue. The guide's security model description is correct — the Lit sample doesn't follow it.
- contact_lookup agent defaults to port 10003, not 8080 - mcp_app_proxy agent defaults to port 10006, not 8080 - Angular client needs build:renderer before npm install - Updated troubleshooting table with correct port
Verified by running the full sample locally: - npm install without --include=dev skips @angular/cli - Angular 21 rejects --host 0.0.0.0 with allowed hosts check - Added both to troubleshooting table
Shows the full flow: initial load → opening the calculator from MCP server → chatting with the agent. Captured from a real local run.
The Lit sample and shared sandbox proxy included allow-same-origin in iframe sandbox attributes, violating the MCP Apps guide/spec: - Lit outer iframe: removed sandbox attribute entirely (guide says don't sandbox the proxy iframe) - Lit sendSandboxResourceReady: allow-scripts only (was allow-scripts allow-forms allow-popups allow-modals allow-same-origin) - Shared sandbox.ts inner iframe default: allow-scripts only (was allow-scripts allow-same-origin allow-forms) The Angular sample already correctly used sandbox: 'allow-scripts'. Confirmed against MCP Apps spec (SEP-1865) and AppBridge SDK docs. Fixes security discrepancy found by Gemini Code Assist review on google#1062.
The Lit sample and shared sandbox proxy included allow-same-origin in iframe sandbox attributes, violating the MCP Apps guide/spec: - Lit outer iframe: removed sandbox attribute entirely (guide says don't sandbox the proxy iframe) - Lit sendSandboxResourceReady: allow-scripts only (was allow-scripts allow-forms allow-popups allow-modals allow-same-origin) - Shared sandbox.ts inner iframe default: allow-scripts only (was allow-scripts allow-same-origin allow-forms) The Angular sample already correctly used sandbox: 'allow-scripts'. Confirmed against MCP Apps spec (SEP-1865) and AppBridge SDK docs. Fixes security discrepancy found by Gemini Code Assist review on google#1062.
Summary
Walked through the MCP Apps guide as a new developer and found several issues. This PR improves the guide with clearer step-by-step instructions, correct paths, and troubleshooting tips.
Issues Found & Fixed
samples/agent/adk/contact_multiple_surfaces/which doesn't exist — the correct path issamples/agent/adk/contact_lookup/npm run devinsamples/client/lit/contact/but that directory has nopackage.json— the actual commands should run fromsamples/client/lit/npm install,npm run build:renderer(Lit), ornpm run build:sandbox(Angular) — these are required before clients will workcontact_lookupagent requires Python ≥ 3.13 per itspyproject.toml, but the guide only said "3.12 or higher suggested"mcp-apps-component.tsGitHub link to correct path undercustom-components-exampledemo:contactshortcut: Mentioned the convenient npm script that runs everything together