Overview
TheApp class provides methods for the View to make requests to the host. The host proxies server requests to the MCP server and handles UI requests directly. For handling incoming host events, see Event Handlers.
callServerTool
Call a tool on the originating MCP server (proxied through the host).Tool-level execution errors are returned in the result with
isError: true rather than throwing exceptions. Transport or protocol failures throw. Always check result.isError.sendMessage
Send a message to the host’s chat interface.updateModelContext
Update the host’s model context with app state. Context is available to the model in future turns without triggering an immediate response. Each call overwrites any previous context.openLink
Request the host to open an external URL in the browser.downloadFile
Request the host to download a file. Since MCP Apps run in sandboxed iframes where direct downloads are blocked, this provides a host-mediated mechanism.readServerResource
Read a resource from the originating MCP server (proxied through the host).listServerResources
List available resources on the originating MCP server (proxied through the host). Supports pagination via cursor.requestDisplayMode
Request the host to change the display mode.mode is the mode actually set — it may differ from the requested mode if unsupported.
sendLog
Send log messages to the host for debugging. Logs are not added to the conversation.requestTeardown
Request the host to tear down this app. The host may approve or ignore the request. If approved, the host will send the standardui/resource-teardown request back to the app (triggering onteardown) before unmounting the iframe.
createSamplingMessage
Request an LLM completion from the host via standard MCPsampling/createMessage. The host has full discretion over model selection and may modify or reject the request. Check app.getHostCapabilities()?.sampling before calling.
params.tools is provided, the result may contain tool_use blocks and stopReason: "toolUse". Check getHostCapabilities()?.sampling?.tools before passing tools.
registerTool
Register a tool that the host can call. Uses Standard Schema (Zod, ArkType, Valibot) for input/output validation. Returns a handle withenable(), disable(), remove(), and update() methods.
sendToolListChanged
Notify the host that the app’s tool list has changed. Call this afterregisterTool, remove(), enable(), or disable().
sendSizeChanged
Manually notify the host of a UI size change. IfautoResize is enabled (default), this is called automatically.