list_inbound_receipt_templates.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. class ListInboundReceiptTemplatesTool:
  2. name = 'list_inbound_receipt_templates'
  3. route_path = '/mcp/tools/listInboundReceiptTemplates'
  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. '交给 export_inbound_receipt。没有柜号时先询问柜号,不得猜测。'
  13. '直送和非直送混在一起,或有柜号对不上时,整次失败,按返回说明拆开再查。'
  14. '参数名仅用于工具调用;向用户回答时只能使用中文业务名称。'
  15. ),
  16. 'input_schema': {
  17. 'type': 'object',
  18. 'properties': {
  19. 'container_codes': self.number_array(
  20. '柜号数组。只放用户明确说出的柜号。'
  21. ),
  22. },
  23. 'required': ['container_codes'],
  24. 'additionalProperties': False,
  25. },
  26. }
  27. @staticmethod
  28. def number_array(description):
  29. return {
  30. 'type': 'array',
  31. 'minItems': 1,
  32. 'maxItems': 200,
  33. 'description': description,
  34. 'items': {
  35. 'type': 'string',
  36. 'minLength': 1,
  37. 'maxLength': 100,
  38. 'pattern': '.*\\S.*',
  39. },
  40. }
  41. @staticmethod
  42. def clean_container_codes(container_codes):
  43. if not isinstance(container_codes, list) or not container_codes:
  44. raise ValueError('container_codes is required')
  45. if len(container_codes) > 200:
  46. raise ValueError('container_codes exceeds 200 items')
  47. cleaned = []
  48. for item in container_codes:
  49. if not isinstance(item, str):
  50. raise ValueError('container code must be a string')
  51. text = item.strip()
  52. if not text or len(text) > 100:
  53. raise ValueError('container code length is invalid')
  54. if text not in cleaned:
  55. cleaned.append(text)
  56. if not cleaned or len(cleaned) > 200:
  57. raise ValueError('container_codes is required')
  58. return cleaned
  59. def call(self, container_codes=None, request_id='rq_list_inbound_receipt_templates'):
  60. if self.api_client is None:
  61. raise RuntimeError(
  62. 'api client is required for list_inbound_receipt_templates'
  63. )
  64. payload = {
  65. 'container_codes': self.clean_container_codes(container_codes),
  66. }
  67. return self.api_client.call_tool(
  68. self.name, self.route_path, payload, request_id,
  69. )