@@ -319,13 +319,14 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
319
319
Returns:
320
320
Filtered list of tools
321
321
"""
322
- if (
323
- self ._include_operations is None
324
- and self ._exclude_operations is None
325
- and self ._include_tags is None
326
- and self ._exclude_tags is None
327
- and self ._max_tool_name_length is None
328
- ):
322
+ include_exclude_conditions_exist = (
323
+ self ._include_operations is not None
324
+ or self ._exclude_operations is not None
325
+ or self ._include_tags is not None
326
+ or self ._exclude_tags is not None
327
+ )
328
+
329
+ if not include_exclude_conditions_exist and self ._max_tool_name_length is None :
329
330
return tools
330
331
331
332
operations_by_tag : Dict [str , List [str ]] = {}
@@ -356,8 +357,6 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
356
357
operations_to_include .update (self ._include_operations )
357
358
elif self ._exclude_operations is not None :
358
359
operations_to_include .update (all_operations - set (self ._exclude_operations ))
359
- elif self ._max_tool_name_length is not None :
360
- operations_to_include .update (all_operations ) # all_operations
361
360
362
361
if self ._include_tags is not None :
363
362
for tag in self ._include_tags :
@@ -369,6 +368,11 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
369
368
370
369
operations_to_include .update (all_operations - excluded_operations )
371
370
371
+ # This condition means that no include/exclude conditions exist,
372
+ # and we've reached this point because we have a max-length limit
373
+ if not include_exclude_conditions_exist :
374
+ operations_to_include = all_operations
375
+
372
376
if self ._max_tool_name_length is not None :
373
377
long_operations = {
374
378
tool .name for tool in tools if len (self .get_combined_full_name (tool .name )) > self ._max_tool_name_length
0 commit comments