| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- class QueryRemoteAddressListTool:
- name = 'query_remote_address_list'
- route_path = '/mcp/tools/queryRemoteAddressList'
- backend = 'base'
- def __init__(self, api_client=None):
- self.api_client = api_client
- def metadata(self):
- return {
- 'name': self.name,
- 'description': (
- '使用场景:用户要搜索或查看地址库列表时调用。可按地址库编号、'
- '名称、启用状态、国家、州/省、城市、邮编筛选,返回当前页。编号格式为'
- 'PY加数字,例如PY12。不传筛选条件时返回当前公司的地址库列表。'
- '禁止使用:修改地址库、导入地址、删除明细、把内部ID当成编号展示。'
- '参数只用于工具内部调用;最终回答只能展示中文业务名称和地址库编号。'
- ),
- 'input_schema': {
- 'type': 'object',
- 'properties': {
- 'address_no': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 20,
- 'description': '地址库编号,格式为PY加数字,例如PY12。',
- },
- 'remote_name': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 100,
- 'description': '地址库名称,按名称包含匹配。',
- },
- 'status': {
- 'type': 'integer',
- 'enum': [0, 1],
- 'description': '状态。1启用,0禁用。',
- },
- 'country': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 10,
- 'description': '国家代码,精确匹配地址明细。',
- },
- 'province': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 50,
- 'description': '州/省,精确匹配地址明细。',
- },
- 'city': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 50,
- 'description': '城市,精确匹配地址明细。',
- },
- 'postcode': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 20,
- 'description': '邮编,落在地址明细的开始邮编和结束邮编之间。',
- },
- 'page': {
- 'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 1,
- },
- 'limit': {
- 'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 20,
- },
- },
- 'additionalProperties': False,
- },
- }
- def call(
- self,
- address_no=None,
- remote_name=None,
- status=None,
- country=None,
- province=None,
- city=None,
- postcode=None,
- page=1,
- limit=20,
- request_id='rq_query_remote_address_list',
- ):
- if self.api_client is None:
- raise RuntimeError(
- 'api client is required for query_remote_address_list'
- )
- payload = {
- 'page': self._page(page),
- 'limit': self._limit(limit),
- }
- text_fields = {
- 'address_no': address_no,
- 'remote_name': remote_name,
- 'country': country,
- 'province': province,
- 'city': city,
- 'postcode': postcode,
- }
- for key, value in text_fields.items():
- if value is None:
- continue
- if not isinstance(value, str):
- raise ValueError(key + ' is invalid')
- value = value.strip()
- if value:
- payload[key] = value
- if status is not None:
- if isinstance(status, bool) or status not in (0, 1):
- raise ValueError('status is invalid')
- payload['status'] = status
- return self.api_client.call_tool(
- self.name, self.route_path, payload, request_id,
- )
- @staticmethod
- def _page(value):
- if isinstance(value, bool) or not isinstance(value, int) or value < 1 or value > 100:
- raise ValueError('page is invalid')
- return value
- @staticmethod
- def _limit(value):
- if isinstance(value, bool) or not isinstance(value, int) or value < 1 or value > 100:
- raise ValueError('limit is invalid')
- return value
|