Explorar el Código

mcp优化应收费用单

jackson hace 2 semanas
padre
commit
0fe0dcac0a

+ 15 - 4
tests/test_receivable_cost_list_tools.py

@@ -197,7 +197,7 @@ class ReceivableCostFilterOptionsToolTest(ToolLoaderMixin, unittest.TestCase):
             'ListReceivableCostFilterOptionsTool',
         )
 
-    def test_schema_has_exact_types_and_customer_dependency(self):
+    def test_schema_has_exact_types_and_optional_customer_id(self):
         metadata = self.tool_class()().metadata()
         schema = metadata['input_schema']
         self.assertFalse(schema['additionalProperties'])
@@ -210,10 +210,12 @@ class ReceivableCostFilterOptionsToolTest(ToolLoaderMixin, unittest.TestCase):
             {'type': 'integer', 'minimum': 1},
             schema['properties']['customer_id'],
         )
+        self.assertNotIn('allOf', schema)
         self.assertIn('子客户', json.dumps(schema, ensure_ascii=False))
         self.assertIn('禁止猜测', metadata['description'])
+        self.assertIn('可选', metadata['description'])
 
-    def test_call_forwards_and_enforces_customer_linkage(self):
+    def test_call_forwards_sub_customer_with_optional_customer_id(self):
         tool_class = self.tool_class()
         client = RecordingApiClient()
         tool = tool_class(client)
@@ -237,9 +239,18 @@ class ReceivableCostFilterOptionsToolTest(ToolLoaderMixin, unittest.TestCase):
             },
             'rq_filters',
         ), client.calls[-1])
+        tool.call(filter_type='子客户')
+        self.assertEqual(
+            {
+                'filter_type': '子客户',
+                'keyword': '',
+                'page': 1,
+                'limit': 20,
+            },
+            client.calls[-1][2],
+        )
         tool.call(filter_type='主客户')
         for arguments in (
-            {'filter_type': '子客户'},
             {'filter_type': 7},
             {'filter_type': '子客户', 'customer_id': 0},
             {'filter_type': '主客户', 'customer_id': 7},
@@ -253,7 +264,7 @@ class ReceivableCostFilterOptionsToolTest(ToolLoaderMixin, unittest.TestCase):
             with self.subTest(arguments=arguments):
                 with self.assertRaises((TypeError, ValueError)):
                     tool.call(**arguments)
-        self.assertEqual(2, len(client.calls))
+        self.assertEqual(3, len(client.calls))
         with self.assertRaisesRegex(RuntimeError, 'api client is required'):
             tool_class().call('主客户')
 

+ 4 - 13
tools/list_receivable_cost_filter_options.py

@@ -12,8 +12,8 @@ class ListReceivableCostFilterOptionsTool:
             'description': (
                 '为query_receivable_cost_list取得当前员工授权范围内的主客户、子客户、'
                 '出账状态、核销状态、单据类型或费用项筛选值。调用查询工具时必须使用本工具'
-                '返回的value,禁止猜测内部ID或状态值。查询子客户时必须提供已选择的主客户'
-                'customer_id;其他筛选类型不得传customer_id。'
+                '返回的value,禁止猜测内部ID或状态值。查询子客户时可直接分页检索,也可选'
+                '传入主客户customer_id缩小范围;其他筛选类型不得传customer_id。'
             ),
             'input_schema': {
                 'type': 'object',
@@ -33,14 +33,6 @@ class ListReceivableCostFilterOptionsTool:
                     },
                 },
                 'required': ['filter_type'],
-                'allOf': [{
-                    'if': {
-                        'properties': {'filter_type': {'const': '子客户'}},
-                        'required': ['filter_type'],
-                    },
-                    'then': {'required': ['customer_id']},
-                    'else': {'not': {'required': ['customer_id']}},
-                }],
                 'additionalProperties': False,
             },
         }
@@ -64,9 +56,8 @@ class ListReceivableCostFilterOptionsTool:
         if filter_type not in self.FILTER_TYPES:
             raise ValueError('filter_type is invalid')
         if filter_type == '子客户':
-            if customer_id is None:
-                raise ValueError('customer_id is required for 子客户')
-            customer_id = self._positive_integer(customer_id, 'customer_id')
+            if customer_id is not None:
+                customer_id = self._positive_integer(customer_id, 'customer_id')
         elif customer_id is not None:
             raise ValueError('customer_id is only valid for 子客户')
         if not isinstance(keyword, str):