useViewState and ModelContext describe the view.
useModelContext manages selected native attachments.
Keep each piece of evidence in one context channel.
Choose the right channel
Attach evidence to the next turn
UseuseModelContext() to add selected text, images, resource links, or embedded resources to the next model turn.
The hook shares one attachment collection across the view.
You can add, replace, remove, and clear attachments with stable application keys.
Read Attach evidence with ChatGPT Plugin Extensions for complete examples, image inputs, and error handling.
The guide also explains host removals and how to combine the hook with useViewState and ModelContext.
Keep structured choices in view state
UseuseViewState for selections, filters, drafts, and progress that future model turns should understand.
window.openai.widgetState.
Other MCP Apps hosts keep state for the current iframe lifetime.
After useModelContext activates native delivery, OpenAI host context can restore model-visible state and attachments.
Private UI persistence remains separate.
Describe visible UI
UseModelContext for natural-language descriptions that follow the React component lifecycle.
ModelContext:
Understand the merged snapshot
The runtime merges structured state and the serialized context tree into one complete object:_uiContext is a reserved model-visible field.
useViewState filters it from application state and rejects developer state with the same key.
Every write sends the complete snapshot.
On MCP Apps hosts, mcp-use sends the object as structuredContent and a JSON text block as content through ui/update-model-context.
On ChatGPT, views without useModelContext write the object to modelContent with window.openai.setWidgetState.
Views with useModelContext use the shared native writer described in ChatGPT Plugin Extensions.
Keep ephemeral values local
Use ReactuseState for transient details that the model does not need, such as hover state, open tooltips, or animation progress.
Next steps
- Use ChatGPT Plugin Extensions to add and remove selected evidence.
- Read the
useViewStateAPI reference for signatures, errors, and host behavior. - Read the
ModelContextAPI reference for lifecycle and nesting. - Use Interactivity for tool calls and follow-up messages.