Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions litellm/proxy/_experimental/mcp_server/ui_session_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ async def resolve_ui_session_team_ids(
prisma_client=prisma_client,
user_api_key_cache=user_api_key_cache,
user_id_upsert=False,
# UI-session authorization must observe grants, revocations, and
# offboarding on the next request. A cached user row can retain a
# pre-login or pre-reconciliation team list until its management
# TTL expires, which makes both grants and revocations stale.
check_db_only=True,
Comment on lines +51 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Remove the new inline comment

This explanatory comment violates the repository-wide instruction against adding code comments unless explicitly requested, creating avoidable policy cleanup for an otherwise self-contained change

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

parent_otel_span=user_api_key_auth.parent_otel_span,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Database lookup enters request path

Setting check_db_only=True bypasses the user cache for every UI-session MCP discovery and tool call, adding a database query and its latency to each request while increasing database load under concurrent use

Rule Used: What: Avoid creating new database requests or Rout... (source)

Knowledge Base Used: Proxy Authentication and Authorization

proxy_logging_obj=proxy_logging_obj,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ async def test_resolve_ui_session_team_ids_returns_unique_ids(monkeypatch):
teams=["team-a", "team-b", "team-a", "", None, "team-c"]
)

get_user_object = AsyncMock(return_value=fake_user)
monkeypatch.setattr(
"litellm.proxy.auth.auth_checks.get_user_object",
AsyncMock(return_value=fake_user),
get_user_object,
)

import litellm.proxy.proxy_server as proxy_server
Expand All @@ -49,6 +50,41 @@ async def test_resolve_ui_session_team_ids_returns_unique_ids(monkeypatch):
team_ids = await resolve_ui_session_team_ids(user_auth)

assert team_ids == ["team-a", "team-b", "team-c"]
get_user_object.assert_awaited_once()
assert get_user_object.await_args.kwargs["check_db_only"] is True


@pytest.mark.asyncio
async def test_resolve_ui_session_team_ids_observes_next_call_revocation(monkeypatch):
user_auth = UserAPIKeyAuth(
team_id=UI_SESSION_TOKEN_TEAM_ID,
user_id="user-revoked",
)

get_user_object = AsyncMock(
side_effect=[
SimpleNamespace(teams=["team-a"]),
SimpleNamespace(teams=[]),
]
)
monkeypatch.setattr(
"litellm.proxy.auth.auth_checks.get_user_object",
get_user_object,
)

import litellm.proxy.proxy_server as proxy_server

monkeypatch.setattr(proxy_server, "prisma_client", object())
monkeypatch.setattr(proxy_server, "proxy_logging_obj", None)
monkeypatch.setattr(proxy_server, "user_api_key_cache", None)

assert await resolve_ui_session_team_ids(user_auth) == ["team-a"]
assert await resolve_ui_session_team_ids(user_auth) == []
assert get_user_object.await_count == 2
assert all(
call.kwargs["check_db_only"] is True
for call in get_user_object.await_args_list
)


@pytest.mark.asyncio
Expand Down
Loading