export_inbound_receipt.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from tools.list_inbound_receipt_templates import ListInboundReceiptTemplatesTool
  2. class ExportInboundReceiptTool:
  3. name = 'export_inbound_receipt'
  4. route_path = '/mcp/tools/exportInboundReceipt'
  5. def __init__(self, api_client=None):
  6. self.api_client = api_client
  7. def metadata(self):
  8. return {
  9. 'name': self.name,
  10. 'description': (
  11. '本工具只提交异步导出任务,不会在本次调用中等待文件生成,也禁止在一次调用内'
  12. '轮询任务状态。成功后返回任务引用(task_ref)和建议等待时间'
  13. '(retry_after_seconds)。稍后单独使用 query_export_task 查询任务状态或下载链接。'
  14. '使用场景:用户已经从 list_inbound_receipt_templates 的结果里选定一张入仓单模板,'
  15. '并明确要求导出文件。必须传同一批柜号和用户选中的模板编码。'
  16. '不得改用直送或非直送以外的模板,不得在没有查到模板时自行挑选编码。'
  17. '参数名仅用于工具调用;向用户回答时只能使用中文业务名称。'
  18. ),
  19. 'input_schema': {
  20. 'type': 'object',
  21. 'properties': {
  22. 'container_codes': ListInboundReceiptTemplatesTool.number_array(
  23. '与查模板时相同的柜号数组。'
  24. ),
  25. 'template_code': {
  26. 'type': 'string',
  27. 'minLength': 1,
  28. 'maxLength': 100,
  29. 'description': '用户从查模板结果里选定的模板编码。',
  30. },
  31. },
  32. 'required': ['container_codes', 'template_code'],
  33. 'additionalProperties': False,
  34. },
  35. }
  36. def call(
  37. self,
  38. container_codes=None,
  39. template_code=None,
  40. request_id='rq_export_inbound_receipt',
  41. ):
  42. if self.api_client is None:
  43. raise RuntimeError('api client is required for export_inbound_receipt')
  44. code = template_code.strip() if isinstance(template_code, str) else ''
  45. if not code or len(code) > 100:
  46. raise ValueError('template_code is required')
  47. payload = {
  48. 'container_codes': ListInboundReceiptTemplatesTool.clean_container_codes(
  49. container_codes
  50. ),
  51. 'template_code': code,
  52. }
  53. return self.api_client.call_tool(
  54. self.name, self.route_path, payload, request_id,
  55. )