import React from "react"; import ResultBlock from "./ResultBlock"; import type { MCPToolResult } from "../types/mcp"; const ToolResultRenderer: React.FC<{ result: MCPToolResult; rendererCode?: string; input?: unknown; }> = ({ result, rendererCode, input }) => { if (!rendererCode) { return ; } try { const exportMatch = rendererCode.match(/export\s+default\s+(.*)/s); if (!exportMatch) { throw new Error("Invalid renderer format - no export default found"); } const componentCode = exportMatch[1].trim(); const componentFunction = new Function( "React", "input", "output", ` const { createElement: h, Fragment } = React; const JSXComponent = ${componentCode}; return JSXComponent(input, output); ` ); const element = componentFunction(React, input || {}, result); // For object results, also show the formatted JSON below the custom renderer if (typeof result === "object" && result !== null) { return (
{element}

Request

Response

); } return element; } catch (error) { return ( ); } }; export default ToolResultRenderer;