Skip to main content
Build a widget when a tool result needs an interactive UI. In 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 under resources/. The folder name becomes the widget name you use from the server.
Define the widget metadata and component in widget.tsx:
Always guard required props behind isPending. Widgets mount before the tool result is available.

Return the widget from a tool

In index.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 server outputSchema 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:
Open 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.name in index.ts
  • the folder name under resources/
They must match exactly.

Next steps