mcp-use, a widget has two parts: a React file under resources/ and a tool that returns widget({ props, output }).
Create the widget file
Create a folder underresources/. The folder name becomes the widget name you use from the server.
widget.tsx:
props behind isPending. Widgets mount before the tool result is available.
Return the widget from a tool
Inindex.ts, add a tool whose widget.name matches the folder under resources/.
props becomes the widget’s rendering data. output becomes the text result the model can read in the conversation.
Keep schemas aligned
The serveroutputSchema should describe the same shape that the widget expects in props.
Use a shared schema when the widget and server live in the same package. If you duplicate schemas, keep the field names and optional fields identical.
Verify the widget
Run the dev server and call the tool in the Inspector:http://localhost:3000/inspector, run search-products, and confirm the widget renders below the tool result.
If the tool succeeds but no widget renders, check these two values first:
widget.nameinindex.ts- the folder name under
resources/
Next steps
- Use Model context to decide what the model should know about widget state.
- Use Interactivity when the widget needs buttons, state, tool calls, or follow-up messages.
- Use the
useWidget()API reference for all hook fields and defaults.