McpAppBridge

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)(source)

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).

The view is untrusted: it only reaches tools of its own server whose visibility includes app (§"Visibility"), through McpAppHost.approveToolCall; links must be http(s); nothing is sent to it before ui/notifications/initialized. Call receive and the host methods from one coroutine context (e.g. the main thread).

Parameters

tool

the MCP Tool JSON of the call that shows the view (hostContext.toolInfo).

send

delivers one JSON-RPC message to the view.

Constructors

Link copied to clipboard
constructor(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)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
var appCapabilities: JsonObject?

The view's appCapabilities from ui/initialize, once it connected.

Link copied to clipboard
var appInfo: JsonObject?

The view's appInfo from ui/initialize.

Link copied to clipboard

The current display mode (hostContext.displayMode).

Functions

Link copied to clipboard
suspend fun receive(text: String)

Handle one message from the view (malformed messages are dropped).

suspend fun receive(message: JsonObject)
Link copied to clipboard
suspend fun setHostContext(hostContext: JsonObject)

Update the host context; the view gets the changed fields (ui/notifications/host-context-changed).

Link copied to clipboard
suspend fun teardown(reason: String? = null, timeoutMs: Long): Boolean

Ask the view to wind down before it is removed (ui/resource-teardown) and wait up to timeoutMs for its answer. Returns whether it answered.

Link copied to clipboard
suspend fun toolCancelled(reason: String)

The tool call was cancelled (ui/notifications/tool-cancelled).

Link copied to clipboard
suspend fun toolInput(arguments: JsonObject)

The tool's complete arguments (ui/notifications/tool-input, sent once).

Link copied to clipboard
suspend fun toolResult(result: JsonObject)

The tool's CallToolResult (ui/notifications/tool-result, sent once, after the input).