Skip to content

Commit b362e0c

Browse files
committed
add uiresource to readme
1 parent 4e6f0bf commit b362e0c

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

packages/mcp-use/README.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,104 @@ server.listen(3000)
532532
| **♻️ Hot Reload** | Development mode with automatic reloading |
533533
| **📊 Observability** | Built-in logging and monitoring capabilities |
534534

535-
### Building UI Widgets
535+
### MCP-UI Resources
536+
537+
MCP-Use provides a unified `uiResource()` method for registering interactive UI widgets that are compatible with MCP-UI clients. This automatically creates both a tool (for dynamic parameters) and a resource (for static access).
538+
539+
#### Quick Start
540+
541+
```ts
542+
import { createMCPServer } from 'mcp-use/server'
543+
544+
const server = createMCPServer('my-server', { version: '1.0.0' })
545+
546+
// Register a widget - creates both tool and resource automatically
547+
server.uiResource({
548+
type: 'externalUrl',
549+
name: 'kanban-board',
550+
widget: 'kanban-board',
551+
title: 'Kanban Board',
552+
description: 'Interactive task management board',
553+
props: {
554+
initialTasks: {
555+
type: 'array',
556+
description: 'Initial tasks',
557+
required: false
558+
},
559+
theme: {
560+
type: 'string',
561+
default: 'light'
562+
}
563+
},
564+
size: ['900px', '600px']
565+
})
566+
567+
server.listen(3000)
568+
```
569+
570+
This automatically creates:
571+
- **Tool**: `ui_kanban-board` - Accepts parameters and returns UIResource
572+
- **Resource**: `ui://widget/kanban-board` - Static access with defaults
573+
574+
#### Three Resource Types
575+
576+
**1. External URL (Iframe)**
577+
Serve widgets from your filesystem via iframe:
578+
579+
```ts
580+
server.uiResource({
581+
type: 'externalUrl',
582+
name: 'dashboard',
583+
widget: 'dashboard',
584+
props: { userId: { type: 'string', required: true } }
585+
})
586+
```
587+
588+
**2. Raw HTML**
589+
Direct HTML content rendering:
590+
591+
```ts
592+
server.uiResource({
593+
type: 'rawHtml',
594+
name: 'welcome-card',
595+
htmlContent: `
596+
<!DOCTYPE html>
597+
<html>
598+
<body><h1>Welcome!</h1></body>
599+
</html>
600+
`
601+
})
602+
```
603+
604+
**3. Remote DOM**
605+
Interactive components using MCP-UI React components:
606+
607+
```ts
608+
server.uiResource({
609+
type: 'remoteDom',
610+
name: 'quick-poll',
611+
script: `
612+
const button = document.createElement('ui-button');
613+
button.setAttribute('label', 'Vote');
614+
root.appendChild(button);
615+
`,
616+
framework: 'react'
617+
})
618+
```
619+
620+
#### Get Started with Templates
621+
622+
```bash
623+
# Create a new project with UIResource examples
624+
npx create-mcp-use-app my-app
625+
# Select: "MCP Server with UIResource widgets"
626+
627+
cd my-app
628+
npm install
629+
npm run dev
630+
```
631+
632+
### Building Custom UI Widgets
536633

537634
MCP-Use supports building custom UI widgets for your MCP tools using React:
538635

0 commit comments

Comments
 (0)