maintain_remote_address.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. class MaintainRemoteAddressTool:
  2. name = 'maintain_remote_address'
  3. route_path = '/mcp/tools/maintainRemoteAddress'
  4. backend = 'base'
  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. '编号格式为PY加数字,例如PY12,必须来自query_remote_address_list的结果。'
  13. '新增地址库,或修改名称和状态,请使用save_remote_address。'
  14. '禁止使用:手填不存在的编号、导入文件、删除明细、保存名称。'
  15. '临时键是内部字段,不要向用户展示。'
  16. '参数只用于工具内部调用;最终回答只能展示中文业务名称和地址库编号。'
  17. ),
  18. 'input_schema': {
  19. 'type': 'object',
  20. 'properties': {
  21. 'address_no': {
  22. 'type': 'string',
  23. 'minLength': 1,
  24. 'maxLength': 20,
  25. 'description': '要维护的地址库编号。不传表示准备新增。',
  26. },
  27. 'page': {
  28. 'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 1,
  29. },
  30. 'limit': {
  31. 'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 20,
  32. },
  33. },
  34. 'additionalProperties': False,
  35. },
  36. }
  37. def call(
  38. self,
  39. address_no=None,
  40. page=1,
  41. limit=20,
  42. request_id='rq_maintain_remote_address',
  43. ):
  44. if self.api_client is None:
  45. raise RuntimeError(
  46. 'api client is required for maintain_remote_address'
  47. )
  48. payload = {
  49. 'page': QueryPage.page(page),
  50. 'limit': QueryPage.limit(limit),
  51. }
  52. if address_no is not None:
  53. if not isinstance(address_no, str):
  54. raise ValueError('address_no is invalid')
  55. address_no = address_no.strip()
  56. if address_no:
  57. payload['address_no'] = address_no
  58. return self.api_client.call_tool(
  59. self.name, self.route_path, payload, request_id,
  60. )
  61. class QueryPage:
  62. @staticmethod
  63. def page(value):
  64. if isinstance(value, bool) or not isinstance(value, int) or value < 1 or value > 100:
  65. raise ValueError('page is invalid')
  66. return value
  67. @staticmethod
  68. def limit(value):
  69. if isinstance(value, bool) or not isinstance(value, int) or value < 1 or value > 100:
  70. raise ValueError('limit is invalid')
  71. return value