17
17
18
18
logger = logging .getLogger (__name__ )
19
19
20
- FULL_TOOL_NAME_MAX_LENGTH = 55
21
-
22
20
23
21
class LowlevelMCPServer (Server ):
24
22
def call_tool (self ):
@@ -111,6 +109,10 @@ def __init__(
111
109
Optional [List [str ]],
112
110
Doc ("List of tags to exclude from MCP tools. Cannot be used with include_tags." ),
113
111
] = None ,
112
+ max_tool_name_length : Annotated [
113
+ Optional [int ],
114
+ Doc ("Maximum length allowed for tools (some vendors prohibit long names)." )
115
+ ] = None ,
114
116
auth_config : Annotated [
115
117
Optional [AuthConfig ],
116
118
Doc ("Configuration for MCP authentication" ),
@@ -138,6 +140,7 @@ def __init__(
138
140
self ._exclude_operations = exclude_operations
139
141
self ._include_tags = include_tags
140
142
self ._exclude_tags = exclude_tags
143
+ self ._max_tool_name_length = max_tool_name_length
141
144
self ._auth_config = auth_config
142
145
143
146
if self ._auth_config :
@@ -485,6 +488,7 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
485
488
and self ._exclude_operations is None
486
489
and self ._include_tags is None
487
490
and self ._exclude_tags is None
491
+ and self ._max_tool_name_length is None
488
492
):
489
493
return tools
490
494
@@ -502,23 +506,6 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
502
506
)
503
507
continue
504
508
505
- operation_full_name = self .get_tool_full_name (operation_id )
506
- if len (operation_full_name ) > FULL_TOOL_NAME_MAX_LENGTH :
507
- logger .warning (f"Skipping operation with exceedingly long operationId: { operation_full_name } " )
508
- continue
509
-
510
- """
511
- if method not in ["get", "post", "put", "delete", "patch"]:
512
- logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}")
513
- continue
514
-
515
- # Get operation metadata
516
- operation_id = operation.get("operationId")
517
- if not operation_id:
518
- logger.warning(f"Skipping operation with no operationId: {method.upper()} {path}, details: {operation}")
519
- continue
520
- """
521
-
522
509
tags = operation .get ("tags" , [])
523
510
for tag in tags :
524
511
if tag not in operations_by_tag :
@@ -527,11 +514,14 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
527
514
528
515
operations_to_include = set ()
529
516
517
+ all_operations = {tool .name for tool in tools }
518
+
530
519
if self ._include_operations is not None :
531
520
operations_to_include .update (self ._include_operations )
532
521
elif self ._exclude_operations is not None :
533
- all_operations = {tool .name for tool in tools }
534
522
operations_to_include .update (all_operations - set (self ._exclude_operations ))
523
+ elif self ._max_tool_name_length is not None :
524
+ operations_to_include .update (all_operations ) # all_operations
535
525
536
526
if self ._include_tags is not None :
537
527
for tag in self ._include_tags :
@@ -541,9 +531,14 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
541
531
for tag in self ._exclude_tags :
542
532
excluded_operations .update (operations_by_tag .get (tag , []))
543
533
544
- all_operations = {tool .name for tool in tools }
545
534
operations_to_include .update (all_operations - excluded_operations )
546
535
536
+ if self ._max_tool_name_length is not None :
537
+ long_operations = {
538
+ tool .name for tool in tools if len (self .get_combined_full_name (tool .name )) > self ._max_tool_name_length
539
+ }
540
+ operations_to_include = operations_to_include - long_operations
541
+
547
542
filtered_tools = [tool for tool in tools if tool .name in operations_to_include ]
548
543
549
544
if filtered_tools :
@@ -554,5 +549,17 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
554
549
555
550
return filtered_tools
556
551
557
- def get_tool_full_name (self , operation_id : str ) -> str :
552
+ def get_combined_full_name (self , operation_id : str ) -> str :
553
+ """
554
+ Combined name consists of server name + operation_id
555
+
556
+ Args:
557
+ operation_id: As defined during creation
558
+
559
+ Returns:
560
+ concatenated string of server name + operation_id
561
+ """
562
+ if not self .name :
563
+ return operation_id
564
+
558
565
return f"{ self .name } \\ { operation_id } "
0 commit comments