Bug Summary
The GET /teams endpoint returns 500 error because it uses current_user_ctx["db"] which is always None. The get_current_user_with_permissions function explicitly returns "db": None with the comment "Session closed; use endpoint's db param instead", but the teams router doesn't follow this pattern.
Affected Component
mcpgateway/routers/teams.py - list_teams() function (line 143)
Root Cause
Line 143 in teams.py:
db = current_user_ctx["db"] # This is always None!
The get_current_user_with_permissions function in rbac.py returns:
"db": None, # Session closed; use endpoint's db param instead
Error Message
mcpgateway.routers.teams - ERROR - Error listing teams: 'NoneType' object has no attribute 'execute'
Steps to Reproduce
TOKEN=$(python -m mcpgateway.utils.create_jwt_token --username admin@example.com --exp 60 --secret "$JWT_SECRET")
curl -X GET "http://localhost:8080/teams/" -H "Authorization: Bearer $TOKEN"
Expected Behavior
Returns list of teams.
Actual Behavior
Returns 500 with {"detail":"Failed to list teams"}
Fix
Add db: Session = Depends(get_db) as a parameter to list_teams() and use it directly instead of extracting from current_user_ctx.
Discovered During
Locust load testing with TeamsUser class.
Bug Summary
The
GET /teamsendpoint returns 500 error because it usescurrent_user_ctx["db"]which is alwaysNone. Theget_current_user_with_permissionsfunction explicitly returns"db": Nonewith the comment "Session closed; use endpoint's db param instead", but the teams router doesn't follow this pattern.Affected Component
mcpgateway/routers/teams.py-list_teams()function (line 143)Root Cause
Line 143 in
teams.py:The
get_current_user_with_permissionsfunction inrbac.pyreturns:Error Message
Steps to Reproduce
Expected Behavior
Returns list of teams.
Actual Behavior
Returns 500 with
{"detail":"Failed to list teams"}Fix
Add
db: Session = Depends(get_db)as a parameter tolist_teams()and use it directly instead of extracting fromcurrent_user_ctx.Discovered During
Locust load testing with
TeamsUserclass.