test-server.js•1.77 kB
#!/usr/bin/env node
import { spawn } from 'child_process';
import { setTimeout } from 'timers/promises';
async function testServer() {
console.log('🚀 启动FastMCP服务器测试...');
// 启动服务器
const server = spawn('node', ['build/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
// 监听服务器输出
server.stdout.on('data', (data) => {
console.log('📤 服务器输出:', data.toString().trim());
});
server.stderr.on('data', (data) => {
console.log('❌ 服务器错误:', data.toString().trim());
});
// 等待服务器启动
console.log('⏳ 等待服务器启动...');
await setTimeout(3000);
// 测试健康检查端点
try {
const response = await fetch('http://localhost:3005/health');
const health = await response.text();
console.log('✅ 健康检查:', health);
} catch (error) {
console.log('❌ 健康检查失败:', error.message);
}
// 测试SSE端点
try {
const response = await fetch('http://localhost:3005/sse', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {},
}),
});
if (response.ok) {
const result = await response.json();
console.log('✅ MCP端点测试成功:', result);
} else {
const errorText = await response.text();
console.log('❌ MCP端点测试失败:', response.status, response.statusText);
console.log('错误详情:', errorText);
}
} catch (error) {
console.log('❌ MCP端点测试失败:', error.message);
}
// 关闭服务器
console.log('🛑 关闭服务器...');
server.kill('SIGTERM');
await setTimeout(1000);
console.log('✅ 测试完成');
}
testServer().catch(console.error);