Skip to content

Commit 3c34954

Browse files
committed
limit tool name length
1 parent 83c9180 commit 3c34954

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
@@ -17,6 +17,8 @@
1717

1818
logger = logging.getLogger(__name__)
1919

20+
FULL_TOOL_NAME_MAX_LENGTH = 55
21+
2022

2123
class LowlevelMCPServer(Server):
2224
def call_tool(self):
@@ -489,13 +491,34 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
489491
operations_by_tag: Dict[str, List[str]] = {}
490492
for path, path_item in openapi_schema.get("paths", {}).items():
491493
for method, operation in path_item.items():
494+
operation_id = operation.get("operationId")
492495
if method not in ["get", "post", "put", "delete", "patch"]:
496+
logger.warning(f"Skipping non-HTTP method: {method.upper()} {path}, operation_id: {operation_id}")
493497
continue
494498

495-
operation_id = operation.get("operationId")
496499
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}")
497508
continue
498509

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+
499522
tags = operation.get("tags", [])
500523
for tag in tags:
501524
if tag not in operations_by_tag:
@@ -530,3 +553,6 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
530553
}
531554

532555
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

Comments
 (0)