diff --git a/api/core/tools/utils/parser.py b/api/core/tools/utils/parser.py index 741adfcc101..b65bf02be88 100644 --- a/api/core/tools/utils/parser.py +++ b/api/core/tools/utils/parser.py @@ -204,7 +204,7 @@ class ApiBasedToolSchemaParser: bundles.append( ApiToolBundle( - server_url=server_url + interface["path"], + server_url=server_url.rstrip("/") + interface["path"], method=interface["method"], summary=interface["operation"]["description"] if "description" in interface["operation"] diff --git a/api/tests/unit_tests/core/tools/utils/test_parser.py b/api/tests/unit_tests/core/tools/utils/test_parser.py index 5a858134b4c..684d7a8815f 100644 --- a/api/tests/unit_tests/core/tools/utils/test_parser.py +++ b/api/tests/unit_tests/core/tools/utils/test_parser.py @@ -511,3 +511,33 @@ def test_openapi_31_union_with_only_null_returns_none(): parameter = {"name": "value", "schema": {"type": ["null"]}} assert ApiBasedToolSchemaParser._get_tool_parameter_type(parameter) is None + + +def test_parse_openapi_to_tool_bundle_avoids_double_slash_in_server_url(app: Flask) -> None: + openapi = { + "openapi": "3.0.0", + "info": {"title": "API", "version": "1.0.0"}, + "servers": [{"url": "https://api.example.com/v1/"}], + "paths": {"/items": {"get": {"summary": "List items", "responses": {"200": {"description": "OK"}}}}}, + } + + with app.test_request_context(): + bundles = ApiBasedToolSchemaParser.parse_openapi_to_tool_bundle(openapi) + + assert len(bundles) == 1 + assert bundles[0].server_url == "https://api.example.com/v1/items" + + +def test_parse_openapi_to_tool_bundle_keeps_server_url_without_trailing_slash(app: Flask) -> None: + openapi = { + "openapi": "3.0.0", + "info": {"title": "API", "version": "1.0.0"}, + "servers": [{"url": "https://api.example.com/v1"}], + "paths": {"/items": {"get": {"summary": "List items", "responses": {"200": {"description": "OK"}}}}}, + } + + with app.test_request_context(): + bundles = ApiBasedToolSchemaParser.parse_openapi_to_tool_bundle(openapi) + + assert len(bundles) == 1 + assert bundles[0].server_url == "https://api.example.com/v1/items"