|
16 | 16 |
|
17 | 17 | logger = getLogger(__name__)
|
18 | 18 |
|
| 19 | +FULL_TOOL_NAME_MAX_LENGTH = 55 |
| 20 | + |
19 | 21 |
|
20 | 22 | class FastApiMCP:
|
21 | 23 | def __init__(
|
@@ -327,13 +329,34 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
|
327 | 329 | operations_by_tag: Dict[str, List[str]] = {}
|
328 | 330 | for path, path_item in openapi_schema.get("paths", {}).items():
|
329 | 331 | for method, operation in path_item.items():
|
| 332 | + operation_id = operation.get("operationId") |
330 | 333 | if method not in ["get", "post", "put", "delete", "patch"]:
|
| 334 | + logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}, operation_id: {operation_id}") |
331 | 335 | continue
|
332 | 336 |
|
333 |
| - operation_id = operation.get("operationId") |
334 | 337 | if not operation_id:
|
| 338 | + logger.warning( |
| 339 | + f"Skipping operation with no operationId: {method.upper()} {path}, details: {operation}" |
| 340 | + ) |
| 341 | + continue |
| 342 | + |
| 343 | + operation_full_name = self.get_tool_full_name(operation_id) |
| 344 | + if len(operation_full_name) > FULL_TOOL_NAME_MAX_LENGTH: |
| 345 | + logger.warning(f"Skipping operation with exceedingly long operationId: {operation_full_name}") |
335 | 346 | continue
|
336 | 347 |
|
| 348 | + """ |
| 349 | + if method not in ["get", "post", "put", "delete", "patch"]: |
| 350 | + logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}") |
| 351 | + continue |
| 352 | +
|
| 353 | + # Get operation metadata |
| 354 | + operation_id = operation.get("operationId") |
| 355 | + if not operation_id: |
| 356 | + logger.warning(f"Skipping operation with no operationId: {method.upper()} {path}, details: {operation}") |
| 357 | + continue |
| 358 | + """ |
| 359 | + |
337 | 360 | tags = operation.get("tags", [])
|
338 | 361 | for tag in tags:
|
339 | 362 | if tag not in operations_by_tag:
|
@@ -368,3 +391,6 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
|
368 | 391 | }
|
369 | 392 |
|
370 | 393 | return filtered_tools
|
| 394 | + |
| 395 | + def get_tool_full_name(self, operation_id: str) -> str: |
| 396 | + return f"{self.name}\\{operation_id}" |
0 commit comments