output_presenter.py 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. import json
  2. import logging
  3. from urllib.parse import urlparse
  4. from constants import DEVICE_INVALID_MESSAGE
  5. logger = logging.getLogger(__name__)
  6. # Builds AI-safe MCP results for the explicitly supported tool set.
  7. class OutputPresenter:
  8. TABLE_TOOLS = frozenset((
  9. 'query_order_exact',
  10. 'query_track',
  11. 'query_customs_declaration_files',
  12. 'query_outbound_list',
  13. ))
  14. DETAIL_TOOLS = frozenset(('query_outbound_detail',))
  15. ORDER_DETAIL_TOOLS = frozenset(('query_order_detail',))
  16. OPTION_TOOLS = frozenset((
  17. 'list_order_filter_options',
  18. 'list_outbound_filter_options',
  19. 'list_pending_outbound_export_filter_options',
  20. ))
  21. EXPORT_TOOLS = frozenset((
  22. 'export_pending_outbound_orders',
  23. 'export_out_of_province_port_data',
  24. ))
  25. TASK_TOOLS = frozenset(('query_export_task',))
  26. SAFE_TOOLS = (
  27. TABLE_TOOLS | DETAIL_TOOLS | ORDER_DETAIL_TOOLS
  28. | OPTION_TOOLS | EXPORT_TOOLS | TASK_TOOLS
  29. )
  30. ORDER_DETAIL_SECTIONS = {
  31. 'overview': '订单概览',
  32. 'packages': '箱单信息',
  33. 'package_items': '箱单商品',
  34. 'dw_auth': 'DW授权信息',
  35. 'attachments': '附件信息',
  36. 'inbound': '入库信息',
  37. 'checks': '查验信息',
  38. 'tracks': '订单轨迹',
  39. 'operation_logs': '操作日志',
  40. 'cost_logs': '应收与结算日志',
  41. 'delivery': '派送信息',
  42. 'all': '全部',
  43. }
  44. ORDER_DETAIL_FIELDS = {
  45. 'overview': {
  46. 'order_info': {
  47. 'order_number': '订单号', 'reference_number': '客户参考号',
  48. 'customer_name': '客户名称', 'departure_country': '起运国',
  49. 'destination_country': '目的国', 'package_method': '包装类型',
  50. 'product_name': '物流产品', 'forecast_pwv': '预报件重体',
  51. 'inbound_pwv': '入库件重体',
  52. 'receivable_charge_weight': '应收计费重/体积',
  53. 'settlement_charge_weight': '结算计费重/体积',
  54. 'declaration_type': '报关类型', 'pre_recording': '是否需要预录单',
  55. 'idcard_name': '企业/个人姓名',
  56. 'idcard_number': '社会信用代码/身份证号',
  57. 'outbound_number': '排舱单号', 'container_mode': '直送柜/拼柜',
  58. 'track_map_available': '是否可查看轨迹地图', 'insurance': '购买保险',
  59. 'delivery_way': '派送方式', 'return_shipping_surcharge': '退运附加',
  60. 'work_order_count': '工单数量', 'bill_remark': '账单备注',
  61. 'remark': '订单备注',
  62. },
  63. 'freight_info': {
  64. 'estimated_inbound_time': '预计入库时间', 'cargo_type': '货物类型',
  65. 'pickup_way': '交货方式', 'warehouse': '交货仓库',
  66. 'pickup_address': '提货地址', 'pickup_contact': '提货联系人',
  67. 'pickup_phone': '提货联系电话', 'delivery_type': '派送类型',
  68. 'delivery_address': '派送地址', 'delivery_remark': '派送备注',
  69. 'oversea_warehouse': '海外仓',
  70. },
  71. 'package_summary': {
  72. 'box_count': '箱数', 'total_weight': '重量', 'weight_unit': '重量单位',
  73. 'total_volume': '体积', 'sku_count': 'SKU数量',
  74. 'clearance_total_price': '清关总价', 'clearance_currency': '清关币种',
  75. 'purchase_total_price': '采购总价', 'purchase_currency': '采购币种',
  76. },
  77. 'trader_info': {
  78. 'exporter': '出口商', 'importer': '进口商',
  79. 'coo_required': '是否做产地证',
  80. },
  81. },
  82. 'packages': {
  83. 'shipment_id': 'SHIPMENT ID', 'reference_id': 'REFERENCE ID',
  84. 'sku_summary': 'SKU', 'product_name_summary': '商品名',
  85. 'box_quantity': '箱数', 'box_length_cm': '单箱长(CM)',
  86. 'box_width_cm': '单箱宽(CM)', 'box_height_cm': '单箱高(CM)',
  87. 'gross_weight_kg': '单箱毛重量(KG)', 'net_weight_kg': '单箱净重量(KG)',
  88. 'is_over_length': '长度是否超限', 'is_over_width': '宽度是否超限',
  89. 'is_over_height': '高度是否超限', 'is_over_weight': '重量是否超限',
  90. },
  91. 'package_items': {
  92. 'shipment_id': 'SHIPMENT ID', 'reference_id': 'REFERENCE ID',
  93. 'box_specification': '箱规', 'box_specification_unit': '箱规单位',
  94. 'package_gross_weight_kg': '箱单单箱毛重(KG)',
  95. 'package_net_weight_kg': '箱单单箱净重(KG)',
  96. 'inspection_result': '查验结果', 'exception_reason': '异常原因',
  97. 'inspection_photo_count': '查验图片数量', 'sku': 'SKU',
  98. 'units_per_box': '单箱个数', 'declaration_type': '报关类型',
  99. 'box_number': '箱号', 'item_gross_weight_kg': '商品单箱毛重量(KG)',
  100. 'item_net_weight_kg': '商品单箱净重量(KG)', 'chinese_name': '中文品名',
  101. 'english_name': '英文名称', 'brand_type': '品牌类型', 'brand': '品牌',
  102. 'model': '型号', 'material_cn': '材质(CN)', 'material_en': '材质(EN)',
  103. 'purpose_cn': '用途', 'goods_attributes': '商品属性',
  104. 'declaration_hs_code': '报关编码', 'clearance_hs_code': '清关编码',
  105. 'material_ratio': '材质占比', 'clearance_unit_price': '清关单价',
  106. 'clearance_currency': '清关币种', 'purchase_unit_price': '采购单价',
  107. 'purchase_currency': '采购币种', 'product_image_count': '商品图片数量',
  108. 'remark': '备注',
  109. },
  110. 'dw_auth': {
  111. 'fba_id': 'FBAID', 'dw_start': 'DW开始时间', 'dw_end': 'DW结束时间',
  112. 'dw_display': 'DW', 'authorization_status': '客户授权状态',
  113. },
  114. 'attachments': {
  115. 'category': '附件分类', 'file_name': '文件名称',
  116. 'file_extension': '文件类型', 'is_image': '是否图片',
  117. 'preview_url': '预览链接', 'download_url': '下载链接',
  118. 'cost_name': '收费项目',
  119. },
  120. 'inbound_summary': {
  121. 'inbound_status': '入库状态', 'inbound_time': '入库时间',
  122. 'inbound_operator': '操作人', 'warehouse': '仓库',
  123. 'abnormal_reason': '异常原因', 'inbound_photo_count': '入库图片数量',
  124. 'forecast_pwv_summary': '预报件重体', 'inbound_pwv_summary': '入库件重体',
  125. },
  126. 'inbound': {
  127. 'has_label': '是否贴标', 'shipment_id': 'SHIPMENT ID',
  128. 'inbound_quantity': '入库件数',
  129. 'measurement_photo_count': '测量图片数量',
  130. 'box_specification': '入库箱规', 'weight_mode': None, 'weight': None,
  131. 'weight_unit': '重量单位', 'is_over_length': '长度是否超限',
  132. 'is_over_width': '宽度是否超限', 'is_over_height': '高度是否超限',
  133. 'is_over_weight': '重量是否超限', 'operated_at': '操作时间',
  134. },
  135. 'checks': {
  136. 'shipment_id': '货件编号', 'sku': 'SKU', 'box_number': '箱号',
  137. 'box_quantity': '箱数', 'box_specification': '箱规',
  138. 'inspection_result': '查验结果',
  139. 'inspection_photo_count': '查验图片数量', 'remark': '备注',
  140. 'inspector': '查验人', 'inspected_at': '查验时间',
  141. },
  142. 'tracks': {
  143. 'track_type': '轨迹类型', 'status': '轨迹节点', 'location': '轨迹地点',
  144. 'occurred_at': '时间', 'tracking_number': '跟踪号',
  145. 'shipment_id': 'SHIPMENT ID', 'content': '轨迹内容',
  146. },
  147. 'operation_logs': {
  148. 'operated_at': '操作时间', 'content': '操作内容', 'operator': '操作人',
  149. },
  150. 'cost_logs': {
  151. 'operated_at': '操作时间', 'content': '操作内容', 'operator': '操作人',
  152. },
  153. 'delivery_summary': {
  154. 'master_tracking_number': '主跟踪号', 'sub_order_count': '子单数量',
  155. },
  156. 'delivery': {'sub_tracking_number': '子跟踪号'},
  157. }
  158. ORDER_DETAIL_STATUS_FIELDS = {
  159. 'stage': '阶段', 'label': '节点', 'state': '状态',
  160. 'occurred_at': '时间', 'time_kind': '时间类型',
  161. }
  162. ORDER_DETAIL_STATES = {
  163. 'completed': '已完成', 'in_progress': '进行中',
  164. 'pending': '待完成', 'hidden': '不展示',
  165. }
  166. ORDER_DETAIL_TIME_KINDS = {
  167. 'actual': '实际', 'estimated': '预计', 'empty': '暂无',
  168. }
  169. TABLE_COLUMNS = {
  170. 'query_order_exact': {
  171. 'order_number': ('订单号',),
  172. 'reference_number': ('客户参考号',),
  173. 'status_txt_name': ('状态',),
  174. 'check_status_txt_name': ('是否已查验',),
  175. 'customer_name': ('客户名称',),
  176. 'customer_account_type_name': ('客户属性',),
  177. 'inbound_date': ('入库时间',),
  178. 'wo_num': ('未完成工单',),
  179. 'product_name': ('物流产品',),
  180. 'inbound_pieces': ('件数',),
  181. 'inbound_volume': ('体积(CBM)',),
  182. 'inbound_weight': ('重量(KG)',),
  183. 'pro_cn_name': ('品名',),
  184. 'export_declaration_type': ('报关方式',),
  185. 'merge_declare_number': ('合并报关单号',),
  186. 'delivery_address': ('派送地址',),
  187. 'container_code': ('柜号',),
  188. 'out_status_txt': ('排舱单状态',),
  189. 'hinge_of_destination': ('目的港',),
  190. 'etd': ('ETD',),
  191. 'atd': ('ATD',),
  192. 'eta': ('ETA',),
  193. 'ata': ('ATA',),
  194. 'release_time': ('清关放行时间',),
  195. 'oversea_inbound_date': ('海外入库时间',),
  196. 'appt_time': ('APPT时间',),
  197. 'est_loading_time': ('预计装柜时间',),
  198. 'pickup_time': ('海外提柜时间',),
  199. 'delivery_way_title': ('派送方式',),
  200. 'tracking_number': ('快递单号', '承运商跟踪号码'),
  201. 'shipment_id': ('Shipment ID',),
  202. 'goods_attribute': ('商品属性',),
  203. 'sku': ('SKU',),
  204. 'sales_user': ('商务经理',),
  205. 'service_user': ('客户经理',),
  206. 'department_name': ('事业部',),
  207. 'remark': ('订单备注',),
  208. 'importer_name': ('进口商',),
  209. 'warehouse_name': ('交货仓库',),
  210. 'paid_status_name': ('付款状态',),
  211. },
  212. 'query_track': {
  213. 'status': ('轨迹节点', '轨迹状态,如:开始集港、离港放行、清关、配送等'),
  214. 'location': ('轨迹地点', '发生地点'),
  215. 'time': ('时间', '轨迹发生时间(已转换为用户时区)'),
  216. 'content': ('轨迹内容', '详细描述'),
  217. 'tracking_number': ('跟踪号', '快递单号'),
  218. 'shipment_id': ('Shipment ID', '包裹ID'),
  219. },
  220. 'query_customs_declaration_files': {
  221. 'outbound_number': ('排舱单号',),
  222. 'order_number': ('订单号',),
  223. 'file_name': ('文件名',),
  224. 'file_type': ('文件类型',),
  225. 'file_url': ('文件链接',),
  226. },
  227. 'query_outbound_list': {
  228. 'outbound_number': ('排舱单号',),
  229. 'direct_send': ('直送柜',),
  230. 'remark': ('备注',),
  231. 'cargo_type': ('超长超重',),
  232. 'warehouse_name': ('集货仓库',),
  233. 'status': ('状态',),
  234. 'so_number': ('SO号',),
  235. 'container_code': ('柜号',),
  236. 'seal_number': ('封条号',),
  237. 'container_type': ('柜型',),
  238. 'shipping_method': ('运输方式',),
  239. 'total_volume': ('体积(CBM)',),
  240. 'total_weight': ('重量(KG)',),
  241. 'ship_schedule': ('船期',),
  242. 'closing_time': ('截关时间',),
  243. 'est_loading_time': ('预计装柜时间',),
  244. 'operator': ('操作人',),
  245. 'operation_modes': ('拖报清方式',),
  246. 'operation_time': ('操作时间',),
  247. },
  248. 'query_outbound_detail': {
  249. 'order_number': ('订单号',),
  250. 'cargo_type': ('超长超重',),
  251. 'customs_files': ('报关资料',),
  252. 'reference_number': ('客户参考号',),
  253. 'customer_name': ('客户名称',),
  254. 'declaration_type': ('报关方式',),
  255. 'merge_declare_number': ('合并报关单号',),
  256. 'order_remark': ('订单备注',),
  257. 'bl_number': ('提单号',),
  258. 'container_code': ('柜号',),
  259. 'customer_service': ('客户经理',),
  260. 'est_inbound_date': ('预计入库时间',),
  261. 'inbound_date': ('实际入库时间',),
  262. 'status': ('状态',),
  263. 'pieces': ('预报件数 / 入库件数',),
  264. 'weight': ('预报实重(KG) / 入库实重(KG)',),
  265. 'volume': ('预报体积(m³) / 入库体积(m³)',),
  266. 'pickup_place': ('交货地',),
  267. 'product_name': ('物流产品',),
  268. 'goods_name': ('品名',),
  269. 'closing_time': ('截关时间',),
  270. 'clearance_remark': ('报关备注',),
  271. 'import_clearance_remark': ('清关备注',),
  272. 'delivery_address': ('派送地址',),
  273. 'delivery_type': ('派送类型',),
  274. 'delivery_way': ('派送方式',),
  275. 'channel': ('派送渠道',),
  276. 'country_name': ('目的国',),
  277. 'importer_name': ('进口商',),
  278. 'vat_type': ('清关税号',),
  279. 'packing_type': ('货物类型',),
  280. 'is_abnormal': ('是否问题件',),
  281. 'package_method': ('包装类型',),
  282. 'order_reply': ('到货回复',),
  283. },
  284. }
  285. OUTBOUND_DETAIL_SUMMARY = {
  286. 'bl_number': '提单号',
  287. 'container_code': '柜号',
  288. 'container_type': '柜型',
  289. 'total_volume': '总体积',
  290. 'total_weight': '总重量',
  291. 'total_pieces': '总件数',
  292. 'sku': 'SKU',
  293. 'buy_declaration_count': '买单报关数量',
  294. 'general_declaration_count': '一般贸易报关数量',
  295. 'must_load': '必装单量/体积',
  296. 'backup_load': '备装单量/体积',
  297. }
  298. FIELD_LABELS = {
  299. 'query_order_exact': {
  300. 'order_number': '订单号',
  301. 'order_numbers': '订单号',
  302. 'reference_number': '客户参考号',
  303. 'reference_numbers': '客户参考号',
  304. 'tracking_number': '快递单号',
  305. 'tracking_numbers': '快递单号',
  306. 'outbound_number': '排舱单号',
  307. 'outbound_numbers': '排舱单号',
  308. 'container_code': '柜号',
  309. 'container_codes': '柜号',
  310. 'so_number': 'SO号',
  311. 'so_numbers': 'SO号',
  312. 'shipment_id': 'Shipment ID',
  313. 'receiver_country': '收货国家',
  314. 'product_ids': '物流产品',
  315. 'customer_ids': '客户',
  316. 'sales_id': '销售人员',
  317. 'warehouse_ids': '仓库',
  318. 'department_id': '事业部',
  319. 'inbound_date_start': '入库开始日期',
  320. 'inbound_date_end': '入库结束日期',
  321. 'outbound_date_start': '出库开始日期',
  322. 'outbound_date_end': '出库结束日期',
  323. 'page': '页码',
  324. 'limit': '每页数量',
  325. },
  326. 'query_track': {
  327. 'order_id': '订单ID',
  328. 'order_number': '订单号',
  329. 'tracking_number': '快递单号',
  330. 'page': '页码',
  331. 'limit': '每页数量',
  332. },
  333. 'query_customs_declaration_files': {
  334. 'outbound_numbers': '排舱单号',
  335. 'order_numbers': '订单号',
  336. 'page': '页码',
  337. 'limit': '每页数量',
  338. },
  339. 'query_outbound_list': {
  340. 'outbound_numbers': '排舱单号',
  341. 'order_numbers': '订单号',
  342. 'container_codes': '柜号',
  343. 'so_numbers': 'SO号',
  344. 'bl_numbers': '提单号',
  345. 'outbound_status': '排舱状态',
  346. 'shipping_method': '运输方式',
  347. 'warehouse_id': '集货仓库',
  348. 'is_direct_send': '是否直送柜',
  349. 'page': '页码',
  350. 'limit': '每页数量',
  351. },
  352. 'query_outbound_detail': {
  353. 'outbound_number': '排舱单号',
  354. 'page': '页码',
  355. 'limit': '每页数量',
  356. },
  357. 'query_order_detail': {
  358. 'order_number': '订单号', 'section': '详情模块',
  359. 'page': '页码', 'limit': '每页数量',
  360. },
  361. 'list_order_filter_options': {
  362. 'filter_type': '筛选项类型',
  363. 'keyword': '关键词',
  364. 'page': '页码',
  365. 'limit': '每页数量',
  366. },
  367. 'list_outbound_filter_options': {
  368. 'filter_type': '筛选类别',
  369. 'keyword': '显示名称',
  370. 'page': '页码',
  371. 'limit': '每页数量',
  372. },
  373. 'list_pending_outbound_export_filter_options': {
  374. 'filter_type': '筛选项类型',
  375. 'product_type_id': '产品分类',
  376. 'keyword': '关键词',
  377. 'page': '页码',
  378. 'limit': '每页数量',
  379. },
  380. 'export_pending_outbound_orders': {
  381. 'number': '单号',
  382. 'product_type_id': '产品分类',
  383. 'product_id': '物流产品',
  384. 'order_warehouse_id': '集货仓库',
  385. 'receiver_country': '目的国',
  386. 'is_remove': '是否装柜剔除',
  387. 'address': '派送地址',
  388. 'inbound_date': '入库时间',
  389. 'status': '订单状态',
  390. 'merge_declare_number': '合并报关单号',
  391. 'importer_id': '进口商',
  392. 'packing_type': '货物类型',
  393. 'is_battery': '带电属性',
  394. 'is_magnetic': '带磁属性',
  395. 'is_wood': '带木属性',
  396. 'is_other': '其他商品属性',
  397. 'is_fda': 'FDA产品属性',
  398. 'is_toy': '玩具属性',
  399. 'is_ultra_limit': '超长超重属性',
  400. 'is_sensitive': '敏感货属性',
  401. 'is_food': '食品属性',
  402. 'no_property': '无属性',
  403. },
  404. 'export_out_of_province_port_data': {
  405. 'outbound_numbers': '排舱单号',
  406. 'container_codes': '柜号',
  407. 'bl_numbers': '提单号',
  408. 'so_numbers': 'SO号',
  409. 'file_type': '资料类型',
  410. },
  411. 'query_export_task': {
  412. 'task_ref': '导出任务引用',
  413. },
  414. }
  415. ERROR_MESSAGES = {
  416. 'MCP_1101': '设备配置已失效,请重新生成配置',
  417. 'MCP_1102': '设备会话已过期,请重新连接',
  418. 'MCP_1103': '员工账号不可用,请联系管理员',
  419. 'MCP_1104': '身份信息已失效,请重新登录或重新生成设备配置',
  420. 'MCP_1201': '工具当前不可用',
  421. 'MCP_1202': '工具当前不可用',
  422. 'MCP_1301': '没有权限使用此工具',
  423. 'MCP_1501': '目标数据不可用',
  424. 'MCP_1502': '结果过多,请缩小查询范围',
  425. 'MCP_1601': '没有可导出的数据',
  426. 'MCP_9001': '工具调用失败,请稍后重试',
  427. }
  428. NON_RETRYABLE_CODES = frozenset((
  429. 'MCP_1101',
  430. 'MCP_1102',
  431. 'MCP_1103',
  432. 'MCP_1104',
  433. 'MCP_1201',
  434. 'MCP_1202',
  435. 'MCP_1301',
  436. 'MCP_1401',
  437. 'MCP_1501',
  438. 'MCP_1502',
  439. 'MCP_1601',
  440. ))
  441. def handles(self, tool_name):
  442. return isinstance(tool_name, str) and tool_name in self.SAFE_TOOLS
  443. # Convert a backend envelope into text and structured display data.
  444. def present(self, tool_name, tool_result):
  445. if not self.handles(tool_name) or not isinstance(tool_result, dict):
  446. return self._format_error()
  447. code = str(tool_result.get('code') or '').strip()
  448. meta = self._build_meta(tool_result.get('meta'))
  449. if code not in ('MCP_0000', '0'):
  450. return self._business_error(
  451. tool_name,
  452. code or 'MCP_9001',
  453. tool_result.get('msg'),
  454. meta,
  455. )
  456. data = tool_result.get('data')
  457. if not isinstance(data, dict):
  458. return self._format_error(meta)
  459. if tool_name in self.DETAIL_TOOLS:
  460. return self._present_outbound_detail(
  461. tool_name,
  462. data,
  463. tool_result.get('meta'),
  464. meta,
  465. )
  466. if tool_name in self.ORDER_DETAIL_TOOLS:
  467. return self._present_order_detail(data, tool_result.get('meta'), meta)
  468. if tool_name in self.TABLE_TOOLS:
  469. return self._present_table(
  470. tool_name,
  471. data,
  472. tool_result.get('meta'),
  473. meta,
  474. )
  475. if tool_name in self.OPTION_TOOLS:
  476. return self._present_options(data, tool_result.get('meta'), meta)
  477. if tool_name in self.EXPORT_TOOLS:
  478. return self._present_export_submission(data, meta)
  479. return self._present_export_task(data, meta)
  480. def _present_order_detail(self, data, raw_meta, meta):
  481. if set(data) != {'section', 'order_number', 'payload'}:
  482. return self._format_error(meta)
  483. section = data.get('section')
  484. order_number = data.get('order_number')
  485. payload = data.get('payload')
  486. if (
  487. section not in self.ORDER_DETAIL_SECTIONS
  488. or not isinstance(order_number, str) or not order_number.strip()
  489. or not isinstance(payload, dict)
  490. ):
  491. return self._format_error(meta)
  492. content = {
  493. '订单号': order_number.strip(),
  494. '详情模块': self.ORDER_DETAIL_SECTIONS[section],
  495. }
  496. if section == 'all':
  497. all_content = self._present_order_detail_all(payload)
  498. if all_content is None:
  499. return self._format_error(meta)
  500. content.update(all_content)
  501. elif section == 'overview':
  502. expected = {
  503. 'status_nodes', 'order_info', 'freight_info',
  504. 'package_summary', 'trader_info',
  505. }
  506. if set(payload) != expected or not isinstance(payload['status_nodes'], list):
  507. return self._format_error(meta)
  508. nodes = []
  509. for row in payload['status_nodes']:
  510. translated = self._translate_exact(row, self.ORDER_DETAIL_STATUS_FIELDS)
  511. if translated is None:
  512. return self._format_error(meta)
  513. state = row.get('state')
  514. time_kind = row.get('time_kind')
  515. if state not in self.ORDER_DETAIL_STATES or time_kind not in self.ORDER_DETAIL_TIME_KINDS:
  516. return self._format_error(meta)
  517. translated['状态'] = self.ORDER_DETAIL_STATES[state]
  518. translated['时间类型'] = self.ORDER_DETAIL_TIME_KINDS[time_kind]
  519. nodes.append(translated)
  520. content['状态节点'] = nodes
  521. for raw_key, chinese_key in (
  522. ('order_info', '订单信息'), ('freight_info', '货运信息'),
  523. ('package_summary', '箱单汇总'), ('trader_info', '进出口商'),
  524. ):
  525. translated = self._translate_exact(
  526. payload.get(raw_key),
  527. self.ORDER_DETAIL_FIELDS['overview'][raw_key],
  528. )
  529. if translated is None:
  530. return self._format_error(meta)
  531. content[chinese_key] = translated
  532. elif section == 'inbound':
  533. if set(payload) != {'summary', 'records'}:
  534. return self._format_error(meta)
  535. summary = self._translate_exact(
  536. payload.get('summary'), self.ORDER_DETAIL_FIELDS['inbound_summary']
  537. )
  538. records = self._translate_order_detail_rows(section, payload.get('records'))
  539. if summary is None or records is None:
  540. return self._format_error(meta)
  541. content['入库概况'] = summary
  542. content['明细'] = records
  543. pagination = self._order_detail_pagination(raw_meta)
  544. if pagination is None:
  545. return self._format_error(meta)
  546. content['分页'] = pagination
  547. elif section == 'delivery':
  548. if set(payload) != {'summary', 'records'}:
  549. return self._format_error(meta)
  550. summary = self._translate_exact(
  551. payload.get('summary'), self.ORDER_DETAIL_FIELDS['delivery_summary']
  552. )
  553. records = self._translate_order_detail_rows(section, payload.get('records'))
  554. if summary is None or records is None:
  555. return self._format_error(meta)
  556. content['派送汇总'] = summary
  557. content['明细'] = records
  558. pagination = self._order_detail_pagination(raw_meta)
  559. if pagination is None:
  560. return self._format_error(meta)
  561. content['分页'] = pagination
  562. else:
  563. if set(payload) != {'records'}:
  564. return self._format_error(meta)
  565. records = self._translate_order_detail_rows(section, payload.get('records'))
  566. pagination = self._order_detail_pagination(raw_meta)
  567. if records is None or pagination is None:
  568. return self._format_error(meta)
  569. content['明细'] = records
  570. content['分页'] = pagination
  571. text = json.dumps(content, ensure_ascii=False, indent=2)
  572. return self._success_result(content, text, meta)
  573. def _present_order_detail_all(self, payload):
  574. expected_sections = set(self.ORDER_DETAIL_SECTIONS) - {'all'}
  575. if set(payload) != expected_sections:
  576. return None
  577. overview = payload.get('overview')
  578. if not isinstance(overview, dict) or set(overview) != {
  579. 'status_nodes', 'order_info', 'freight_info', 'package_summary', 'trader_info',
  580. } or not isinstance(overview['status_nodes'], list):
  581. return None
  582. overview_content = {'状态节点': []}
  583. for row in overview['status_nodes']:
  584. translated = self._translate_exact(row, self.ORDER_DETAIL_STATUS_FIELDS)
  585. if translated is None:
  586. return None
  587. state = row.get('state')
  588. time_kind = row.get('time_kind')
  589. if state not in self.ORDER_DETAIL_STATES or time_kind not in self.ORDER_DETAIL_TIME_KINDS:
  590. return None
  591. translated['状态'] = self.ORDER_DETAIL_STATES[state]
  592. translated['时间类型'] = self.ORDER_DETAIL_TIME_KINDS[time_kind]
  593. overview_content['状态节点'].append(translated)
  594. for raw_key, chinese_key in (
  595. ('order_info', '订单信息'), ('freight_info', '货运信息'),
  596. ('package_summary', '箱单汇总'), ('trader_info', '进出口商'),
  597. ):
  598. translated = self._translate_exact(
  599. overview.get(raw_key), self.ORDER_DETAIL_FIELDS['overview'][raw_key]
  600. )
  601. if translated is None:
  602. return None
  603. overview_content[chinese_key] = translated
  604. result = {'订单概览': overview_content}
  605. for section, label in self.ORDER_DETAIL_SECTIONS.items():
  606. if section in ('overview', 'all'):
  607. continue
  608. translated = self._present_order_detail_all_section(section, payload.get(section))
  609. if translated is None:
  610. return None
  611. result[label] = translated
  612. return result
  613. def _present_order_detail_all_section(self, section, payload):
  614. if not isinstance(payload, dict) or 'pagination' not in payload:
  615. return None
  616. pagination = self._order_detail_pagination(payload.get('pagination'))
  617. if pagination is None:
  618. return None
  619. if section == 'inbound':
  620. if set(payload) != {'summary', 'records', 'pagination'}:
  621. return None
  622. summary = self._translate_exact(
  623. payload.get('summary'), self.ORDER_DETAIL_FIELDS['inbound_summary']
  624. )
  625. records = self._translate_order_detail_rows(section, payload.get('records'))
  626. if summary is None or records is None:
  627. return None
  628. return {'入库概况': summary, '明细': records, '分页': pagination}
  629. if section == 'delivery':
  630. if set(payload) != {'summary', 'records', 'pagination'}:
  631. return None
  632. summary = self._translate_exact(
  633. payload.get('summary'), self.ORDER_DETAIL_FIELDS['delivery_summary']
  634. )
  635. records = self._translate_order_detail_rows(section, payload.get('records'))
  636. if summary is None or records is None:
  637. return None
  638. return {'派送汇总': summary, '明细': records, '分页': pagination}
  639. if set(payload) != {'records', 'pagination'}:
  640. return None
  641. records = self._translate_order_detail_rows(section, payload.get('records'))
  642. if records is None:
  643. return None
  644. return {'明细': records, '分页': pagination}
  645. def _translate_order_detail_rows(self, section, records):
  646. if not isinstance(records, list):
  647. return None
  648. mapping = self.ORDER_DETAIL_FIELDS.get(section)
  649. if not isinstance(mapping, dict):
  650. return None
  651. translated_rows = []
  652. for row in records:
  653. translated = self._translate_exact(row, mapping)
  654. if translated is None:
  655. return None
  656. if section == 'inbound':
  657. mode = row.get('weight_mode')
  658. if mode not in ('single_box', 'total'):
  659. return None
  660. translated[
  661. '单箱入库重量' if mode == 'single_box' else '总重量KG'
  662. ] = row.get('weight', '')
  663. translated_rows.append(translated)
  664. return translated_rows
  665. @staticmethod
  666. def _translate_exact(value, mapping):
  667. if not isinstance(value, dict) or set(value) != set(mapping):
  668. return None
  669. result = {}
  670. for key, label in mapping.items():
  671. if label is None:
  672. continue
  673. item = value.get(key, '')
  674. if isinstance(item, (dict, list)):
  675. return None
  676. result[label] = '' if item is None else item
  677. return result
  678. @staticmethod
  679. def _order_detail_pagination(raw_meta):
  680. if not isinstance(raw_meta, dict):
  681. return None
  682. if not all(key in raw_meta for key in ('page', 'limit', 'has_more')):
  683. return None
  684. page = raw_meta.get('page')
  685. limit = raw_meta.get('limit')
  686. has_more = raw_meta.get('has_more')
  687. if isinstance(page, bool) or not isinstance(page, int) or page < 1:
  688. return None
  689. if isinstance(limit, bool) or not isinstance(limit, int) or limit < 1:
  690. return None
  691. if not isinstance(has_more, bool):
  692. return None
  693. return {'页码': page, '每页数量': limit, '是否还有更多': has_more}
  694. # Map local tool exceptions without exposing internal error details.
  695. def present_exception(self, tool_name, exception):
  696. if not self.handles(tool_name):
  697. return self._format_error()
  698. message = str(exception or '').strip()
  699. if isinstance(exception, ValueError):
  700. label = self._find_field_label(tool_name, message)
  701. return self._error_result(
  702. 'MCP_1401',
  703. self._parameter_message(label),
  704. False,
  705. )
  706. if message == DEVICE_INVALID_MESSAGE:
  707. return self._error_result('MCP_1101', DEVICE_INVALID_MESSAGE, False)
  708. if message.lower().startswith('tool disabled'):
  709. return self._error_result('MCP_1202', '工具当前不可用', False)
  710. return self._error_result(
  711. 'MCP_9001',
  712. '工具调用失败,请稍后重试',
  713. True,
  714. )
  715. def _present_table(self, tool_name, data, raw_meta, meta):
  716. columns = data.get('columns')
  717. records = data.get('records')
  718. if not isinstance(columns, list) or not columns or not isinstance(records, list):
  719. return self._format_error(meta)
  720. allowed_columns = self.TABLE_COLUMNS.get(tool_name)
  721. if not isinstance(allowed_columns, dict):
  722. return self._format_error(meta)
  723. headers = []
  724. keys = []
  725. for column in columns:
  726. if not isinstance(column, dict):
  727. return self._format_error(meta)
  728. key = column.get('key')
  729. label = column.get('name')
  730. if not isinstance(key, str) or not key.strip():
  731. return self._format_error(meta)
  732. if not isinstance(label, str) or not label.strip():
  733. return self._format_error(meta)
  734. key = key.strip()
  735. definition = allowed_columns.get(key)
  736. if not isinstance(definition, tuple) or not definition:
  737. return self._format_error(meta)
  738. keys.append(key)
  739. header = {'label': definition[0]}
  740. if len(definition) > 1:
  741. header['description'] = definition[1]
  742. headers.append(header)
  743. rows = []
  744. for record in records:
  745. if not isinstance(record, dict):
  746. return self._format_error(meta)
  747. rows.append([
  748. '' if record.get(key) is None else record.get(key, '')
  749. for key in keys
  750. ])
  751. content = {
  752. 'summary': self._safe_text(data.get('summary')),
  753. 'headers': headers,
  754. 'rows': rows,
  755. }
  756. tips = self._safe_tips(data.get('tips'))
  757. if tips:
  758. content['tips'] = tips
  759. pagination = self._build_pagination(raw_meta)
  760. if pagination:
  761. content['pagination'] = pagination
  762. return self._success_result(content, self._render_table(content), meta)
  763. def _present_outbound_detail(self, tool_name, data, raw_meta, meta):
  764. summary = data.get('summary')
  765. columns = data.get('columns')
  766. records = data.get('records')
  767. if not isinstance(summary, dict):
  768. return self._format_error(meta)
  769. if not isinstance(columns, list) or not columns or not isinstance(records, list):
  770. return self._format_error(meta)
  771. if any(key not in summary for key in self.OUTBOUND_DETAIL_SUMMARY):
  772. return self._format_error(meta)
  773. allowed_columns = self.TABLE_COLUMNS.get(tool_name)
  774. headers = []
  775. keys = []
  776. for column in columns:
  777. if not isinstance(column, dict):
  778. return self._format_error(meta)
  779. key = column.get('key')
  780. definition = allowed_columns.get(key) if isinstance(key, str) else None
  781. if not isinstance(definition, tuple) or not definition:
  782. return self._format_error(meta)
  783. keys.append(key)
  784. headers.append({'label': definition[0]})
  785. rows = []
  786. for record in records:
  787. if not isinstance(record, dict):
  788. return self._format_error(meta)
  789. row = []
  790. for key in keys:
  791. value = '' if record.get(key) is None else record.get(key, '')
  792. if key == 'customs_files':
  793. if not isinstance(value, list):
  794. return self._format_error(meta)
  795. files = []
  796. for item in value:
  797. if not isinstance(item, dict):
  798. return self._format_error(meta)
  799. files.append({
  800. '文件名称': item.get('file_name', ''),
  801. '文件类型': item.get('file_type', ''),
  802. '文件链接': item.get('file_url', ''),
  803. })
  804. value = files
  805. row.append(value)
  806. rows.append(row)
  807. summary_keys = list(self.OUTBOUND_DETAIL_SUMMARY.keys())
  808. content = {
  809. 'summary': {
  810. 'headers': [
  811. {'label': self.OUTBOUND_DETAIL_SUMMARY[key]}
  812. for key in summary_keys
  813. ],
  814. 'row': [summary.get(key, '') for key in summary_keys],
  815. },
  816. 'details': {
  817. 'headers': headers,
  818. 'rows': rows,
  819. },
  820. }
  821. tips = self._safe_tips(data.get('tips'))
  822. if tips:
  823. content['details']['tips'] = tips
  824. pagination = self._build_pagination(raw_meta)
  825. if pagination:
  826. content['details']['pagination'] = pagination
  827. return self._success_result(
  828. content,
  829. self._render_outbound_detail(content),
  830. meta,
  831. )
  832. @classmethod
  833. def _render_outbound_detail(cls, content):
  834. lines = ['排舱汇总:']
  835. summary = content['summary']
  836. for header, value in zip(summary['headers'], summary['row']):
  837. lines.append('- {0}: {1}'.format(header['label'], value))
  838. lines.append('订单明细:')
  839. details = content['details']
  840. lines.append('表头共 {0} 列:'.format(len(details['headers'])))
  841. for index, header in enumerate(details['headers'], start=1):
  842. lines.append('{0}. {1}'.format(index, header['label']))
  843. for index, row in enumerate(details['rows'], start=1):
  844. lines.append('记录 {0}:'.format(index))
  845. for header, value in zip(details['headers'], row):
  846. if isinstance(value, (dict, list)):
  847. value = json.dumps(value, ensure_ascii=False)
  848. lines.append('- {0}: {1}'.format(header['label'], value))
  849. tips = details.get('tips') or []
  850. if tips:
  851. lines.append('提示:{0}'.format(';'.join(tips)))
  852. return '\n'.join(lines)
  853. def _present_options(self, data, raw_meta, meta):
  854. records = data.get('records')
  855. if not isinstance(records, list):
  856. return self._format_error(meta)
  857. rows = []
  858. for record in records:
  859. if not isinstance(record, dict):
  860. return self._format_error(meta)
  861. rows.append([
  862. record.get('value', ''),
  863. self._safe_text(record.get('label')),
  864. self._safe_text(record.get('code')),
  865. ])
  866. content = {
  867. 'headers': [
  868. {'label': '可传值'},
  869. {'label': '显示名称'},
  870. {'label': '业务编码'},
  871. ],
  872. 'rows': rows,
  873. }
  874. pagination = self._build_pagination(raw_meta)
  875. if pagination:
  876. content['pagination'] = pagination
  877. return self._success_result(content, self._render_table(content), meta)
  878. def _present_export_submission(self, data, meta):
  879. expected = {'task_ref', 'status', 'retry_after_seconds'}
  880. if set(data) != expected:
  881. return self._format_error(meta)
  882. task_ref = data.get('task_ref')
  883. retry_after = data.get('retry_after_seconds')
  884. if (
  885. not isinstance(task_ref, str) or not task_ref.strip()
  886. or data.get('status') != 'queued'
  887. or isinstance(retry_after, bool)
  888. or not isinstance(retry_after, int)
  889. or retry_after <= 0
  890. ):
  891. return self._format_error(meta)
  892. task = {
  893. 'task_ref': task_ref.strip(),
  894. 'status': 'queued',
  895. 'retry_after_seconds': retry_after,
  896. }
  897. content = {
  898. 'message': '导出任务已提交',
  899. 'task': task,
  900. }
  901. text = (
  902. '导出任务已提交\n'
  903. '- 任务引用: {0}\n'
  904. '- 建议 {1} 秒后单独查询任务状态'
  905. ).format(task['task_ref'], retry_after)
  906. return self._success_result(content, text, meta)
  907. def _present_export_task(self, data, meta):
  908. task_ref = data.get('task_ref')
  909. status = data.get('status')
  910. if (
  911. not isinstance(task_ref, str)
  912. or not task_ref.strip()
  913. or status not in ('queued', 'running', 'completed', 'failed')
  914. ):
  915. return self._format_error(meta)
  916. task = {'task_ref': task_ref.strip(), 'status': status}
  917. if status in ('queued', 'running'):
  918. if set(data) != {'task_ref', 'status', 'retry_after_seconds'}:
  919. return self._format_error(meta)
  920. retry_after = data.get('retry_after_seconds')
  921. if (
  922. isinstance(retry_after, bool)
  923. or not isinstance(retry_after, int)
  924. or retry_after <= 0
  925. ):
  926. return self._format_error(meta)
  927. task['retry_after_seconds'] = retry_after
  928. label = '等待中' if status == 'queued' else '生成中'
  929. content = {'message': '导出任务{0}'.format(label), 'task': task}
  930. text = (
  931. '导出任务{0}\n- 任务引用: {1}\n- 建议 {2} 秒后再次查询'
  932. ).format(label, task['task_ref'], retry_after)
  933. return self._success_result(content, text, meta)
  934. if status == 'failed':
  935. if set(data) != {'task_ref', 'status'}:
  936. return self._format_error(meta)
  937. content = {'message': '导出任务失败,请重新提交', 'task': task}
  938. text = '导出任务失败,请重新提交'
  939. return self._success_result(content, text, meta)
  940. if set(data) != {'task_ref', 'status', 'files'}:
  941. return self._format_error(meta)
  942. files = data.get('files')
  943. if not isinstance(files, list) or not files:
  944. return self._format_error(meta)
  945. safe_files = []
  946. for item in files:
  947. if not isinstance(item, dict) or set(item) != {'label', 'url'}:
  948. return self._format_error(meta)
  949. label = item.get('label')
  950. url = item.get('url')
  951. if (
  952. not isinstance(label, str) or not label.strip()
  953. or not self._valid_http_url(url)
  954. ):
  955. return self._format_error(meta)
  956. safe_files.append({'label': label.strip(), 'url': url.strip()})
  957. content = {
  958. 'message': '文件已生成',
  959. 'task': task,
  960. 'files': safe_files,
  961. }
  962. lines = ['文件已生成']
  963. for item in safe_files:
  964. lines.append('- {0}: {1}'.format(item['label'], item['url']))
  965. return self._success_result(content, '\n'.join(lines), meta)
  966. def _valid_http_url(self, value):
  967. if not isinstance(value, str) or not value.strip():
  968. return False
  969. if value != value.strip() or '\\' in value or any(
  970. character.isspace() or ord(character) < 32 or ord(character) == 127
  971. for character in value
  972. ):
  973. return False
  974. try:
  975. parsed = urlparse(value)
  976. port = parsed.port
  977. return (
  978. parsed.scheme in ('http', 'https')
  979. and bool(parsed.hostname)
  980. and parsed.username is None
  981. and parsed.password is None
  982. and (port is None or 0 < port <= 65535)
  983. )
  984. except ValueError:
  985. return False
  986. def _business_error(self, tool_name, code, raw_message, meta):
  987. if code not in self.ERROR_MESSAGES and code != 'MCP_1401':
  988. logger.warning(
  989. 'Unknown MCP business error code',
  990. extra={
  991. 'request_id': meta.get('request_id', ''),
  992. 'tool_code': tool_name,
  993. 'backend_code': code,
  994. 'response_code': 'MCP_9001',
  995. 'diagnostic_reason': 'UNEXPECTED_EXCEPTION',
  996. },
  997. )
  998. code = 'MCP_9001'
  999. if code == 'MCP_1401':
  1000. label = self._find_field_label(tool_name, raw_message)
  1001. message = self._parameter_message(label)
  1002. else:
  1003. message = self.ERROR_MESSAGES[code]
  1004. retryable = code not in self.NON_RETRYABLE_CODES
  1005. return self._error_result(code, message, retryable, meta)
  1006. def _find_field_label(self, tool_name, raw_message):
  1007. message = str(raw_message or '')
  1008. fields = self.FIELD_LABELS.get(tool_name, {})
  1009. for field in sorted(fields, key=len, reverse=True):
  1010. if field in message:
  1011. return fields[field]
  1012. return ''
  1013. @staticmethod
  1014. def _parameter_message(label):
  1015. return '{0}参数不正确'.format(label) if label else '工具参数不正确,请检查后重试'
  1016. @staticmethod
  1017. def _build_meta(raw_meta):
  1018. if not isinstance(raw_meta, dict):
  1019. return {}
  1020. request_id = raw_meta.get('request_id')
  1021. if not isinstance(request_id, str) or not request_id.strip():
  1022. return {}
  1023. return {'request_id': request_id.strip()}
  1024. @staticmethod
  1025. def _build_pagination(raw_meta):
  1026. if not isinstance(raw_meta, dict):
  1027. return {}
  1028. return {
  1029. key: raw_meta[key]
  1030. for key in ('page', 'limit', 'has_more', 'total')
  1031. if key in raw_meta
  1032. }
  1033. @staticmethod
  1034. def _safe_text(value):
  1035. if value is None:
  1036. return ''
  1037. return str(value).strip()
  1038. @classmethod
  1039. def _safe_tips(cls, value):
  1040. if not isinstance(value, list):
  1041. return []
  1042. return [cls._safe_text(item) for item in value if cls._safe_text(item)]
  1043. @classmethod
  1044. def _render_table(cls, content):
  1045. headers = content.get('headers') or []
  1046. rows = content.get('rows') or []
  1047. lines = []
  1048. summary = cls._safe_text(content.get('summary'))
  1049. if summary:
  1050. lines.append(summary)
  1051. lines.append('表头共 {0} 列:'.format(len(headers)))
  1052. for index, header in enumerate(headers, start=1):
  1053. lines.append('{0}. {1}'.format(index, header['label']))
  1054. for index, row in enumerate(rows, start=1):
  1055. lines.append('记录 {0}:'.format(index))
  1056. for header, value in zip(headers, row):
  1057. if isinstance(value, (dict, list)):
  1058. value = json.dumps(value, ensure_ascii=False)
  1059. lines.append('- {0}: {1}'.format(header['label'], value))
  1060. tips = content.get('tips') or []
  1061. if tips:
  1062. lines.append('提示:{0}'.format(';'.join(tips)))
  1063. return '\n'.join(lines)
  1064. @staticmethod
  1065. def _success_result(content, text, meta):
  1066. return {
  1067. 'structured_content': content,
  1068. 'text': text,
  1069. 'is_error': False,
  1070. 'meta': meta,
  1071. }
  1072. @staticmethod
  1073. def _error_result(code, message, retryable, meta=None):
  1074. return {
  1075. 'structured_content': {
  1076. 'code': code,
  1077. 'message': message,
  1078. 'retryable': retryable,
  1079. },
  1080. 'text': '{0}: {1}'.format(code, message),
  1081. 'is_error': True,
  1082. 'meta': meta or {},
  1083. }
  1084. @classmethod
  1085. def _format_error(cls, meta=None):
  1086. return cls._error_result(
  1087. 'MCP_9001',
  1088. '工具返回格式异常',
  1089. True,
  1090. meta,
  1091. )