Skip to main content
MCP Apps SDK

Overview

The App 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.
If you are deciding which method to use from an iframe View, start with the View API Guide. It compares callServerTool(), readServerResource(), updateModelContext(), sendMessage(), sampling, app-side tools, downloads, links, display modes, logs, and teardown.

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.
For large follow-up messages, offload data to updateModelContext first, then send a brief trigger via sendMessage:
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.
The returned 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 standard ui/resource-teardown request back to the app (triggering onteardown) before unmounting the iframe.

createSamplingMessage

Request an LLM completion from the host via standard MCP sampling/createMessage. The host has full discretion over model selection and may modify or reject the request. Check app.getHostCapabilities()?.sampling before calling.
When 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 with enable(), disable(), remove(), and update() methods.

sendToolListChanged

Notify the host that the app’s tool list has changed. Call this after registerTool, remove(), enable(), or disable().

sendSizeChanged

Manually notify the host of a UI size change. If autoResize is enabled (default), this is called automatically.