Files
funstat-mcp/core/test_server.py
2025-11-01 21:58:03 +08:00

87 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
测试 Funstat MCP Server
这个脚本会测试 MCP 服务器的所有功能
"""
import asyncio
import sys
from server import FunstatMCPServer
async def test_server():
"""测试服务器功能"""
print("=" * 60)
print("🧪 Funstat MCP Server 测试")
print("=" * 60)
print()
server = FunstatMCPServer()
try:
# 初始化
print("1⃣ 初始化服务器...")
await server.initialize()
print("✅ 初始化成功")
print()
# 测试工具列表
print("2⃣ 获取工具列表...")
tools = await server.list_tools()
print(f"✅ 找到 {len(tools)} 个工具:")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
print()
# 测试 /start 命令
print("3⃣ 测试 /start 命令...")
result = await server.call_tool("funstat_start", {})
response = result[0].text
print("✅ 响应:")
print(response[:500])
if len(response) > 500:
print(f" ... (还有 {len(response) - 500} 个字符)")
print()
# 测试 /balance 命令
print("4⃣ 测试 /balance 命令...")
result = await server.call_tool("funstat_balance", {})
print("✅ 响应:")
print(result[0].text)
print()
# 测试搜索功能
print("5⃣ 测试搜索功能 (关键词: python)...")
result = await server.call_tool("funstat_search", {"query": "python"})
response = result[0].text
print("✅ 响应:")
print(response[:500])
if len(response) > 500:
print(f" ... (还有 {len(response) - 500} 个字符)")
print()
# 测试缓存
print("6⃣ 测试缓存 (再次搜索 python)...")
result = await server.call_tool("funstat_search", {"query": "python"})
print("✅ 响应: (应该来自缓存)")
print(result[0].text[:200])
print()
print("=" * 60)
print("✅ 所有测试通过!")
print("=" * 60)
except Exception as e:
print(f"❌ 测试失败: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
finally:
if server.client:
await server.client.disconnect()
if __name__ == "__main__":
asyncio.run(test_server())