-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathumd-example.html
More file actions
116 lines (104 loc) · 2.93 KB
/
umd-example.html
File metadata and controls
116 lines (104 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MCP UIUX UMD 示例</title>
<!-- 引入 React 和 ReactDOM -->
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<!-- 引入 Babel 用于 JSX 转换 -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- 引入 MCP UIUX 库 -->
<script src="../dist/index.umd.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input {
padding: 8px;
margin: 5px 0;
}
button {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
ul {
list-style-type: none;
padding: 0;
}
li {
padding: 8px;
margin: 5px 0;
background-color: #f2f2f2;
border-radius: 4px;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { MCPProvider, useMCP, MCPStatus } = MCPUIUX;
const AppContent = () => {
const [serverUrl, setServerUrl] = React.useState('http://localhost:8080');
const [resourcePath, setResourcePath] = React.useState('');
const {
connect,
loading,
error,
tools,
resources,
resourceTemplates,
prompts
} = useMCP();
React.useEffect(() => {
connect(serverUrl, resourcePath);
}, [serverUrl, resourcePath]);
return (
<div>
<h1>MCP UIUX UMD 示例</h1>
<div style={{ marginBottom: '20px' }}>
<div>
<label>服务器地址:</label>
<input
type="text"
value={serverUrl}
onChange={(e) => setServerUrl(e.target.value)}
style={{ width: '300px', marginLeft: '10px' }}
/>
</div>
<div style={{ marginTop: '10px' }}>
<label>资源路径过滤:</label>
<input
type="text"
value={resourcePath}
onChange={(e) => setResourcePath(e.target.value)}
style={{ width: '300px', marginLeft: '10px' }}
/>
</div>
</div>
{loading && <div>正在加载...</div>}
{error && <div style={{ color: 'red' }}>错误: {error}</div>}
<MCPStatus serverUrl={serverUrl} />
</div>
);
};
const App = () => {
return (
<MCPProvider>
<AppContent />
</MCPProvider>
);
};
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
</body>
</html>