@mcp-ui/client Overview
The @mcp-ui/client package helps you render UI resources sent from an MCP-enabled server. The primary component for this is <UIResourceRenderer />, which automatically detects the resource type and renders the appropriate component for it.
What's Included?
Components
<UIResourceRenderer />: The main component you'll use. It inspects the resource'smimeTypeand renders either<HTMLResourceRenderer />or<RemoteDOMResourceRenderer />internally.<HTMLResourceRenderer />: Internal component for HTML/URL resources<RemoteDOMResourceRenderer />: Internal component for remote DOM resourcesisUIResource(): Utility function to check if content is a UI resource (replaces manualcontent.type === 'resource' && content.resource.uri?.startsWith('ui://')checks)
Utility Functions
getResourceMetadata(resource): Extracts the resource's_metacontent (standard MCP metadata)getUIResourceMetadata(resource): Extracts only the MCP-UI specific metadata keys (prefixed withmcpui.dev/ui-) from the resource's_metacontent
Purpose
- Standardized UI: mcp-ui's client guarantees full compatibility with the latest MCP UI standards.
- Simplified Rendering: Abstract away the complexities of handling different resource types.
- Security: Renders user-provided HTML and scripts within sandboxed iframes.
- Interactivity: Provides a unified mechanism (
onUIActionprop) for UI resources to communicate back to the host application.
Building
This package uses Vite in library mode. It outputs ESM (.mjs) and UMD (.js) formats, plus TypeScript declarations (.d.ts). react is externalized.
To build just this package from the monorepo root:
pnpm build --filter @mcp-ui/clientUtility Functions Reference
getResourceMetadata(resource)
Extracts the standard MCP metadata from a resource's _meta property.
import { getResourceMetadata } from '@mcp-ui/client';
const resource = {
uri: 'ui://example/demo',
mimeType: 'text/html',
text: '<div>Hello</div>',
_meta: {
title: 'Demo Component',
version: '1.0.0',
'mcpui.dev/ui-preferred-frame-size': ['800px', '600px'],
'mcpui.dev/ui-initial-render-data': { theme: 'dark' },
author: 'Development Team'
}
};
const metadata = getResourceMetadata(resource);
console.log(metadata);
// Output: {
// title: 'Demo Component',
// version: '1.0.0',
// 'mcpui.dev/ui-preferred-frame-size': ['800px', '600px'],
// 'mcpui.dev/ui-initial-render-data': { theme: 'dark' },
// author: 'Development Team'
// }2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
getUIResourceMetadata(resource)
Extracts only the MCP-UI specific metadata keys (those prefixed with mcpui.dev/ui-) from a resource's _meta property, with the prefixes removed for easier access.
import { getUIResourceMetadata } from '@mcp-ui/client';
const resource = {
uri: 'ui://example/demo',
mimeType: 'text/html',
text: '<div>Hello</div>',
_meta: {
title: 'Demo Component',
version: '1.0.0',
'mcpui.dev/ui-preferred-frame-size': ['800px', '600px'],
'mcpui.dev/ui-initial-render-data': { theme: 'dark' },
author: 'Development Team'
}
};
const uiMetadata = getUIResourceMetadata(resource);
console.log(uiMetadata);
// Output: {
// 'preferred-frame-size': ['800px', '600px'],
// 'initial-render-data': { theme: 'dark' },
// }2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Usage Examples
These utility functions are particularly useful when you need to access metadata programmatically:
import { getUIResourceMetadata, UIResourceRenderer } from '@mcp-ui/client';
function SmartResourceRenderer({ resource }) {
const uiMetadata = getUIResourceMetadata(resource);
// Use metadata to make rendering decisions
const initialRenderData = uiMetadata['initial-render-data'];
const containerClass = initialRenderData.preferredContext === 'hero' ? 'hero-container' : 'default-container';
return (
<div className={containerClass}>
{preferredContext === 'hero' && (
<h2>Featured Component</h2>
)}
<UIResourceRenderer resource={resource} />
</div>
);
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
See More
See the following pages for more details:

