Skip to content

Commit 6c8bed2

Browse files
committed
instructions
1 parent 961f118 commit 6c8bed2

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

exercises/01.simple/README.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
11
# Simple
2+
3+
MCP UI enables servers to send rich, interactive user interfaces along with their responses, transforming AI chat from text-only interactions into visually engaging experiences. Instead of just returning plain text, your MCP server can now provide HTML content that clients can render as actual UI components.
4+
5+
This capability opens up entirely new possibilities for AI applications. Instead of describing a chart or form, you can actually show one. Instead of listing data in text format, you can present it in a beautiful, interactive interface.
6+
7+
Example:
8+
9+
```ts
10+
import { createUIResource } from '@mcp-ui/server'
11+
12+
// Create a UI resource with raw HTML
13+
const resource = createUIResource({
14+
uri: 'ui://weather-card/lagos-nigeria',
15+
content: {
16+
type: 'rawHtml',
17+
htmlString: `
18+
<div style="padding: 20px; border: 1px solid #ccc; border-radius: 8px; background: linear-gradient(135deg, #74b9ff, #0984e3); color: white;">
19+
<h1>Lagos, Nigeria</h1>
20+
<p>85°F - Partly Cloudy</p>
21+
<p>Humidity: 78% | Wind: 12 mph</p>
22+
</div>
23+
`,
24+
},
25+
encoding: 'text',
26+
})
27+
```
28+
29+
<callout-info>
30+
The `createUIResource` function is the foundation of MCP UI. It takes your
31+
HTML content and packages it into a format that MCP clients can understand and
32+
render. The `uri` parameter creates a unique identifier for your UI resource,
33+
while the `content` specifies what type of UI you're providing.
34+
</callout-info>
35+
36+
Here's how this works in practice. When an AI assistant needs to show weather information, instead of returning plain text like "Lagos, Nigeria: 85°F, Partly Cloudy, Humidity: 78%", it can return a UI resource that renders as an actual visual weather card with proper styling and structure.
37+
38+
The MCP UI specification defines several content types, but we'll start with the simplest: `rawHtml`. This allows you to send any HTML string that will be rendered directly by the client. This is perfect for static content, simple layouts, and getting started with UI in MCP.
39+
40+
<callout-success>
41+
From [the MCP UI
42+
documentation](https://mcpui.dev/guide/server/typescript/usage-examples#metadata-configuration-examples):
43+
Raw HTML content is delivered as `text/html` MIME type and can include any
44+
valid HTML markup, making it ideal for simple UI components and static content
45+
display.
46+
</callout-success>
47+
48+
Here's a sequence diagram showing how UI resources flow through the MCP system:
49+
50+
```mermaid
51+
sequenceDiagram
52+
participant User
53+
participant App
54+
participant Client
55+
participant Server
56+
57+
User->>App: Request weather information
58+
App->>Client: Call get_weather tool
59+
Client->>Server: Call get_weather tool
60+
Server->>Server: Fetch weather data
61+
Server->>Server: Create HTML content
62+
Server->>Server: Package as UI resource
63+
Server->>Client: Return UI resource
64+
Client->>App: Return UI resource
65+
App->>App: Render HTML content
66+
App->>User: Display visual weather card
67+
```
68+
69+
In this exercise, you'll implement a tool that returns a UI resource instead of plain text. You'll learn how to:
70+
71+
- Import and use the `createUIResource` function from `@mcp-ui/server`
72+
- Create HTML content that displays data in a structured, visual way
73+
- Handle error cases (like missing data) with appropriate UI feedback
74+
- Package your HTML as a proper MCP UI resource
75+
76+
The key difference from regular MCP tools is that instead of returning text content, you'll return a UI resource that clients can render as actual visual components. This transforms the user experience from reading text descriptions to interacting with rich, visual interfaces.
77+
78+
- 📜 [MCP UI Server Documentation](https://mcpui.dev/guide/server/typescript/usage-examples#metadata-configuration-examples)

0 commit comments

Comments
 (0)