Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions mcpgateway/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5148,25 +5148,21 @@ async def cleanup_import_statuses(max_age_hours: int = 24, user=Depends(get_curr

# Redirect root path to admin UI
@app.get("/")
async def root_redirect(request: Request):
async def root_redirect():
"""
Redirects the root path ("/") to "/admin".
Redirects the root path ("/") to "/admin/".

Logs a debug message before redirecting.

Args:
request (Request): The incoming HTTP request (used only to build the
target URL via :pymeth:`starlette.requests.Request.url_for`).

Returns:
RedirectResponse: Redirects to /admin.
RedirectResponse: Redirects to /admin/.

Raises:
HTTPException: If there is an error during redirection.
"""
logger.debug("Redirecting root path to /admin")
root_path = request.scope.get("root_path", "")
return RedirectResponse(f"{root_path}/admin", status_code=303)
logger.debug("Redirecting root path to /admin/")
root_path = settings.app_root_path
return RedirectResponse(f"{root_path}/admin/", status_code=303)
# return RedirectResponse(request.url_for("admin_home"))

else:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/mcpgateway/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ def test_root_redirect(self, test_client):

# Check if UI is enabled
if settings.mcpgateway_ui_enabled:
# When UI is enabled, should redirect to admin
# When UI is enabled, should redirect to admin with trailing slash
assert response.status_code == 303
assert response.headers["location"] == "/admin"
assert response.headers["location"] == f"{settings.app_root_path}/admin/"
else:
# When UI is disabled, should return API info
assert response.status_code == 200
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/mcpgateway/test_main_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pytest

# First-Party
from mcpgateway.config import settings
from mcpgateway.main import app


Expand Down Expand Up @@ -186,9 +187,9 @@ def test_root_endpoint_conditional_behavior(self):
client = TestClient(app)
response = client.get("/", follow_redirects=False)

# Should redirect to /admin when UI is enabled
# Should redirect to /admin/ when UI is enabled
if response.status_code == 303:
assert response.headers.get("location") == "/admin"
assert response.headers.get("location") == f"{settings.app_root_path}/admin/"
else:
# Fallback behavior
assert response.status_code == 200
Expand Down
Loading