xfl_demo_client.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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(tun_id: int):
  6. async with client:
  7. result1 = await client.call_tool("query_wind_by_tunid",{"tun_id":"581","model_id":2012326636757958658})
  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(581))
  31. asyncio.run(list_all_mcp_tools_tcp())