refactor: Standardize root_path access and fix redirect trailing slashes #1598
+104
−108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📌 Summary
Standardizes root path handling and fixes redirect URLs to avoid unnecessary FastAPI 307 redirects.
Fixes #1588
🔁 Changes Made
Part 1: Standardize root_path access
Replaced all occurrences of
request.scope.get("root_path", "")withsettings.app_root_pathfor consistency and cleaner code.mcpgateway/admin.py(74 occurrences)mcpgateway/utils/verify_credentials.py(3 occurrences)mcpgateway/routers/oauth_router.py(1 occurrence)mcpgateway/routers/sso.py(1 occurrence)Part 2: Add trailing slashes to redirect URLs
Added trailing slashes to
/adminredirects to prevent FastAPI from issuing unnecessary 307 redirects.mcpgateway/admin.py(23 occurrences)mcpgateway/routers/sso.py(1 occurrence){root_path}/admin→{root_path}/admin/{root_path}/admin#→{root_path}/admin/#🧪 Verification
✅ Acceptance Criteria Met
request.scope.get("root_path", "")replaced withsettings.app_root_path📝 Notes