From 3c25cda0b6449fb4750a03fc5340472ec7c31a09 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 9 Feb 2026 14:46:37 -0800 Subject: [PATCH] MCPOAuth2TokenCache --- .../_experimental/mcp_server/oauth2_token_cache.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py b/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py index 9f4e2bc1648..10856267fea 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py +++ b/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py @@ -10,6 +10,11 @@ from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union from litellm._logging import verbose_logger from litellm.caching.in_memory_cache import InMemoryCache +from litellm.constants import ( + MCP_OAUTH2_TOKEN_CACHE_DEFAULT_TTL, + MCP_OAUTH2_TOKEN_CACHE_MAX_SIZE, + MCP_OAUTH2_TOKEN_EXPIRY_BUFFER_SECONDS, +) from litellm.llms.custom_httpx.http_handler import get_async_httpx_client from litellm.types.llms.custom_http import httpxSpecialProvider @@ -17,9 +22,6 @@ if TYPE_CHECKING: from litellm.types.mcp_server.mcp_server_manager import MCPServer -_EXPIRY_BUFFER_SECONDS = 60 - - class MCPOAuth2TokenCache(InMemoryCache): """ In-memory cache for OAuth2 client_credentials tokens, keyed by server_id. @@ -30,8 +32,8 @@ class MCPOAuth2TokenCache(InMemoryCache): def __init__(self) -> None: super().__init__( - max_size_in_memory=200, - default_ttl=3600, + max_size_in_memory=MCP_OAUTH2_TOKEN_CACHE_MAX_SIZE, + default_ttl=MCP_OAUTH2_TOKEN_CACHE_DEFAULT_TTL, ) self._locks: Dict[str, asyncio.Lock] = {} @@ -99,7 +101,7 @@ class MCPOAuth2TokenCache(InMemoryCache): ) expires_in = int(body.get("expires_in", 3600)) - ttl = max(expires_in - _EXPIRY_BUFFER_SECONDS, 0) + ttl = max(expires_in - MCP_OAUTH2_TOKEN_EXPIRY_BUFFER_SECONDS, 0) verbose_logger.info( "Fetched OAuth2 token for MCP server %s (expires in %ds)",