Skip to main content
Interactive widgets can call tools, save UI state, send follow-up messages, and request a larger display mode. Use these APIs for user actions that should happen inside the widget instead of requiring another prompt. This guide assumes your widget already renders with useWidget(). See Build widgets first if you still need the server and widget setup.

Call tools from a widget

Use useCallTool() when a button or form should call another MCP tool. The hook gives you loading, success, and error state.
Prefer useCallTool() for user-facing actions. Use useWidget().callTool only for small one-off calls where you do not need hook-managed state.

Save widget state

Use setState for UI state that should survive re-renders and be available to future model turns.
Use widget state for view state and user choices. Do not use widget state as your database.

Send a follow-up message

Use sendFollowUpMessage when a widget action should ask the model to continue the conversation.
Follow-up messages create a new model turn. Use them for actions that need model reasoning, not for local UI updates.

Request display modes

Use requestDisplayMode when a widget needs more room.
The host may grant a different mode than requested. Read displayMode for the actual current mode.

Combine actions carefully

A single click should usually do one main thing. For example:
  • call a tool to fetch more data
  • update widget state after a user choice
  • send a follow-up message for model reasoning
  • request fullscreen for a larger view
If one action must do multiple things, update local widget state first so the UI responds immediately, then call the tool or send the follow-up message.

Next steps

  • Use Model context to decide what the model should know about these interactions.
  • Use useCallTool() for full call state and typing details.
  • Use useWidget() for all host actions and display-mode behavior.