Skip to content

fix(mcp): authorize UI sessions as live users - #34585

Open
luckybucky9 wants to merge 2 commits into
BerriAI:mainfrom
luckybucky9:codex/ui-session-live-team-permissions
Open

fix(mcp): authorize UI sessions as live users#34585
luckybucky9 wants to merge 2 commits into
BerriAI:mainfrom
luckybucky9:codex/ui-session-live-team-permissions

Conversation

@luckybucky9

@luckybucky9 luckybucky9 commented Jul 25, 2026

Copy link
Copy Markdown

Summary

  • resolve MCP discovery for a UI session through the existing admitted-user authorization path instead of treating the dashboard key as an ordinary virtual key
  • force interactive user and team-membership authorization to read the current user row from the database
  • preserve team grants, roster checks, organization ceilings, tool permissions, rate limits, revocation, and offboarding on the next request

Why

With require_key_mcp_access_defined: true, cloning a litellm-dashboard UI session into an employee team still applies the ordinary virtual-key ceiling. Because that session key intentionally has no key-level MCP object permission, every team server is hidden even when the employee is correctly provisioned. The DCR bridge already has a server-only admitted-user path that resolves the signed-in employee against live policy; UI discovery should use the same path.

This also closes the stale-user-cache portion of #34566 by using database-only user loads at initial admission and team fan-out.

Tests

  • pytest -q tests/test_litellm/proxy/_experimental/mcp_server/test_ui_session_utils.py tests/test_litellm/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py (302 passed)
  • Ruff check and format check pass on all changed files

Closes the remaining UI-session authorization portion of #34566.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR refreshes UI-session MCP team membership directly from the database

  • Bypasses cached user rows when resolving UI-session team contexts
  • Adds coverage for database-only lookup and next-call team revocation

Confidence Score: 4/5

The PR is safe to merge, with non-blocking cleanup needed for the new inline comment and the request-path database cost

The database-only lookup refreshes grants as intended, but it bypasses the user cache on UI-session MCP requests and introduces an inline comment prohibited by repository guidance

Files Needing Attention: litellm/proxy/_experimental/mcp_server/ui_session_utils.py

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/ui_session_utils.py Forces live database-backed team resolution, adding per-request database work and a new inline comment that conflicts with repository guidance
tests/test_litellm/proxy/_experimental/mcp_server/test_ui_session_utils.py Adds focused assertions that database-only resolution is requested and that a subsequent lookup observes revoked team membership

Reviews (1): Last reviewed commit: "fix(mcp): refresh UI session teams from ..." | Re-trigger Greptile

Comment on lines +51 to +55
# 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,

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!

# pre-login or pre-reconciliation team list until its management
# TTL expires, which makes both grants and revocations stale.
check_db_only=True,
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

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@luckybucky9 luckybucky9 changed the title fix(mcp): refresh UI session teams from database fix(mcp): authorize UI sessions as live users Jul 25, 2026
Comment on lines +92 to +94
from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import (
MCPRequestHandler,
)
@codspeed-hq

codspeed-hq Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing luckybucky9:codex/ui-session-live-team-permissions (bae22aa) with main (0cd588a)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants