View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/McpUseProvider.tsx
McpUseProvider composes the common React setup for a widget into a single wrapper. From outermost to innermost it renders StrictMode, then ThemeProvider, then (conditionally) WidgetControls, then ErrorBoundary around your children. When autoSize is enabled it also wraps the tree in a container div that a ResizeObserver measures to notify the host of height changes.
McpUseProvider
Unified provider component that combines all common React setup for mcp-use widgets.children with the standard mcp-use provider stack. Always includes StrictMode (outermost), ThemeProvider, and ErrorBoundary (innermost). Conditionally adds WidgetControls when debugger is true or viewControls is set, and an auto-sizing container div when autoSize is true.
The auto-sizing container uses a ResizeObserver on the wrapping div to detect content height changes and notifies the host through the MCP Apps bridge (ui/notifications/size-changed). Notifications are debounced by 150ms to let animations settle, and a positive height change is only sent when it differs from the last reported height by at least 5px. A zero height is always reported, which lets the host collapse and hide an empty widget. When the widget renders inside the top-level window (not an iframe, where window === window.parent) the height notification is skipped. If ResizeObserver is unavailable or window is undefined (server-side rendering), auto-sizing is a no-op.
Props
SignatureThe widget content to wrap.Enable the debug button in theWidgetControlscomponent. Whentrue,WidgetControlsis rendered around the content.Enable view controls in theWidgetControlscomponent.trueshows both the picture-in-picture and fullscreen buttons,"pip"shows only the picture-in-picture button, and"fullscreen"shows only the fullscreen button. Any truthy value also causesWidgetControlsto be rendered.Automatically notify the host about container height changes for auto-sizing using aResizeObserveron the children container, sent via the MCP Appsui/notifications/size-changednotification.Setcolor-schemeon the document root to match the active theme, enabling native dark scrollbars and the CSSlight-dark()function. Disable only when you need the browser canvas to stay transparent in hosts that render widgets over a differently themed background. Forwarded toThemeProvider.
The default for
autoSize is true in the current source. Widgets are auto-sized out of the box. Pass autoSize={false} to opt out.Types
The props object accepted byMcpUseProvider.
McpUseProviderProps
Shape of the props object passed toMcpUseProvider.
Fields
SignatureThe widget content to wrap.Optional. Enable the debug button inWidgetControls. Defaults tofalse.Optional. Enable view controls inWidgetControls. Defaults tofalse.Optional. Enable host height notifications viaResizeObserver. Defaults totrue.Optional. Setcolor-schemeon the document root to match the active theme. Defaults totrue.
What is included
McpUseProvider builds the component tree with conditional wrappers, from outermost to innermost:
StrictMode(always, outermost): React development-mode checks.ThemeProvider(always): protocol-aware theme management, syncs with both MCP Apps and ChatGPT. Receives thecolorSchemeprop.WidgetControls(conditional): rendered whendebuggeristrueorviewControlsis set. ReceivesdebuggerandviewControls.- Auto-sizing container
div(conditional): rendered whenautoSizeistrue. Styled withwidth: "100%"andminHeight: 0, and observed by aResizeObserver. ErrorBoundary(always, innermost): catches render errors for graceful failures.
Usage
Minimal usage wraps a single widget component. The widget itself is registered server-side and rendered inside the iframe; the example server below shows the matching server tool that drives aweather-display widget.
new MCPServer({ ... }) to construct the server:
Related
WidgetControls: debug and view controls.ThemeProvider: theme management.ErrorBoundary: error handling.useWidget: widget hook for accessing props and actions.