View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/Image.tsx
Image component is a drop-in replacement for the native img element inside MCP widgets. It automatically resolves relative src paths against the MCP public URL injected by the server, while leaving absolute URLs and data URIs untouched. This lets you reference files in your public/ folder with simple root-relative paths (for example /fruits/apple.png) and have them work in both local development and deployed widgets.
Image
Image component that automatically handles absolute paths using the MCP public URL.img element after resolving its src. The component is typed as
React.FC<React.ImgHTMLAttributes<globalThis.HTMLImageElement>>, so it accepts every standard img HTML attribute (for example alt, className, width, height, loading, onClick). The src prop is destructured out, resolved, and reapplied; all other props are spread onto the rendered img unchanged.
Source resolution rules applied to src:
- If
srcis falsy (undefinedor an empty string), it is returned unchanged and rendered as-is. - If
srcstarts withhttp://,https://, ordata:, it is treated as already absolute and used as-is. - Otherwise
srcis treated as a public path. The resolver strips a single leading slash fromsrcand joins it to the public URL base as`${publicUrl}/${cleanSrc}`. - If no public URL base is available (the resolver falls back to an empty string), the original
srcis returned unchanged.
window globals injected by the MCP server. It prefers window.__mcpPublicAssetsUrl (used by static deployments such as a Supabase storage bucket) and falls back to window.__mcpPublicUrl (used for dynamic serving, for example http://localhost:3000/mcp-use/public). When window is undefined (server-side rendering), the base resolves to an empty string and paths are returned unchanged. The base is expected to have no trailing slash, matching the MCPServer implementation, so exactly one slash separates the base from the resolved path.
Props
SignatureImage source URL or path. A root-relative path such as/fruits/apple.pngis prefixed with the MCP public URL; anhttp://,https://, ordata:value is used as-is. Inherited fromReact.ImgHTMLAttributes, so it is optional at the type level, but in practice you should always provide it.Any other standardimgattribute (for examplealt,className,style,width,height,loading,srcSet,onClick). These are forwarded to the underlyingimgelement without modification.
Source Resolution
The component handles three source formats. Each row shows an inputsrc and how it is rendered when the public URL base is, for example, http://localhost:3000/mcp-use/public.
Input src | Resolved output | Rule |
|---|---|---|
https://example.com/image.jpg | https://example.com/image.jpg | Absolute URL, used as-is |
http://example.com/image.jpg | http://example.com/image.jpg | Absolute URL, used as-is |
data:image/png;base64,... | data:image/png;base64,... | Data URI, used as-is |
/fruits/apple.png | http://localhost:3000/mcp-use/public/fruits/apple.png | Public path, leading slash stripped, joined to base |
fruits/apple.png | http://localhost:3000/mcp-use/public/fruits/apple.png | Public path with no leading slash, joined to base |
/fruits/apple.png (no base available) | /fruits/apple.png | Falls back to the original src |
"" or undefined | unchanged | Falsy source returned as-is |
Basic Usage
Public Folder Images
When referencing images from yourpublic/ folder, use paths relative to the public root. The component resolves them to the correct URL using the injected window globals.
The
Image component prefers window.__mcpPublicAssetsUrl when it is available (static deployments such as a Supabase storage bucket), falling back to window.__mcpPublicUrl for dynamic serving.Window Globals
The component reads thesewindow globals, which are injected by the MCP server or set at build time:
window.__mcpPublicAssetsUrl: Base URL for public assets in static deployments (for example a Supabase storage bucket). Preferred when present.window.__mcpPublicUrl: Base URL for public assets (for examplehttp://localhost:3000/mcp-use/public). Used as the fallback.
window (server-side rendering), the resolver uses an empty base and returns each src unchanged.
Related
McpUseProvider
Unified provider that supplies widget context to components like
Image.useFiles
Hook for working with widget files and resolving file URLs.