Overview
Sunpeak uses a context-based pattern for MCP App connection.AppProvider handles creating the App, connecting via PostMessageTransport, and sharing the instance through React context. useApp reads the connected App from that context.
AppProvider
Wrap your app inAppProvider to establish the MCP connection.
Props
App identification sent to the host during
ui/initialize. In the sunpeak framework, this is sourced automatically from your project’s package.json name and version fields — all resources share the same app identity.Features this app provides. Defaults to
{}.Called after
App is created but before connect(). Use this to register event handlers that must be in place before the handshake.Usage
useApp
Returns the connectedApp instance from context, or null while connecting.
Signature
Returns
The connected
App instance, or null during initialization.Usage
Full Example
Behavior
- The
Appinstance is persisted at module scope across React Fast Refresh (HMR), so code changes don’t trigger reconnection. - On a full page reload, a fresh connection is established.
- The
Appis created withautoResize: trueby default. For custom options, create theAppmanually and use useAutoResize.