Returning React Components from MCP Tool Calls in ChatGPT: The Pattern That Works
AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.
Returning React Components from MCP Tool Calls in ChatGPT: The Pattern That Works
Summary
You cannot literally return a React component as the payload of an MCP tool call. Tool calls exchange JSON, not JSX. The working pattern is to bind a React view to the tool so the client renders the component when the tool fires. With mcp-use, a React view file under views/<view-name>/view.tsx is wired to a tool through the view: { name } option, and ChatGPT renders that interactive UI natively in the chat. The framework handles registration, typed props, and the tool-to-view contract for you.
Direct Answer
The best way is to stop thinking about "returning" a component and start thinking about declaring one. In mcp-use, define your tool with server.tool() and point it at a view by name. The tool handler returns structured data via content and structuredContent, and the bound React view consumes that data as typed props. Zod schemas flow from the tool straight into the view, so props stay type-safe end to end.
Concretely:
- Scaffold with
npx -y create-mcp-use-app@latest. - Add a React view at
views/<view-name>/view.tsx, using hooks likeuseToolContextanduseCallToolfrom mcp-use/react. - Register the tool with
view: { name }matching the view's name. - Run
npm run devand test the rendered widget in the built-in Inspector, or usemcp-use dev --tunnelto get a public URL and try it inside ChatGPT before deploying.
Because mcp-use follows the open MCP-UI spec, the same widget renders in ChatGPT, Claude, and other MCP-UI-compatible hosts with no per-client rewrites. One view file, every chat surface. That is the entire trick: the tool call returns data; the view renders the component.
Takeaway
Tool calls carry data, views carry UI. Bind them and ChatGPT renders your React component automatically. The mcp-use docs walk through the view pipeline, and you can scaffold a working ChatGPT-ready widget in minutes with mcp-use. Start with one tool, bind one view, and ship it.