In sunpeak, register event handlers in the
onAppCreated callback of useApp to ensure they’re set before the connection handshake.Overview
TheApp class exposes setter properties for handling host notifications and requests. These are convenience wrappers around setNotificationHandler() and setRequestHandler() from the MCP SDK’s Protocol class. For making requests from the View to the host, see Requests.
Notification Handlers
ontoolinput
Called when the host sends complete tool arguments. This arrives after a tool call begins and before the tool result.Complete tool call arguments as key-value pairs.
ontoolinputpartial
Called as the host streams partial tool arguments during tool call initialization. Use for progressive rendering before complete input is available.Partial tool arguments (healed JSON — incomplete objects may be truncated).
ontoolresult
Called when the host sends the result of a tool execution.Standard MCP tool execution result. Key fields:
| Field | Type | Description |
|---|---|---|
content | ContentBlock[] | Text content for model context |
structuredContent | Record<string, unknown> | Data optimized for UI rendering |
isError | boolean | Whether the tool returned an error |
_meta | object | Metadata (e.g., viewUUID for state persistence) |
ontoolcancelled
Called when tool execution is cancelled (user action, timeout, classifier intervention).Optional reason for the cancellation.
onhostcontextchanged
Called when the host context changes (theme toggle, resize, locale change, etc.). Params are automatically merged into the internal context before the callback —getHostContext() returns updated values.
Partial context update containing only changed fields. See Core Types for the full
McpUiHostContext structure.Request Handlers
onteardown
Called when the host requests graceful shutdown before unmounting the iframe. Return{} (or a promise resolving to {}) when ready.
oncalltool
Handle tool calls from the host directed at this app. Requires declaringtools capability in the constructor.
Name of the tool being called.
Tool arguments.
onlisttools
Return the list of tools this app provides. Requires declaringtools capability.