From e4611faf581ef055e330843fc6e11219fef7ed24 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Sat, 21 Mar 2026 12:46:33 -0700 Subject: [PATCH] fix: invalidate ObjectPermissionTable cache alongside team cache _invalidate_team_cache only cleared the team object cache but not the ObjectPermissionTable cache. After add_mcp_server_to_team, the team was re-fetched from DB but its object_permission was served from stale cache, causing newly created servers to not appear in the list. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../object_permission_utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/management_helpers/object_permission_utils.py b/litellm/proxy/management_helpers/object_permission_utils.py index a4b52962332..ddd7ba96598 100644 --- a/litellm/proxy/management_helpers/object_permission_utils.py +++ b/litellm/proxy/management_helpers/object_permission_utils.py @@ -366,11 +366,17 @@ async def validate_key_mcp_servers_against_team( ) -def _invalidate_team_cache(team_id: str) -> None: - """Invalidate the cached team object so subsequent reads see updated data.""" +def _invalidate_team_cache( + team_id: str, object_permission_id: Optional[str] = None +) -> None: + """Invalidate the cached team object and its ObjectPermissionTable so subsequent reads see updated data.""" from litellm.proxy.proxy_server import user_api_key_cache user_api_key_cache.delete_cache(key="team_id:{}".format(team_id)) + if object_permission_id: + user_api_key_cache.delete_cache( + key="object_permission_id:{}".format(object_permission_id) + ) async def add_mcp_server_to_team( @@ -429,7 +435,7 @@ async def add_mcp_server_to_team( ) # Invalidate team cache so the updated mcp_servers list is visible immediately - _invalidate_team_cache(team_id) + _invalidate_team_cache(team_id, object_permission_id) async def remove_mcp_server_from_team( @@ -464,4 +470,6 @@ async def remove_mcp_server_from_team( ) # Invalidate team cache so the updated mcp_servers list is visible immediately - _invalidate_team_cache(team_id) + _invalidate_team_cache( + team_id, team.object_permission_id if team else None + )