import asyncio
import httpx
import json

async def test_mcp_detailed():
    print("详细测试LiteLLM的MCP端点...")
    
    async with httpx.AsyncClient() as client:
        try:
            print("\n测试端点: http://localhost:4000/mcp/")
            
            # 使用流式请求来处理SSE
            async with client.stream(
                "GET",
                "http://localhost:4000/mcp/",
                headers={
                    "Authorization": "Bearer sk-1234567890abcdef",
                    "Accept": "text/event-stream",
                    "Cache-Control": "no-cache"
                },
                timeout=10.0
            ) as response:
                print(f"状态码: {response.status_code}")
                print(f"响应头: {dict(response.headers)}")
                
                if response.status_code == 200:
                    print("开始读取SSE流...")
                    content = ""
                    async for chunk in response.aiter_text():
                        content += chunk
                        print(f"收到数据块: {repr(chunk)}")
                        
                        # 如果收到足够的数据就停止
                        if len(content) > 1000:
                            print("收到足够数据，停止读取")
                            break
                    
                    print(f"\n完整内容: {content}")
                else:
                    error_content = await response.aread()
                    print(f"错误响应: {error_content.decode()}")
                    
        except Exception as e:
            print(f"请求失败: {type(e).__name__}: {e}")
            import traceback
            traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(test_mcp_detailed())