xfl_demo_client.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import asyncio
  2. import json
  3. from fastmcp import Client
  4. client = Client("http://39.97.59.228:8071/mcp")
  5. async def call_tool():
  6. async with client:
  7. result1 = await client.call_tool("query_device_data_by_id",{"device_id": "1432344790415630337", "page_size": 20})
  8. data = json.loads(result1.content[0].text)
  9. print(json.dumps(data, ensure_ascii=False, indent=2))
  10. # result2 = await client.call_tool("list_ventanaly_monitor_data_days",{"strtype":"1730768271306147"})
  11. def parse_tool_params(schema: dict):
  12. params = {}
  13. required = schema.get("required", [])
  14. props = schema.get("properties", {})
  15. for name, info in props.items():
  16. params[name] = {
  17. "type": info.get("type"),
  18. "desc": info.get("description", ""),
  19. "required": name in required
  20. }
  21. return params
  22. async def list_all_mcp_tools_tcp():
  23. """TCP 远程MCP客户端查询工具列表"""
  24. async with client:
  25. tools = await client.list_tools()
  26. for t in tools:
  27. print(f"- {t.name}: {t.description}")
  28. params_info = parse_tool_params(t.inputSchema)
  29. print("参数详情:", params_info)
  30. asyncio.run(call_tool())
  31. # asyncio.run(list_all_mcp_tools_tcp())