-
Notifications
You must be signed in to change notification settings - Fork 989
Mcp Apps 1 : Introducing McpApps A2UI Component #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+416
−2
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
080e7d2
feat: Add MCP Calculator app & McpApp rendering component
sugoi-yuzuru 49d8729
refactor: Update iframe view child to signal-based API, use `OnInit` …
sugoi-yuzuru 2fb920b
chore: improve comment grammar and punctuation in sandbox tool call h…
sugoi-yuzuru 5a7e996
feat: decode URL-encoded content and send dynamic updates to the sand…
sugoi-yuzuru e5f42d1
fix: prevent memory leaks by closing AppBridge and tighten sandbox se…
sugoi-yuzuru d6793ff
docs: reformat README.md for improved readability by adding line breaks.
sugoi-yuzuru b008677
refactor: clarify sandbox iframe attribute behavior and use a constan…
sugoi-yuzuru f0983b7
refactor: move resolvedTitle signal type annotation to the computed f…
sugoi-yuzuru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
samples/client/angular/projects/orchestrator/public/sandbox_iframe/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Sandbox Iframe | ||
|
|
||
| This directory contains the `sandbox.html` and its associated resources. | ||
|
|
||
| ## Purpose | ||
|
|
||
| `sandbox.html` is designed to be loaded into an `<iframe>` to provide a secure, | ||
| isolated environment for running MCP (Model Context Protocol) applications. It | ||
| acts as a bridge between the host application (Orchestrator) and the untrusted | ||
| or external MCP apps, managing communication via `postMessage`. | ||
|
|
||
| ## Development | ||
|
|
||
| The logic for the sandbox is written in `sandbox.ts` and must be compiled to | ||
| `sandbox.js` to be executable by the browser. | ||
|
|
||
| ### Build Command | ||
|
|
||
| To generate `sandbox.js` from `sandbox.ts`, run the following command from the | ||
| `samples/client/angular` directory: | ||
|
|
||
| ```bash | ||
| npm run build:sandbox | ||
| ``` | ||
|
|
||
| This ensures that all dependencies (like `@modelcontextprotocol/ext-apps`) are | ||
| correctly bundled. | ||
42 changes: 42 additions & 0 deletions
42
samples/client/angular/projects/orchestrator/public/sandbox_iframe/sandbox.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <!-- | ||
| Copyright 2025 Google LLC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>MCP App Sandbox</title> | ||
| <style> | ||
| body, html { | ||
| margin: 0; | ||
| padding: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| overflow: hidden; | ||
| } | ||
| #content { | ||
| width: 100%; | ||
| height: 100%; | ||
| border: none; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="content"></div> | ||
| <script type="module" src="sandbox.js"></script> | ||
| </body> | ||
| </html> |
92 changes: 92 additions & 0 deletions
92
samples/client/angular/projects/orchestrator/public/sandbox_iframe/sandbox.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| Copyright 2025 Google LLC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { | ||
| AppBridge, | ||
| PostMessageTransport, | ||
| SANDBOX_PROXY_READY_METHOD, | ||
| SANDBOX_RESOURCE_READY_METHOD | ||
| } from '@modelcontextprotocol/ext-apps/app-bridge'; | ||
|
|
||
| /** | ||
| * Note on "sandbox" terminology: | ||
| * The primary functionality of this unit (sandbox.html/ts) is to serve a sandboxed | ||
| * environment for the McpApp component. | ||
| * | ||
| * The sandbox.html is simply a webpage that contains a sandboxed inner iframe. | ||
| * The `sandbox` property is an iframe attribute that acts as an allow-list rather than a | ||
| * block-list. By default (when it is ''), the iframe will not allow anything, ensuring | ||
| * the environment is as vacuum-sealed as possible. Individual features can be enabled | ||
| * by setting the `sandbox` property when the host (McpApp component) triggers the | ||
| * SANDBOX_RESOURCE_READY_METHOD | ||
| */ | ||
|
|
||
| // Initialize AppBridge | ||
| const bridge = new AppBridge( | ||
| null, // No client in sandbox | ||
| { name: 'MCP Sandbox', version: '1.0.0' }, | ||
| { | ||
| serverTools: {}, | ||
| logging: {} | ||
| } | ||
| ); | ||
|
|
||
| // By default no features will be allowed for the sandbox iframe. | ||
| const DEFAULT_SANDBOX_ALLOWED_FEATURES = ''; | ||
|
|
||
| bridge.oncalltool = async (params: any) => { | ||
| // Forward tool calls to parent if needed, or handle locally | ||
| // For now, we just log | ||
| console.log('[Sandbox] Tool call:', params); | ||
| // We can also postMessage back to parent manually if bridge doesn't handle it. | ||
| // The implementation of forwarding logic would go here | ||
| // For now, throw to indicate not implemented in sandbox | ||
| throw new Error('Tool execution not supported in sandbox directly'); | ||
| }; | ||
|
|
||
| // Notify parent we are ready (standard) | ||
| window.parent.postMessage({ method: SANDBOX_PROXY_READY_METHOD }, window.location.origin); | ||
|
|
||
| // Listen for resource ready message | ||
| window.addEventListener('message', async (event) => { | ||
sugoi-yuzuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Validate the origin of incoming messages | ||
| if (event.origin !== window.location.origin) { | ||
| return; | ||
| } | ||
|
|
||
| const data = event.data; | ||
| if (data && data.method === SANDBOX_RESOURCE_READY_METHOD) { | ||
| const { html, sandbox } = data.params; | ||
| const content = document.getElementById('content'); | ||
| if (html && content) { | ||
sugoi-yuzuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Create an inner iframe with srcdoc to enable Javascript execution if any. | ||
| const innerFrame = document.createElement('iframe'); | ||
| innerFrame.srcdoc = html; | ||
| innerFrame.style.width = '100%'; | ||
| innerFrame.style.height = '100%'; | ||
| innerFrame.style.border = 'none'; | ||
| innerFrame.sandbox = sandbox || DEFAULT_SANDBOX_ALLOWED_FEATURES; | ||
|
|
||
| // Clear any existing content and inject the new iframe | ||
| content.innerHTML = ''; | ||
| content.appendChild(innerFrame); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Initialize transport with parent | ||
| const transport = new PostMessageTransport(window.parent, window.parent); | ||
| await bridge.connect(transport); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.