PrometheusGroup commited on
Commit
7dec804
·
verified ·
1 Parent(s): 1b4e69f

create a dark styled web page to go with this file:

Browse files

import React, { useState, useMemo } from 'react';
import { createRoot } from 'react-dom/client';

type ToolName = 'list_files' | 'read_file' | 'create_file' | 'write_file' | 'delete_file' | 'identify_log_errors';

interface Tool {
value: ToolName;
label: string;
description: string;
params: { name: string; type: 'text' | 'textarea'; label: string }[];
}

const TOOLS: Tool[] = [
{ value: 'list_files', label: 'List Files', description: 'Lists files and directories in a given path.', params: [{ name: 'path', type: 'text', label: 'Directory Path' }] },
{ value: 'read_file', label: 'Read File', description: 'Reads the content of a specific file.', params: [{ name: 'path', type: 'text', label: 'File Path' }] },
{ value: 'create_file', label: 'Create File', description: 'Creates a new file with optional content.', params: [{ name: 'path', type: 'text', label: 'New File Path' }, { name: 'content', type: 'textarea', label: 'Initial Content (optional)' }] },
{ value: 'write_file', label: 'Write to File', description: 'Writes content to a file, creating a backup first.', params: [{ name: 'path', type: 'text', label: 'File Path' }, { name: 'content', type: 'textarea', label: 'New Content' }] },
{ value: 'delete_file', label: 'Delete File', description: 'Deletes a specific file.', params: [{ name: 'path', type: 'text', label: 'File to Delete' }] },
{ value: 'identify_log_errors', label: 'Identify Log Errors', description: 'Scans a log file for common error messages.', params: [{ name: 'log_file_path', type: 'text', label: 'Log File Path' }] },
];

const App = () => {
const [selectedTool, setSelectedTool] = useState<ToolName>(TOOLS[0].value);
const [parameters, setParameters] = useState<Record<string, string>>({ path: 'C:\\temp' });
const [isLoading, setIsLoading] = useState(false);
const [response, setResponse] = useState<any>(null);
const [error, setError] = useState('');

const currentTool = useMemo(() => TOOLS.find(t => t.value === selectedTool)!, [selectedTool]);

const handleToolChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newToolName = e.target.value as ToolName;
setSelectedTool(newToolName);
// Reset parameters when tool changes
setParameters({});
setResponse(null);
setError('');
};

const handleParamChange = (name: string, value: string) => {
setParameters(prev => ({ ...prev, [name]: value }));
};

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
setResponse(null);
setError('');

const invocation_id = `mcp-ui-${Date.now()}`;
const endpoint = `http://127.0.0.1:8000/mcp/invoke/${selectedTool}`;

try {
const res = await fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tool_name: selectedTool,
invocation_id,
parameters,
}),
});

const data = await res.json();
if (!res.ok || data.result?.status === 'error') {
throw new Error(data.result?.message || `Server responded with status: ${res.status}`);
}
setResponse(data);
} catch (err) {
setError(err instanceof Error ? err.message : 'An unknown error occurred.');
} finally {
setIsLoading(false);
}
};

return (
<div className="container">
<header>
<h1>MCP Toolkit Control Panel</h1>
<p>A client to interact with the Maintenance & Control Program toolkit server.</p>
</header>

<main>
<div className="card form-card">
<h2>Select a Tool</h2>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label htmlFor="tool-select">Tool</label>
<select id="tool-select" value={selectedTool} onChange={handleToolChange}>
{TOOLS.map(tool => (
<option key={tool.value} value={tool.value}>{tool.label}</option>
))}
</select>
<p>{currentTool.description}</p>
</div>

{currentTool.params.map(param => (
<div className="form-group" key={param.name}>
<label htmlFor={param.name}>{param.label}</label>
{param.type === 'textarea' ? (
<textarea
id={param.name}
value={parameters[param.name] || ''}
onChange={(e) => handleParamChange(param.name, e.target.value)}
required
/>
) : (
<input
id={param.name}
type="text"
value={parameters[param.name] || ''}
onChange={(e) => handleParamChange(param.name, e.target.value)}
required
/>
)}
</div>
))}

<button type="submit" disabled={isLoading}>
{isLoading ? 'Running...' : `Run: ${currentTool.label}`}
</button>
</form>
</div>

{isLoading && (
<div className="card status-card">
<div className="loader">
<span></span>
<span></span>
<span></span>
</div>
<p>Communicating with MCP Server...</p>
</div>
)}

{error && (
<div className="card result-card error">
<h2>Error</h2>
<pre>{error}</pre>
</div>
)}

{response && (
<div className="card result-card success">
<h2>Result for Invocation: {response.invocation_id}</h2>
<pre>{JSON.stringify(response.result, null, 2)}</pre>
</div>
)}
</main>
</div>
);
};

