McpUseProvider
TheMcpUseProvider is a unified provider component that combines all common React setup for mcp-use widgets. It automatically includes StrictMode, ThemeProvider, BrowserRouter, optional WidgetControls, and ErrorBoundary, eliminating the need to manually set up these providers.
Import
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | required | The widget content to wrap |
debugger | boolean | false | Enable debug button in WidgetControls component |
viewControls | boolean | "pip" | "fullscreen" | false | Enable view controls (fullscreen/pip). true shows both, "pip" shows only pip, "fullscreen" shows only fullscreen |
autoSize | boolean | false | Automatically notify OpenAI about container height changes using ResizeObserver |
What’s Included
TheMcpUseProvider automatically wraps your widget with:
- StrictMode (outermost) - React’s development mode checks
- ThemeProvider - Theme management that syncs with ChatGPT
- BrowserRouter - React Router with automatic basename calculation
- WidgetControls (conditional) - Debug and view controls if enabled
- ErrorBoundary (innermost) - Error handling for graceful failures
- Auto-sizing container (conditional) - ResizeObserver wrapper if
autoSize={true}
Basic Usage
With Debug Controls
Enable the debug button to inspect widget state, props, and test tool calls:With View Controls
Enable fullscreen and picture-in-picture controls:With Auto-sizing
Enable automatic height notifications for dynamic content:Complete Example
Auto-sizing Feature
WhenautoSize={true}, the provider:
- Uses
ResizeObserverto monitor the container height - Automatically calls
window.openai.notifyIntrinsicHeight()when height changes - Debounces notifications (150ms) to prevent excessive calls
- Uses
scrollHeightas fallback for more accurate measurements - Prevents feedback loops by tracking notification state
Automatic Basename Calculation
TheBrowserRouter automatically calculates the correct basename for routing:
- In production: Uses
/as basename - In inspector dev proxy: Detects
/inspector/api/dev-widget/:toolIdpattern and sets basename accordingly
Dev Mode Detection
When running in the inspector’s dev widget proxy,WidgetControls are automatically hidden since the inspector provides its own debugging interface. This prevents duplicate controls from appearing.
Related Components
WidgetControls- Debug and view controlsThemeProvider- Theme managementErrorBoundary- Error handlinguseWidget- Widget hook for accessing props and actions