mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

fix(api): Login redirect loop (#5190)

Open gcgoncalves opened this issue 5 months ago โ€ข 0 comments

๐Ÿ› Bug-fix PR

Closes #5190


๐Ÿ“Œ Summary

When the MCP_CLIENT_AUTH_ENABLED flag is set to false, logging into the admin UI goes into an infinite redirect loop between /admin and /admin/login.

๐Ÿ” Reproduction Steps

  1. Set MCP_CLIENT_AUTH_ENABLED to false
  2. Access the admin UI
  3. Open the browser network tab
  4. Login
  5. Watch the browser network tab

๐Ÿž Root Cause

The loop is:

  1. GET /admin: route dependency get_current_user_with_permissions enters mcp_client_auth_enabled=False block, hits is_proxy_auth_trust_active()=False โ†’ redirects browser to /admin/login. The JWT cookie is present but the function returns early before ever reaching the JWT-reading code.

  2. GET /admin/login: admin_login_page reads the JWT cookie, validates it, sees is_admin=True โ†’ redirects to /admin

๐Ÿ’ก Fix Description

Before entering the mcp_client_auth_enabled=False block, check if a JWT token is already present. If it is, skip the block and fall through to standard JWT validation.

๐Ÿงช Verification

Check Command Status
Lint suite make lint โœ…
Unit tests make test โœ…
Coverage โ‰ฅ 80 % make coverage โœ…
Manual regression no longer fails steps / screenshots โœ…

๐Ÿ“ MCP Compliance (if relevant)

  • [ ] Matches current MCP spec
  • [ ] No breaking change to MCP clients

โœ… Checklist

  • [X] Code formatted (make black isort pre-commit)
  • [X] No secrets/credentials committed

gcgoncalves avatar Jun 12 '26 10:06 gcgoncalves