From d6344bde5ea1edf3140e37c4d6ebd11fac0021e2 Mon Sep 17 00:00:00 2001 From: Chingfeng Li Date: Fri, 24 Oct 2025 10:17:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0MCP=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=BE=91MCP=20Tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/test/test_page.css | 6 +- main/xiaozhi-server/test/test_page.html | 836 ++++++++++++++++++++++-- 2 files changed, 774 insertions(+), 68 deletions(-) diff --git a/main/xiaozhi-server/test/test_page.css b/main/xiaozhi-server/test/test_page.css index c70c9706..bea04994 100644 --- a/main/xiaozhi-server/test/test_page.css +++ b/main/xiaozhi-server/test/test_page.css @@ -21,9 +21,9 @@ h1 { } .section { - margin-bottom: 20px; - padding: 15px; - border-radius: 8px; + margin-bottom: 5px; + padding: 10px; + border-radius: 10px; background-color: #f9f9f9; } diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index 879d627b..2cf9a0ff 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -56,6 +56,163 @@ #fileProtocolWarning button:hover { background-color: #45a049; } + + /* MCP 工具管理样式 */ + .mcp-tools-container { + display: grid; + gap: 12px; + margin-top: 10px; + } + + .mcp-tool-card { + background-color: white; + border: 1px solid #e0e0e0; + border-radius: 8px; + padding: 15px; + transition: all 0.2s; + } + + .mcp-tool-card:hover { + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); + } + + .mcp-tool-card.disabled { + opacity: 0.6; + pointer-events: none; + } + + .mcp-tool-header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 10px; + } + + .mcp-tool-name { + font-size: 15px; + font-weight: 600; + color: #333; + flex: 1; + } + + .mcp-tool-actions { + display: flex; + gap: 6px; + } + + .mcp-tool-description { + color: #666; + font-size: 13px; + line-height: 1.5; + margin-bottom: 8px; + } + + .mcp-tool-info { + background-color: #f9f9f9; + border: 1px solid #e0e0e0; + border-radius: 4px; + padding: 8px; + font-size: 12px; + } + + .mcp-tool-info-row { + display: flex; + gap: 15px; + margin-bottom: 4px; + } + + .mcp-tool-info-label { + color: #999; + min-width: 60px; + } + + .mcp-tool-info-value { + color: #333; + font-family: 'Courier New', monospace; + } + + .mcp-property-item { + background-color: white; + border: 1px solid #e0e0e0; + border-radius: 5px; + padding: 12px; + margin-bottom: 10px; + } + + .mcp-property-header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 10px; + } + + .mcp-property-name { + font-weight: 600; + color: #333; + } + + .mcp-property-row { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 10px; + margin-bottom: 8px; + } + + .mcp-property-row-full { + margin-bottom: 8px; + } + + .mcp-small-label { + display: block; + margin-bottom: 4px; + font-size: 12px; + color: #666; + } + + .mcp-small-input { + width: 100%; + padding: 6px 8px; + border: 1px solid #ddd; + border-radius: 4px; + font-size: 13px; + } + + .mcp-checkbox-label { + display: flex; + align-items: center; + gap: 6px; + font-size: 13px; + color: #666; + cursor: pointer; + } + + .mcp-error { + background-color: #ffebee; + color: #c62828; + padding: 10px; + border-radius: 5px; + margin-bottom: 15px; + font-size: 14px; + } + + .mcp-badge { + display: inline-block; + padding: 2px 8px; + border-radius: 12px; + font-size: 11px; + font-weight: 500; + margin-left: 8px; + } + + .mcp-badge-required { + background-color: #ffebee; + color: #c62828; + } + + .mcp-badge-optional { + background-color: #e3f2fd; + color: #1976d2; + } From eb743ab57706fb84a0462370148d2592f82807ad Mon Sep 17 00:00:00 2001 From: Chingfeng Li Date: Fri, 24 Oct 2025 15:58:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BB=8Ejson=E4=B8=AD=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=B7=A5=E5=85=B7=EF=BC=8C=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/default-mcp-tools.json | 72 +++++++++++++++++++ main/xiaozhi-server/test/test_page.html | 57 +-------------- 2 files changed, 73 insertions(+), 56 deletions(-) create mode 100644 main/xiaozhi-server/test/default-mcp-tools.json diff --git a/main/xiaozhi-server/test/default-mcp-tools.json b/main/xiaozhi-server/test/default-mcp-tools.json new file mode 100644 index 00000000..2d44f2dc --- /dev/null +++ b/main/xiaozhi-server/test/default-mcp-tools.json @@ -0,0 +1,72 @@ +[ + { + "name": "self.get_device_status", + "description": "Provides the real-time information of the device, including the current status of the audio speaker, screen, battery, network, etc.\nUse this tool for: \n1. Answering questions about current condition (e.g. what is the current volume of the audio speaker?)\n2. As the first step to control the device (e.g. turn up / down the volume of the audio speaker, etc.)", + "inputSchema": { + "type": "object", + "properties": {} + }, + "mockResponse": { + "audio_speaker": { + "volume": 50, + "muted": false + }, + "screen": { + "brightness": 80, + "theme": "light" + }, + "battery": { + "level": 85, + "charging": false + }, + "network": { + "connected": true, + "type": "wifi" + } + } + }, + { + "name": "self.audio_speaker.set_volume", + "description": "Set the volume of the audio speaker. If the current volume is unknown, you must call `self.get_device_status` tool first and then call this tool.", + "inputSchema": { + "type": "object", + "properties": { + "volume": { + "type": "integer", + "minimum": 0, + "maximum": 100 + } + }, + "required": [ + "volume" + ] + }, + "mockResponse": { + "success": true, + "volume": "${volume}", + "message": "音量已设置为 ${volume}" + } + }, + { + "name": "self.screen.set_brightness", + "description": "Set the brightness of the screen.", + "inputSchema": { + "type": "object", + "properties": { + "brightness": { + "type": "integer", + "minimum": 0, + "maximum": 100 + } + }, + "required": [ + "brightness" + ] + }, + "mockResponse": { + "success": true, + "brightness": "${brightness}", + "message": "亮度已设置为 ${brightness}" + } + } +] \ No newline at end of file diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index 2cf9a0ff..b00bb9c2 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -1794,62 +1794,7 @@ // ========================================== // 默认工具数据 - const defaultMcpTools = [ - { - name: "self.get_device_status", - description: "Provides the real-time information of the device, including the current status of the audio speaker, screen, battery, network, etc.\nUse this tool for: \n1. Answering questions about current condition (e.g. what is the current volume of the audio speaker?)\n2. As the first step to control the device (e.g. turn up / down the volume of the audio speaker, etc.)", - inputSchema: { - type: "object", - properties: {} - }, - mockResponse: { - audio_speaker: { volume: 50, muted: false }, - screen: { brightness: 80, theme: 'light' }, - battery: { level: 85, charging: false }, - network: { connected: true, type: 'wifi' } - } - }, - { - name: "self.audio_speaker.set_volume", - description: "Set the volume of the audio speaker. If the current volume is unknown, you must call `self.get_device_status` tool first and then call this tool.", - inputSchema: { - type: "object", - properties: { - volume: { - type: "integer", - minimum: 0, - maximum: 100 - } - }, - required: ["volume"] - }, - mockResponse: { - success: true, - volume: "${volume}", - message: "音量已设置为 ${volume}" - } - }, - { - name: "self.screen.set_brightness", - description: "Set the brightness of the screen.", - inputSchema: { - type: "object", - properties: { - brightness: { - type: "integer", - minimum: 0, - maximum: 100 - } - }, - required: ["brightness"] - }, - mockResponse: { - success: true, - brightness: "${brightness}", - message: "亮度已设置为 ${brightness}" - } - } - ]; + const defaultMcpTools = await fetch("default-mcp-tools.json").then(res => res.json()); // 全局变量 let mcpTools = []; From 47b44bb12454bdb8f580f6131f05b9ee980efd15 Mon Sep 17 00:00:00 2001 From: Chingfeng Li Date: Fri, 24 Oct 2025 16:01:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/test/test_page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index b00bb9c2..a6672dbc 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -2133,7 +2133,7 @@ // 显示错误 function showMcpError(message) { const errorContainer = document.getElementById('mcpErrorContainer'); - errorContainer.innerHTML = `
${escapeHtml(message)}
`; + errorContainer.innerHTML = `
${message}
`; } // 编辑工具