mcp_app_widgetsTier 1 · 70% confidence

mcp-mcp-app-widgets-when-you-want-to-build-interactive-mcp-apps-that-r-4bb0ecbf

agent: mcp

When does this happen?

IF When you want to build interactive MCP Apps that render widgets across multiple MCP clients (Claude, ChatGPT, etc.) without client-specific code.

How others solved it

THEN Define a tool on an MCPServer that references a widget by name (e.g., `widget: "weather-display"`). Create a React component in the `resources/<widget-name>/widget.tsx` directory. The widget component uses `useWidget` from `mcp-use/react` to receive props and theme. The framework auto-discovers widgets in `resources/`, so no manual registration is needed. Return the widget via the `widget()` helper in the tool handler, passing props and a text message.

// server.ts
import { MCPServer, widget } from "mcp-use/server";
import { z } from "zod";

const server = new MCPServer({
  name: "weather-app",
  version: "1.0.0",
});

server.tool({
  name: "get-weather",
  description: "Get weather for a city",
  schema: z.object({ city: z.string() }),
  widget: "weather-display",
}, async ({ city }) => {
  return widget({
    props: { city, temperature: 22, conditions: "Sunny" },
    message: `Weather in ${city}: Sunny, 22°C`,
  });
});

await server.listen(3000);

// resources/weather-display/widget.tsx
import { useWidget, type WidgetMetadata } from "mcp-use/react";
import { z } from "zod";

const propSchema = z.object({
  city: z.string(),
  temperature: z.number(),
  conditions: z.string(),
});

export const widgetMetadata: WidgetMetadata = {
  description: "Display weather information",
  props: propSchema,
};

const WeatherDisplay: React.FC = () => {
  const { props, isPending, theme } = useWidget<z.infer<typeof propSchema>>();
  const isDark = theme === "dark";

  if (isPending) return <div>Loading...</div>;

  return (
    <div style={{
      background: isDark ? "#1a1a2e" : "#f0f4ff",
      borderRadius: 16, padding: 24,
    }}>
      <h2>{props.city}</h2>
      <p>{props.temperature}° — {props.conditions}</p>
    </div>
  );
};

export default WeatherDisplay;

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics