Wraps App class
MCP Apps SDK reference
Overview
AppProvider wraps your resource component tree and establishes the connection to the MCP Apps host. All sunpeak hooks read from this context internally, so you never need to pass app as a parameter.
The sunpeak framework adds AppProvider automatically in both sunpeak dev and sunpeak build — you never need to write it yourself. It reads name and version from your project’s package.json for appInfo.
Import
Props
App identification sent to the host during
ui/initialize. In the sunpeak framework, this is sourced from your project’s package.json name and version fields.Capabilities to advertise to the host during initialization. See
McpUiAppCapabilities for the protocol-level type.Callback invoked after the
App instance is created but before connect(). Use this to register event handlers that must be in place before the initialization handshake.The resource component tree.
Usage
With event handlers
AppState
The context value provided to child components viauseApp.
The connected
App instance, or null while connecting.Whether initialization completed successfully.
Connection error if initialization failed,
null otherwise.Behavior
- HMR persistence — The
Appinstance is stored at module scope and persists across React Fast Refresh. Code changes don’t trigger reconnection. A full page reload establishes a fresh connection. - StrictMode — The provider handles React StrictMode’s double-mount cycle by deduplicating the connection attempt. If a connection is already in flight, the second mount waits for it.
- Single instance — Only one
Appinstance is created per page. MultipleAppProvidermounts (e.g., during StrictMode) share the same underlying connection.