# 测试MySQL连接和基本功能
$env:DATABASE_URL = "mysql://testuser:testuser@localhost:13306/testdb"
Write-Host "==== Testing MySQL Connection ====" -ForegroundColor Green
# 先测试连接是否可用
try {
# 直接测试数据库连接
Write-Host "测试数据库连接..." -ForegroundColor Yellow
# 创建一个简单的SQL查询来测试连接
$initRequest = @'
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}
'@
$listTablesRequest = @'
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"list_tables","arguments":{}}}
'@
# 创建临时文件来测试
$tempFile = [System.IO.Path]::GetTempFileName()
@"
$initRequest
$listTablesRequest
"@ | Out-File -FilePath $tempFile -Encoding UTF8
# 运行MCP服务器
$result = Get-Content $tempFile | & ".\target\release\sqlx-mcp.exe"
Write-Host "MCP服务器响应:" -ForegroundColor Cyan
Write-Host $result -ForegroundColor White
# 清理临时文件
Remove-Item $tempFile -ErrorAction SilentlyContinue
} catch {
Write-Host "❌ 错误: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "==== 测试完成 ====" -ForegroundColor Green