-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApp.tsx
More file actions
130 lines (117 loc) · 3.53 KB
/
App.tsx
File metadata and controls
130 lines (117 loc) · 3.53 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom/client';
import { MCPProvider, useMCP, MCPStatus, InputSchemaForm, ReactJson } from 'mcp-uiux';
const AppContent: React.FC = () => {
const [serverUrl, setServerUrl] = useState('');
const [resourcePath, setResourcePath] = useState('');
const [selectedTool, setSelectedTool] = useState<any>(null);
const [formData, setFormData] = useState<any>(null);
const [debug, setDebug] = useState(false);
const {
connect,
loading,
error,
tools,
resources,
resourceTemplates,
prompts,
notifications
} = useMCP();
useEffect(() => {
if (localStorage.getItem('mcp-uiux-serverUrl')) {
setServerUrl(localStorage.getItem('mcp-uiux-serverUrl') || 'http://localhost:8080');
} else {
setServerUrl('http://localhost:8080');
}
if (localStorage.getItem('mcp-uiux-resourcePath')) {
setResourcePath(localStorage.getItem('mcp-uiux-resourcePath') || '');
}
}, [])
useEffect(() => {
connect(serverUrl, resourcePath);
}, [serverUrl, resourcePath]);
const handleToolSelect = (tool: any) => {
setSelectedTool(tool);
setFormData(null);
};
const handleFormComplete = (data: any) => {
setFormData(data);
setSelectedTool(null);
// console.log('表单数据:', data);
// 这里可以添加调用工具的逻辑
};
return (
<div style={{ padding: '20px' }}>
<h1>MCP UIUX 示例 <button onClick={()=>setDebug(!debug)}>测试</button></h1>
{
debug&& Object.keys(notifications).map((key, index) => (
<div key={index}>
{key}: {notifications[key]}
</div>
))
}
{debug&& <div style={{ display: 'flex' }}>
{tools.length > 0 && <div style={{ flex: '1', marginRight: '20px' }}>
<h3>工具列表 ({tools.length})</h3>
<ul style={{ cursor: 'pointer' }}>
{tools.map((tool, index) => (
<li
key={index}
onClick={() => handleToolSelect(tool)}
style={{
padding: '8px',
backgroundColor: selectedTool && selectedTool.name === tool.name ? '#e6f7ff' : 'transparent',
borderRadius: '4px'
}}
>
{tool.name}
</li>
))}
</ul>
</div>}
<div style={{ flex: '2' }}>
{selectedTool && (
<div>
<h3>工具:{selectedTool.name}</h3>
<div style={{ marginBottom: '20px' }}>
<InputSchemaForm tool={selectedTool}
onComplete={handleFormComplete} />
</div>
</div>
)}
{formData && (
<div>
<h4>表单数据</h4>
<ReactJson src={formData} />
{/* <pre>{JSON.stringify(formData, null, 2)}</pre> */}
</div>
)}
</div>
</div>}
{debug&& resources.length > 0 && <div>
<h3>资源列表 ({resources.length})</h3>
<ul>
{resources.map((resource, index) => (
<li key={index}>{decodeURIComponent(resource.uri)}</li>
))}
</ul>
</div>}
<MCPStatus
serverUrl={serverUrl}
showSettings={true}
/>
</div>
);
};
const App: React.FC = () => {
return (
<MCPProvider>
<AppContent />
</MCPProvider>
);
};
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);