|
17 | 17 |
|
18 | 18 | logger = logging.getLogger(__name__)
|
19 | 19 |
|
| 20 | +FULL_TOOL_NAME_MAX_LENGTH = 55 |
| 21 | + |
20 | 22 |
|
21 | 23 | class LowlevelMCPServer(Server):
|
22 | 24 | def call_tool(self):
|
@@ -489,13 +491,34 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
|
489 | 491 | operations_by_tag: Dict[str, List[str]] = {}
|
490 | 492 | for path, path_item in openapi_schema.get("paths", {}).items():
|
491 | 493 | for method, operation in path_item.items():
|
| 494 | + operation_id = operation.get("operationId") |
492 | 495 | if method not in ["get", "post", "put", "delete", "patch"]:
|
| 496 | + logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}, operation_id: {operation_id}") |
493 | 497 | continue
|
494 | 498 |
|
495 |
| - operation_id = operation.get("operationId") |
496 | 499 | if not operation_id:
|
| 500 | + logger.warning( |
| 501 | + f"Skipping operation with no operationId: {method.upper()} {path}, details: {operation}" |
| 502 | + ) |
| 503 | + continue |
| 504 | + |
| 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}") |
497 | 508 | continue
|
498 | 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 | + |
499 | 522 | tags = operation.get("tags", [])
|
500 | 523 | for tag in tags:
|
501 | 524 | if tag not in operations_by_tag:
|
@@ -530,3 +553,6 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
|
530 | 553 | }
|
531 | 554 |
|
532 | 555 | return filtered_tools
|
| 556 | + |
| 557 | + def get_tool_full_name(self, operation_id: str) -> str: |
| 558 | + return f"{self.name}\\{operation_id}" |
0 commit comments