What you’ll build
This guide creates a local server with:- an MCP endpoint at
http://localhost:3000/mcp - an Inspector at
http://localhost:3000/inspector - a
search-toolstool that returns a widget - a React widget at
resources/product-search-result/widget.tsx
Prerequisites
- Node.js 20.19 or higher, or 22.12 or higher
- Basic TypeScript and React knowledge
Create the project
Run the MCP Apps template:Run the server
Start the development server:Inspect the widget tool
Openindex.ts and find the search-tools tool. The template includes extra server metadata, fruit data, and a second get-fruit-details tool. This excerpt shows the widget-returning path you need to understand first.
widget.name must match the folder under resources/. In this template, product-search-result maps to resources/product-search-result/widget.tsx.
The props object becomes widget rendering data. The output value is the short text result the model can read.
Inspect the React widget
Openresources/product-search-result/widget.tsx. The widget reads the tool result with useWidget().
The generated widget includes metadata, layout components, display-mode controls, state, and tool calls. This excerpt shows the core data access pattern.
isPending before reading required fields from props.
Verify in the Inspector
Use the Inspector to confirm that the server and widget work.- Open
http://localhost:3000/inspector. - Go to the Tools tab.
- Select
search-tools. - Run the tool with
{ "query": "a" }or{}. - Confirm that the widget renders below the tool result.
widget.name exactly matches the folder under resources/ and that the handler returns widget(...).
Next steps
- Use
useWidget()to read props, state, host context, and display mode. - Use
useCallTool()when a widget needs to call another MCP tool. - Configure Content Security Policy before loading external APIs, images, scripts, embeds, or static assets.