Widgets
Widgets allow an MCP server to expose interactive user interfaces alongside MCP tools. A widget can be used when a tool needs to present richer output than plain text or structured data. mcpfy provides the widget runtime, registration APIs, and build tooling required to develop and serve widgets.Widget Directory Structure
By default, mcpfy looks for widgets under:weather.
The widget directory can be changed through the server’s widgetsDir configuration:
widgetsDir is not specified, the default is src/widgets.
Registering a Widget
A widget is associated with a tool using thewidget property.
For example:
Creating the Widget Entry File
Create:src/widgets/<name>/main.tsx convention is handled by the mcpfy widget runtime.
You should not manually add another ThemeProvider or HostRuntime around the standard widget entry point when using the normal SDK convention. The runtime handles the required provider setup.
Widget Content
Widgets can provide HTML content or reference a URL. When using HTML content, the content must use the structured form:Widget Size
Widget dimensions are represented as a tuple containing width and height. For example:- Width
- Height
Building Widgets
Widget source code must be built before it can be used in a production server. mcpfy provides CLI commands for this:Development
Use:Production Build
Before starting the server in production, run:Widget Development Workflow
A typical workflow is:1. Create the widget directory
2. Create the entry file
3. Register the widget with a tool
4. Run the widget development command
5. Build for production
6. Start the MCP server
Start the server using the project’s normal start command after the widget build has completed.Example Project
A complete project can look like:Widget Runtime
The widget runtime provides the environment required for widgets to communicate with the MCP host. For the standard widget structure, mcpfy takes care of the required runtime/provider setup. This means a widget entry point should focus on the UI rather than manually recreating the host runtime. For advanced React integration, see Widget React.Widget and Tool Communication
A widget is commonly paired with an MCP tool. The general flow is:Production Considerations
When deploying an MCP server that uses widgets:- Ensure every registered widget has a corresponding widget directory.
- Ensure each widget has its required
main.tsxentry point. - Run
mcpfy buildbefore starting the production server. - Include the generated widget assets in the deployment.
- Keep widget names consistent between
server.tool()and the widget directory. - Do not manually double-wrap the standard widget entry point with providers already supplied by the SDK runtime.

