60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
// 测试修复后的 MCP 连接
|
|
const { v4: uuidv4 } = require('uuid');
|
|
|
|
async function testMCPConnection() {
|
|
try {
|
|
console.log('🧪 测试 MCP 连接 (修复版)...');
|
|
|
|
// 测试健康检查
|
|
const healthResponse = await fetch('http://127.0.0.1:3100/health');
|
|
console.log('✅ 健康检查:', healthResponse.status, healthResponse.statusText);
|
|
|
|
// 测试 MCP initialize 请求 (修复 Accept 头)
|
|
const initResponse = await fetch('http://127.0.0.1:3100/mcp', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json, text/event-stream' // 修复的关键行
|
|
},
|
|
body: JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
id: uuidv4(),
|
|
method: 'initialize',
|
|
params: {
|
|
protocolVersion: "2024-11-05",
|
|
capabilities: {
|
|
roots: {
|
|
listChanged: true
|
|
},
|
|
sampling: {}
|
|
},
|
|
clientInfo: {
|
|
name: "xiaozhi-client",
|
|
version: "1.0.0"
|
|
}
|
|
}
|
|
})
|
|
});
|
|
|
|
console.log('🔧 MCP Initialize:', initResponse.status, initResponse.statusText);
|
|
|
|
if (initResponse.ok) {
|
|
const result = await initResponse.json();
|
|
console.log('✅ MCP Initialize 成功:', JSON.stringify(result, null, 2));
|
|
} else {
|
|
const error = await initResponse.text();
|
|
console.log('❌ MCP Initialize 失败:', error);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 连接错误:', error.message);
|
|
}
|
|
}
|
|
|
|
// 需要全局 fetch 支持
|
|
if (typeof fetch === 'undefined') {
|
|
const { fetch } = require('node-fetch');
|
|
global.fetch = fetch;
|
|
}
|
|
|
|
testMCPConnection(); |