Skip to content

Commit 198e32e

Browse files
committed
limit tool name length
1 parent 174848f commit 198e32e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

fastapi_mcp/openapi/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def convert_openapi_to_mcp_tools(
4343
for method, operation in path_item.items():
4444
# Skip non-HTTP methods
4545
if method not in ["get", "post", "put", "delete", "patch"]:
46-
logger.warning(f"Skipping non-HTTP method: {method}")
46+
logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}")
4747
continue
4848

4949
# Get operation metadata
5050
operation_id = operation.get("operationId")
5151
if not operation_id:
52-
logger.warning(f"Skipping operation with no operationId: {operation}")
52+
logger.warning(f"Skipping operation with no operationId: {method.upper()} {path}, details: {operation}")
5353
continue
5454

5555
# Save operation details for later HTTP calls

fastapi_mcp/server.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
logger = getLogger(__name__)
1818

19+
FULL_TOOL_NAME_MAX_LENGTH = 55
20+
1921

2022
class FastApiMCP:
2123
def __init__(
@@ -327,13 +329,34 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
327329
operations_by_tag: Dict[str, List[str]] = {}
328330
for path, path_item in openapi_schema.get("paths", {}).items():
329331
for method, operation in path_item.items():
332+
operation_id = operation.get("operationId")
330333
if method not in ["get", "post", "put", "delete", "patch"]:
334+
logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}, operation_id: {operation_id}")
331335
continue
332336

333-
operation_id = operation.get("operationId")
334337
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}")
335346
continue
336347

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+
337360
tags = operation.get("tags", [])
338361
for tag in tags:
339362
if tag not in operations_by_tag:
@@ -368,3 +391,6 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
368391
}
369392

370393
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

Comments
 (0)