<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MySQL MCP 聊天测试</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
width: 100%;
max-width: 900px;
height: 90vh;
background: white;
border-radius: 16px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
position: relative;
}
.header h1 {
font-size: 24px;
margin-bottom: 5px;
text-align: center;
}
.header p {
font-size: 14px;
opacity: 0.9;
text-align: center;
}
.header-actions {
position: absolute;
top: 20px;
right: 20px;
display: flex;
gap: 10px;
}
.icon-button {
background: rgba(255, 255, 255, 0.2);
border: none;
color: white;
width: 36px;
height: 36px;
border-radius: 50%;
cursor: pointer;
font-size: 18px;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.3s;
}
.icon-button:hover {
background: rgba(255, 255, 255, 0.3);
}
.messages {
flex: 1;
overflow-y: auto;
padding: 20px;
background: #f7f9fc;
}
.message {
margin-bottom: 16px;
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message.user {
text-align: right;
}
.message-content {
display: inline-block;
max-width: 70%;
padding: 12px 16px;
border-radius: 12px;
word-wrap: break-word;
}
.message.user .message-content {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.message.assistant .message-content {
background: white;
color: #333;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.message.system .message-content {
background: #fff3cd;
color: #856404;
border-left: 4px solid #ffc107;
}
.tool-execution-container {
margin: 8px 0;
border: 1px solid #e0e0e0;
border-radius: 8px;
overflow: hidden;
}
.tool-execution-header {
background: #f5f5f5;
padding: 10px 12px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: space-between;
user-select: none;
}
.tool-execution-header:hover {
background: #eeeeee;
}
.tool-execution-header .title {
font-weight: bold;
color: #666;
font-size: 13px;
}
.tool-execution-header .toggle {
font-size: 12px;
color: #999;
}
.tool-execution-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
}
.tool-execution-content.expanded {
max-height: 2000px;
}
.tool-call {
background: #e3f2fd;
border-left: 4px solid #2196f3;
padding: 12px;
margin: 0;
font-size: 13px;
}
.tool-call .tool-name {
font-weight: bold;
color: #1976d2;
margin-bottom: 4px;
}
.tool-call pre {
background: #f5f5f5;
padding: 8px;
border-radius: 4px;
overflow-x: auto;
margin-top: 4px;
}
.tool-result {
background: #e8f5e9;
border-left: 4px solid #4caf50;
padding: 12px;
margin: 0;
font-size: 13px;
}
.tool-result .tool-name {
font-weight: bold;
color: #388e3c;
margin-bottom: 4px;
}
.tool-error {
background: #ffebee;
border-left: 4px solid #f44336;
padding: 12px;
margin: 0;
font-size: 13px;
}
.input-area {
padding: 20px;
background: white;
border-top: 1px solid #e0e0e0;
}
.input-container {
display: flex;
gap: 10px;
}
#messageInput {
flex: 1;
padding: 12px 16px;
border: 2px solid #e0e0e0;
border-radius: 24px;
font-size: 14px;
outline: none;
transition: border-color 0.3s;
}
#messageInput:focus {
border-color: #667eea;
}
#sendButton {
padding: 12px 32px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 24px;
font-size: 14px;
font-weight: bold;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
#sendButton:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
#sendButton:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.loading {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background: #667eea;
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 0.3; }
50% { opacity: 1; }
}
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* 历史记录侧边栏 */
.history-sidebar {
position: fixed;
top: 0;
right: -400px;
width: 400px;
height: 100vh;
background: white;
box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
transition: right 0.3s ease;
z-index: 1000;
display: flex;
flex-direction: column;
}
.history-sidebar.open {
right: 0;
}
.history-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.history-header h2 {
font-size: 18px;
margin: 0;
}
.close-button {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
}
.history-list {
flex: 1;
overflow-y: auto;
padding: 10px;
}
.history-item {
background: #f7f9fc;
border-radius: 8px;
padding: 12px;
margin-bottom: 10px;
cursor: pointer;
transition: background 0.2s;
position: relative;
}
.history-item:hover {
background: #e8f0fe;
}
.history-item.active {
background: #d1e7ff;
border-left: 4px solid #667eea;
}
.history-item-title {
font-weight: bold;
color: #333;
margin-bottom: 4px;
font-size: 14px;
}
.history-item-preview {
color: #666;
font-size: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.history-item-time {
color: #999;
font-size: 11px;
margin-top: 4px;
}
.history-item-delete {
position: absolute;
top: 10px;
right: 10px;
background: #ff4444;
color: white;
border: none;
border-radius: 4px;
padding: 4px 8px;
font-size: 12px;
cursor: pointer;
opacity: 0;
transition: opacity 0.2s;
}
.history-item:hover .history-item-delete {
opacity: 1;
}
.history-empty {
text-align: center;
color: #999;
padding: 40px 20px;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
display: none;
}
.overlay.show {
display: block;
}
.current-chat-title {
font-size: 12px;
opacity: 0.8;
margin-top: 5px;
text-align: center;
}
</style>
</head>
<body>
<!-- 遮罩层 -->
<div class="overlay" id="overlay"></div>
<!-- 历史记录侧边栏 -->
<div class="history-sidebar" id="historySidebar">
<div class="history-header">
<h2>📋 聊天历史</h2>
<button class="close-button" id="closeHistoryButton">×</button>
</div>
<div class="history-list" id="historyList"></div>
</div>
<div class="container">
<div class="header">
<h1>🤖 MySQL MCP 聊天助手</h1>
<p>通过自然语言操作数据库</p>
<div class="header-actions">
<button id="historyButton" class="icon-button" title="聊天历史">📋</button>
<button id="newChatButton" class="icon-button" title="新建对话">➕</button>
</div>
</div>
<div class="messages" id="messages">
</div>
<div class="input-area">
<div class="input-container">
<input
type="text"
id="messageInput"
placeholder="输入你的问题..."
autocomplete="off"
/>
<button id="sendButton">发送</button>
</div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>