test_mcp_registry.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from __future__ import annotations
  2. """验证自建旅行MCP与高德MCP服务器的工具注册与加载是否正常。"""
  3. import asyncio
  4. from rich.console import Console
  5. from rich.table import Table
  6. from app.mcp_client import load_mcp_tools
  7. console = Console()
  8. async def main() -> None:
  9. bundle = await load_mcp_tools()
  10. console.print(
  11. {
  12. "全部MCP工具数": len(
  13. bundle.all_tools
  14. ),
  15. "旅行查询工具数": len(
  16. bundle.travel_tools
  17. ),
  18. "高德工具数": len(
  19. bundle.amap_tools
  20. ),
  21. }
  22. )
  23. table = Table(title="已加载MCP工具")
  24. table.add_column("工具类型")
  25. table.add_column("工具名称")
  26. table.add_column("说明")
  27. travel_names = {
  28. tool.name
  29. for tool in bundle.travel_tools
  30. }
  31. for tool in bundle.all_tools:
  32. tool_type = (
  33. "旅行查询"
  34. if tool.name in travel_names
  35. else "高德地图"
  36. )
  37. table.add_row(
  38. tool_type,
  39. tool.name,
  40. (tool.description or "")[:100],
  41. )
  42. console.print(table)
  43. if __name__ == "__main__":
  44. asyncio.run(main())