Overview
useApp creates an App instance, connects it to the host via PostMessageTransport, and returns the connection state. Options are only used on the initial mount — the hook does not reconnect when options change.
Signature
UseAppOptions
Features this app provides (e.g.,
{ tools: { listChanged: true } }).Report size changes to the host. See
App options.Throw when host-bound methods run before the initialization handshake completes.
Bridge app tools and WebMCP in both directions. See WebMCP interoperability.
Called after
App is created but before connect(). Use this to register event handlers that must be in place before the initialization handshake.AppState
Usage
Behavior
- Unmount — The hook closes its
Appwhen the component unmounts. In React Strict Mode’s double mount, and when Fast Refresh re-runs effects, the firstAppcloses and a new one connects. The upstream JSDoc still says theAppis not closed, but the 2.1 code closes it. sunpeak’sAppProviderkeeps oneAppat module scope across both cases. - Auto-resize — The
Appis created withautoResize: trueby default. PassautoResize,strict, orwebMcpBridgeto change theAppoptions. For anything else, create theAppmanually and useuseAutoResize. - Options stability — Options are only read on initial mount. Changing
appInfo,capabilities,onAppCreated,autoResize,strict, orwebMcpBridgeafter mount has no effect.