Skip to main content
sunpeak API

Overview

Manages UI state that is automatically synced to the host via updateModelContext. Works like React’s useState, but each update is pushed to the host so the AI model can see it on the next message. Use this for user decisions, selections, or any state the model should be aware of. The hook starts from defaultState whenever the View mounts. It does not restore state after the host recreates the iframe. For durable data, save and reload it through server tools. See MCP App State Persistence. Use an object-shaped state value. The hook sends it as updateModelContext().structuredContent, which the MCP Apps protocol defines as an object.

Wraps updateModelContext

MCP Apps SDK reference

Import

Signature

Parameters

T
required
Initial state value.

Returns

[T, (state: SetStateAction<T>) => void]
A tuple containing the current state and a setter function, similar to React’s useState.

Usage