Two Patterns
| Pattern | Hook | When to use |
|---|---|---|
| Initial hydration | useToolInfo | Data passed when widget loads |
| User-triggered | useCallTool | User clicks button, needs more data |
Initial Hydration with useToolInfo
When the host calls your widget’s tool, the server returnsstructuredContent. Access it with useToolInfo:
Status Flags
| Flag | Meaning |
|---|---|
isIdle | Widget hasn’t received data yet |
isPending | Tool is still executing |
isSuccess | Data is available in output |
isError | Tool failed, check error |
User-Triggered Fetching with useCallTool
When the user clicks something and you need more data:Tool Accessibility: In Apps SDK (ChatGPT), tools must have
_meta["openai/widgetAccessible"] set to true to be callable from widgets. In MCP Apps, all tools are accessible by default. See useCallTool API for details.With Callbacks
With Async/Await
Type Safety with generateHelpers
UsegenerateHelpers for autocomplete and type inference. See generateHelpers for setup.