#!/usr/bin/env python3
"""
本地测试脚本
"""
import sys
import asyncio
from pathlib import Path

# 添加项目路径到sys.path
sys.path.insert(0, str(Path(__file__).parent))

from cbioportal_mcp.server import CBioPortalMCPServer
from cbioportal_mcp.config import Configuration

async def test_server():
    """测试服务器"""
    print("🚀 开始测试 cBioPortal MCP 服务器...")
    
    # 创建配置
    config = Configuration()
    
    # 创建服务器实例
    server = CBioPortalMCPServer(config)
    
    # 启动服务器
    await server.startup()
    print("✅ 服务器启动成功")
    
    # 获取工具列表
    tools = server.mcp._tools
    
    if tools:
        print(f"✅ 成功获取到 {len(tools)} 个工具:")
        for i, tool in enumerate(tools.values(), 1):
            name = tool.name
            description = tool.description
            print(f"   {i}. {name}: {description}")
        print("\n🎉 本地测试通过！")
        return True
    else:
        print("❌ 未找到任何工具")
        return False
    
    # 关闭服务器
    await server.shutdown()

if __name__ == "__main__":
    try:
        success = asyncio.run(test_server())
        sys.exit(0 if success else 1)
    except Exception as e:
        print(f"❌ 测试失败: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)