query_export_task.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class QueryExportTaskTool:
  2. name = 'query_export_task'
  3. route_path = '/mcp/tools/queryExportTask'
  4. def __init__(self, api_client=None):
  5. self.api_client = api_client
  6. def metadata(self):
  7. return {
  8. 'name': self.name,
  9. 'description': (
  10. '查询此前由导出工具提交的一个异步导出任务。只能使用导出工具返回的'
  11. '任务引用,并通过单独的新调用查询。任务仍在等待或执行时,可按返回的'
  12. '建议等待时间稍后再次查询;不得在同一次调用内等待或循环轮询。'
  13. '任务完成后返回安全下载链接。'
  14. ),
  15. 'input_schema': {
  16. 'type': 'object',
  17. 'properties': {
  18. 'task_ref': {
  19. 'type': 'string',
  20. 'minLength': 1,
  21. 'maxLength': 512,
  22. 'description': '导出工具返回的任务引用。',
  23. },
  24. },
  25. 'required': ['task_ref'],
  26. 'additionalProperties': False,
  27. },
  28. }
  29. def call(self, task_ref=None, request_id='rq_query_export_task'):
  30. if self.api_client is None:
  31. raise RuntimeError('api client is required for query_export_task')
  32. if not isinstance(task_ref, str):
  33. raise ValueError('task_ref must be a string')
  34. task_ref = task_ref.strip()
  35. if not task_ref or len(task_ref) > 512:
  36. raise ValueError('task_ref must contain 1 to 512 characters')
  37. return self.api_client.call_tool(
  38. self.name,
  39. self.route_path,
  40. {'task_ref': task_ref},
  41. request_id,
  42. )