const container = document.getElementById('root');
const root = createRoot(container!);
root.render(<App />);

Files changed (3) hide show
  1. index.html +17 -1
  2. script.js +144 -0
  3. style.css +166 -0
index.html CHANGED
@@ -1 +1,17 @@
1
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>MCP Toolkit Control Panel</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ </head>
10
+ <body class="dark-theme">
11
+ <div id="root"></div>
12
+ <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
13
+ <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
14
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
15
+ <script type="text/babel" src="script.js"></script>
16
+ </body>
17
+ </html>
script.js CHANGED
@@ -1 +1,145 @@
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ const TOOLS = [
3
+ { value: 'list_files', label: 'List Files', description: 'Lists files and directories in a given path.', params: [{ name: 'path', type: 'text', label: 'Directory Path' }] },
4
+ { value: 'read_file', label: 'Read File', description: 'Reads the content of a specific file.', params: [{ name: 'path', type: 'text', label: 'File Path' }] },
5
+ { value: 'create_file', label: 'Create File', description: 'Creates a new file with optional content.', params: [{ name: 'path', type: 'text', label: 'New File Path' }, { name: 'content', type: 'textarea', label: 'Initial Content (optional)' }] },
6
+ { value: 'write_file', label: 'Write to File', description: 'Writes content to a file, creating a backup first.', params: [{ name: 'path', type: 'text', label: 'File Path' }, { name: 'content', type: 'textarea', label: 'New Content' }] },
7
+ { value: 'delete_file', label: 'Delete File', description: 'Deletes a specific file.', params: [{ name: 'path', type: 'text', label: 'File to Delete' }] },
8
+ { value: 'identify_log_errors', label: 'Identify Log Errors', description: 'Scans a log file for common error messages.', params: [{ name: 'log_file_path', type: 'text', label: 'Log File Path' }] },
9
+ ];
10
+
11
+ function App() {
12
+ const [selectedTool, setSelectedTool] = React.useState(TOOLS[0].value);
13
+ const [parameters, setParameters] = React.useState({ path: 'C:\\temp' });
14
+ const [isLoading, setIsLoading] = React.useState(false);
15
+ const [response, setResponse] = React.useState(null);
16
+ const [error, setError] = React.useState('');
17
+
18
+ const currentTool = React.useMemo(() => TOOLS.find(t => t.value === selectedTool), [selectedTool]);
19
+
20
+ const handleToolChange = (e) => {
21
+ const newToolName = e.target.value;
22
+ setSelectedTool(newToolName);
23
+ setParameters({});
24
+ setResponse(null);
25
+ setError('');
26
+ };
27
+
28
+ const handleParamChange = (name, value) => {
29
+ setParameters(prev => ({ ...prev, [name]: value }));
30
+ };
31
+
32
+ const handleSubmit = async (e) => {
33
+ e.preventDefault();
34
+ setIsLoading(true);
35
+ setResponse(null);
36
+ setError('');
37
+
38
+ const invocation_id = `mcp-ui-${Date.now()}`;
39
+ const endpoint = `http://127.0.0.1:8000/mcp/invoke/${selectedTool}`;
40
+
41
+ try {
42
+ const res = await fetch(endpoint, {
43
+ method: 'POST',
44
+ headers: { 'Content-Type': 'application/json' },
45
+ body: JSON.stringify({
46
+ tool_name: selectedTool,
47
+ invocation_id,
48
+ parameters,
49
+ }),
50
+ });
51
+
52
+ const data = await res.json();
53
+ if (!res.ok || data.result?.status === 'error') {
54
+ throw new Error(data.result?.message || `Server responded with status: ${res.status}`);
55
+ }
56
+ setResponse(data);
57
+ } catch (err) {
58
+ setError(err instanceof Error ? err.message : 'An unknown error occurred.');
59
+ } finally {
60
+ setIsLoading(false);
61
+ }
62
+ };
63
+
64
+ return (
65
+ <div className="container">
66
+ <header>
67
+ <h1>MCP Toolkit Control Panel</h1>
68
+ <p>A client to interact with the Maintenance & Control Program toolkit server.</p>
69
+ </header>
70
+
71
+ <main>
72
+ <div className="card form-card">
73
+ <h2>Select a Tool</h2>
74
+ <form onSubmit={handleSubmit}>
75
+ <div className="form-group">
76
+ <label htmlFor="tool-select">Tool</label>
77
+ <select id="tool-select" value={selectedTool} onChange={handleToolChange}>
78
+ {TOOLS.map(tool => (
79
+ <option key={tool.value} value={tool.value}>{tool.label}</option>
80
+ ))}
81
+ </select>
82
+ <p>{currentTool.description}</p>
83
+ </div>
84
+
85
+ {currentTool.params.map(param => (
86
+ <div className="form-group" key={param.name}>
87
+ <label htmlFor={param.name}>{param.label}</label>
88
+ {param.type === 'textarea' ? (
89
+ <textarea
90
+ id={param.name}
91
+ value={parameters[param.name] || ''}
92
+ onChange={(e) => handleParamChange(param.name, e.target.value)}
93
+ required
94
+ />
95
+ ) : (
96
+ <input
97
+ id={param.name}
98
+ type="text"
99
+ value={parameters[param.name] || ''}
100
+ onChange={(e) => handleParamChange(param.name, e.target.value)}
101
+ required
102
+ />
103
+ )}
104
+ </div>
105
+ ))}
106
+
107
+ <button type="submit" disabled={isLoading}>
108
+ {isLoading ? 'Running...' : `Run: ${currentTool.label}`}
109
+ </button>
110
+ </form>
111
+ </div>
112
+
113
+ {isLoading && (
114
+ <div className="card status-card">
115
+ <div className="loader">
116
+ <span></span>
117
+ <span></span>
118
+ <span></span>
119
+ </div>
120
+ <p>Communicating with MCP Server...</p>
121
+ </div>
122
+ )}
123
+
124
+ {error && (
125
+ <div className="card result-card error">
126
+ <h2>Error</h2>
127
+ <pre>{error}</pre>
128
+ </div>
129
+ )}
130
+
131
+ {response && (
132
+ <div className="card result-card success">
133
+ <h2>Result for Invocation: {response.invocation_id}</h2>
134
+ <pre>{JSON.stringify(response.result, null, 2)}</pre>
135
+ </div>
136
+ )}
137
+ </main>
138
+ </div>
139
+ );
140
+ }
141
+
142
+ const root = ReactDOM.createRoot(document.getElementById('root'));
143
+ root.render(<App />);
144
+
145
+
style.css CHANGED
@@ -1 +1,167 @@
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ :root {
3
+ --primary: #6366F1;
4
+ --primary-dark: #4F46E5;
5
+ --background: #1A1A2E;
6
+ --card-bg: #16213E;
7
+ --text: #E6E6E6;
8
+ --text-muted: #A0AEC0;
9
+ --error: #F56565;
10
+ --success: #48BB78;
11
+ }
12
+
13
+ body.dark-theme {
14
+ background-color: var(--background);
15
+ color: var(--text);
16
+ min-height: 100vh;
17
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
18
+ }
19
+
20
+ .container {
21
+ max-width: 1200px;
22
+ margin: 0 auto;
23
+ padding: 2rem;
24
+ }
25
+
26
+ header {
27
+ margin-bottom: 2rem;
28
+ text-align: center;
29
+ }
30
+
31
+ header h1 {
32
+ color: var(--primary);
33
+ font-size: 2.5rem;
34
+ margin-bottom: 0.5rem;
35
+ }
36
+
37
+ header p {
38
+ color: var(--text-muted);
39
+ font-size: 1.1rem;
40
+ }
41
+
42
+ .card {
43
+ background-color: var(--card-bg);
44
+ border-radius: 0.5rem;
45
+ padding: 1.5rem;
46
+ margin-bottom: 1.5rem;
47
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
48
+ }
49
+
50
+ .form-card {
51
+ border-left: 4px solid var(--primary);
52
+ }
53
+
54
+ .result-card {
55
+ border-left: 4px solid var(--success);
56
+ }
57
+
58
+ .result-card.error {
59
+ border-left-color: var(--error);
60
+ }
61
+
62
+ h2 {
63
+ color: var(--primary);
64
+ margin-top: 0;
65
+ margin-bottom: 1rem;
66
+ font-size: 1.5rem;
67
+ }
68
+
69
+ .form-group {
70
+ margin-bottom: 1rem;
71
+ }
72
+
73
+ label {
74
+ display: block;
75
+ margin-bottom: 0.5rem;
76
+ color: var(--text-muted);
77
+ }
78
+
79
+ select, input, textarea {
80
+ width: 100%;
81
+ padding: 0.75rem;
82
+ border-radius: 0.25rem;
83
+ border: 1px solid #2D3748;
84
+ background-color: #2D3748;
85
+ color: var(--text);
86
+ margin-bottom: 0.5rem;
87
+ }
88
+
89
+ textarea {
90
+ min-height: 150px;
91
+ resize: vertical;
92
+ }
93
+
94
+ button {
95
+ background-color: var(--primary);
96
+ color: white;
97
+ padding: 0.75rem 1.5rem;
98
+ border: none;
99
+ border-radius: 0.25rem;
100
+ cursor: pointer;
101
+ font-weight: bold;
102
+ transition: background-color 0.2s;
103
+ margin-top: 1rem;
104
+ }
105
+
106
+ button:hover {
107
+ background-color: var(--primary-dark);
108
+ }
109
+
110
+ button:disabled {
111
+ background-color: #4A5568;
112
+ cursor: not-allowed;
113
+ }
114
+
115
+ .loader {
116
+ display: flex;
117
+ justify-content: center;
118
+ gap: 0.5rem;
119
+ margin: 1rem 0;
120
+ }
121
+
122
+ .loader span {
123
+ display: inline-block;
124
+ width: 1rem;
125
+ height: 1rem;
126
+ border-radius: 50%;
127
+ background-color: var(--primary);
128
+ animation: bounce 1.4s infinite ease-in-out both;
129
+ }
130
+
131
+ .loader span:nth-child(1) {
132
+ animation-delay: -0.32s;
133
+ }
134
+
135
+ .loader span:nth-child(2) {
136
+ animation-delay: -0.16s;
137
+ }
138
+
139
+ @keyframes bounce {
140
+ 0%, 80%, 100% {
141
+ transform: scale(0);
142
+ }
143
+ 40% {
144
+ transform: scale(1);
145
+ }
146
+ }
147
+
148
+ pre {
149
+ background-color: #2D3748;
150
+ padding: 1rem;
151
+ border-radius: 0.25rem;
152
+ overflow-x: auto;
153
+ white-space: pre-wrap;
154
+ word-wrap: break-word;
155
+ }
156
+
157
+ @media (max-width: 768px) {
158
+ .container {
159
+ padding: 1rem;
160
+ }
161
+
162
+ header h1 {
163
+ font-size: 2rem;
164
+ }
165
+ }
166
+
167
+