Package-level declarations

Types

Link copied to clipboard
interface McpAppActions

What an app does with its views' requests; the chat-level part of McpAppHost (the view handles sizing, display modes and tool approval itself).

Link copied to clipboard
class McpAppBridge(client: McpClient, resource: McpAppResource, toolCallId: String, tool: JsonObject, host: McpAppHost, hostContext: JsonObject = JsonObject(emptyMap()), hostInfo: McpImplementation = McpImplementation("ai-elements-kotlin", "0.3.0"), send: suspend (JsonObject) -> Unit)

The host side of one MCP App view (MCP Apps 2026-01-26, §"Communication Protocol"): it answers the view's JSON-RPC over send / receive as an MCP server that proxies client — the connection of the server that owns the view — and drives the lifecycle (ui/initialize, tool input and result, host context, teardown).

Link copied to clipboard
data class McpAppCsp(val connectDomains: List<String> = emptyList(), val resourceDomains: List<String> = emptyList(), val frameDomains: List<String> = emptyList(), val baseUriDomains: List<String> = emptyList())

The origins a view may reach (MCP Apps McpUiResourceCsp). Empty lists are the secure default: no connections, no external resources, no nested frames, same-origin base URIs.

Link copied to clipboard
class McpAppException(message: String) : Exception

A view that cannot be shown: not a ui:// resource, not text/html;profile=mcp-app, or empty.

Link copied to clipboard
interface McpAppHost

What the host does for a view. Every method has a safe default (decline, ignore), so a host implements only what it offers.

Link copied to clipboard
data class McpAppModelContext(val toolCallId: String, val app: String, val content: JsonArray?, val structuredContent: JsonElement?)

What a view wants the model to know (ui/update-model-context): its latest content blocks and structuredContent. Attach toDataPart to the next user turn; each view's newest replaces its previous one.

Link copied to clipboard
data class McpAppResource(val uri: String, val html: String, val csp: McpAppCsp = McpAppCsp(), val permissions: Set<String> = emptySet(), val prefersBorder: Boolean? = null, val domain: String? = null)

An MCP App view read from its server (resources/read of a ui:// URI, §"UI Resource Format").

Link copied to clipboard
class McpAppSessions(capacity: Int = 8)

The live views of a chat, by tool call. A view keeps running while it scrolls out of sight or its message recomposes — its sandbox, connection and state live here, not in the composition — and is torn down (ui/resource-teardown) when evicted (beyond capacity, least recently shown first) or on close. rememberMcpAppSessions closes them with the composition.

Functions

Link copied to clipboard
fun mcpAppRenderer(clientFor: (serverId: String) -> McpClient?, actions: McpAppActions, sessions: McpAppSessions): DataRenderer

Renders DataPart.MCP_APP parts — added by MCP tools that have a view (_meta.ui.resourceUri) — as their MCP App (McpAppView). clientFor returns the connection of the part's server (by the server id the part names; reuse the instances the agent uses); a part whose server is unknown renders nothing. The views live in sessions: keep one per chat screen.

Link copied to clipboard
@Composable
fun McpAppsHost(clientFor: (serverId: String) -> McpClient?, actions: McpAppActions, content: @Composable (renderer: DataRenderer) -> Unit)

MCP Apps for a chat screen: content gets the renderer for DataPart.MCP_APP (register it in AiElementsRenderers.data), and the views' dialogs — tool approvals, full screen — show at this level, whether or not their view is scrolled into sight. Views are torn down with this.

Link copied to clipboard
@Composable
fun McpAppView(client: McpClient, resourceUri: String, toolCallId: String, tool: JsonObject, input: JsonObject, result: JsonObject?, actions: McpAppActions, modifier: Modifier = Modifier, sessions: McpAppSessions = rememberMcpAppSessions(), maxHeight: Dp = 600.dp, originKey: String = client.url)

Shows the MCP App view resourceUri of one tool call: it reads the view from client (the connection of the server that owns it), runs it in a sandbox and connects it to the chat through actions. input is the call's arguments and result its CallToolResult once it returns.

Link copied to clipboard

Read and validate the MCP App view at uri.

Link copied to clipboard
@Composable
fun rememberMcpAppSessions(capacity: Int = 8): McpAppSessions

McpAppSessions that close when this leaves the composition.