export_out_of_province_port_data.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. class ExportOutOfProvincePortDataTool:
  2. name = 'export_out_of_province_port_data'
  3. route_path = '/mcp/tools/exportOutOfProvincePortData'
  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. '导出后台排舱单列表中的省外进港资料,并返回可下载文件 URL。'
  11. '只能在用户明确要求导出省外进港资料,并明确提供排舱单号和'
  12. '宁波、上海或美森资料类型时调用。排舱单号不是系统订单号、'
  13. '客户参考号、快递单号、柜号、SO 号或 Shipment ID;不得根据'
  14. '号码格式猜测。号码类型或资料类型不明确时先询问用户。'
  15. '一次只能选择一种资料类型;用户要求多个类型时应分别调用。'
  16. ),
  17. 'input_schema': {
  18. 'type': 'object',
  19. 'properties': {
  20. 'outbound_numbers': {
  21. 'type': 'array',
  22. 'items': {
  23. 'type': 'string',
  24. 'minLength': 1,
  25. 'maxLength': 100,
  26. },
  27. 'minItems': 1,
  28. 'maxItems': 100,
  29. 'uniqueItems': True,
  30. 'description': (
  31. '要导出的排舱单号数组。排舱单号是后台排舱单列表中的'
  32. '业务单号,不是系统订单号、客户参考号、快递单号、柜号、'
  33. 'SO号或Shipment ID。只能使用用户明确提供并确认类型为'
  34. '排舱单号的值,不得根据号码格式猜测。'
  35. ),
  36. 'examples': [[
  37. 'PC202607140001',
  38. 'PC202607140002',
  39. ]],
  40. },
  41. 'file_type': {
  42. 'type': 'string',
  43. 'enum': ['NB', 'SH', 'MS'],
  44. 'description': (
  45. '进港资料类型:NB=宁波进港资料,SH=上海进港资料,'
  46. 'MS=美森进港资料。必须根据用户明确选择传值;'
  47. '用户未说明时先询问,不得默认选择。'
  48. ),
  49. 'examples': ['NB'],
  50. },
  51. },
  52. 'required': ['outbound_numbers', 'file_type'],
  53. 'additionalProperties': False,
  54. },
  55. }
  56. def call(
  57. self,
  58. outbound_numbers,
  59. file_type,
  60. request_id='rq_export_out_of_province_port_data',
  61. ):
  62. if self.api_client is None:
  63. raise RuntimeError(
  64. 'api client is required for export_out_of_province_port_data'
  65. )
  66. numbers = self._normalize_outbound_numbers(outbound_numbers)
  67. normalized_type = str(file_type or '').strip().upper()
  68. if normalized_type not in ('NB', 'SH', 'MS'):
  69. raise ValueError('file_type must be NB, SH, or MS')
  70. return self.api_client.call_tool(
  71. self.name,
  72. self.route_path,
  73. {
  74. 'outbound_numbers': numbers,
  75. 'file_type': normalized_type,
  76. },
  77. request_id,
  78. )
  79. @staticmethod
  80. def _normalize_outbound_numbers(values):
  81. if not isinstance(values, list):
  82. raise ValueError('outbound_numbers must be an array')
  83. numbers = []
  84. for value in values:
  85. if not isinstance(value, str):
  86. raise ValueError('outbound_numbers must contain strings')
  87. value = value.strip()
  88. if not value:
  89. continue
  90. if len(value) > 100:
  91. raise ValueError('outbound number is too long')
  92. if value not in numbers:
  93. numbers.append(value)
  94. if not numbers or len(numbers) > 100:
  95. raise ValueError('outbound_numbers must contain 1 to 100 values')
  96. return numbers