feat: add experimental MCP Apps support for rich iframe UIs#15926
Open
tristan-stahnke-GPS wants to merge 13 commits intoanomalyco:devfrom
Open
feat: add experimental MCP Apps support for rich iframe UIs#15926tristan-stahnke-GPS wants to merge 13 commits intoanomalyco:devfrom
tristan-stahnke-GPS wants to merge 13 commits intoanomalyco:devfrom
Conversation
78cb76f to
36e226f
Compare
c2db03c to
7ff0560
Compare
Add MCP Apps protocol integration behind OPENCODE_EXPERIMENTAL_MCP_APPS flag, allowing MCP servers to render interactive UIs in sandboxed iframes. - Feature flag, AppMeta schema, tool metadata registry, and resource cache - Visibility filtering (_meta.ui.visibility: ["app"]) hides tools from LLM - structuredContent + resourceUri + server threaded into tool metadata - 3 experimental API routes (apps list, resource fetch, tool-call proxy) - McpAppTool renderer with AppBridge handshake and iframe auto-sizing - Configurable maxHeight (default 640px) via _meta.ui.maxHeight - FetchAppResourceFn wired through DataProvider - SDK regenerated - 15 tests across 3 test files - Demo fixture (server.py, app.html, README.md)
7ff0560 to
af15a3d
Compare
…S/opencode into feat/mcp-apps
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add MCP Apps protocol integration behind OPENCODE_EXPERIMENTAL_MCP_APPS flag, allowing MCP servers to render interactive UIs in sandboxed iframes.
Issue for this PR
Closes #10884
Type of change
What does this PR do?
This adds support for the MCP Apps protocol behind the
OPENCODE_EXPERIMENTAL_MCP_APPSflag. MCP servers can now declare tools with_meta.ui.resourceUripointing to aui://resource, and opencode will render the tool result inside a sandboxed iframe with a full AppBridge handshake.How it works end-to-end:
_meta.ui.resourceUrigets registered in atoolMetaRegistry. Tools withvisibility: ["app"]are filtered out of the LLM's tool list (they're only callable by the iframe itself).structuredContent,resourceUri,server, andmaxHeightare threaded into the tool part metadata so the frontend can pick them up.resourceUriin its metadata renders as aMcpAppToolinstead of the generic tool renderer.McpAppToolfetches the HTML resource via a new experimental API route, renders it in a sandboxed<iframe srcdoc>, and establishes anAppBridgeconnection overPostMessageTransport.oninitialized), the host sendstoolInputandtoolResult(withstructuredContent) to the iframe, which renders the data.onsizechange, capped at a configurablemaxHeight(default 640px, overridable per-tool via_meta.ui.maxHeight).Key implementation details worth calling out:
AppBridgeandPostMessageTransportare statically imported (not dynamicimport()) to avoid a race condition where the iframe sendsui/initializebefore the host bridge is listening.structuredContentfrom SolidJS reactive state is deep-cloned viaJSON.parse(JSON.stringify())before passing tobridge.sendToolResult(), because SolidJS Proxy objects failpostMessage's structured clone algorithm (DataCloneError).createSignalrather than direct DOM manipulation, so re-renders don't clobber the height set byonsizechange.<div>withoverflow: hiddenconstrains the layout box so the parent container doesn't grow to the iframe's scroll height.New files:
packages/opencode/src/flag/flag.ts—OPENCODE_EXPERIMENTAL_MCP_APPSflag (respectsOPENCODE_EXPERIMENTALtoo)packages/opencode/src/server/routes/experimental.ts— 3 routes: list app tools, fetch HTML resource, proxy tool callspackages/ui/src/components/message-part.tsx—McpAppToolrenderer (~100 lines)packages/ui/src/context/data.tsx—FetchAppResourceFntype + proppackages/opencode/test/fixture/mcp-app-demo/(Python MCP server + dashboard HTML app)How did you verify your code works?
extractAppMeta, visibility filtering,toolMetaregistry,apps()list,appResourcefetch/cache,structuredContentpassthrough, route handlers, andmaxHeightextractionDataCloneErrorin browser console after the structured clone fixbun turbo typecheck)Screenshots / recordings
Demo dashboard rendering inside opencode after a
demo_dashboardtool call:The iframe shows metric cards (Requests, Latency, Error Rate, Uptime), a throughput chart, traffic-by-region bars, and action buttons — all rendered from
structuredContentdelivered via the MCP Apps bridge protocol.Checklist