From ed108151524fcedfae331ebd36417aca513f7812 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 20 May 2026 18:34:28 +0000 Subject: [PATCH] fix(mcp): reuse proxy_logging DualCache in inject_mcp_jwt_headers_for_upstream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of allocating a fresh DualCache() on every tools/list invocation, prefer the shared proxy_logging_obj.internal_usage_cache.dual_cache when available. The cache argument is currently unused by MCPJWTSigner, but sharing the proxy's cache avoids per-call allocation overhead and matches the cache identity used elsewhere in the proxy hook plumbing — so any future per-request state stored in cache will survive across list calls. Co-authored-by: Claude --- .../mcp_jwt_signer/mcp_jwt_signer.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py index 0d505907ff1..0f299f4c5f7 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py @@ -945,9 +945,22 @@ async def inject_mcp_jwt_headers_for_upstream( call_type: CallTypesLiteral = ( "list_mcp_tools" if for_list_tools else "call_mcp_tool" ) + try: + from litellm.proxy.proxy_server import ( # noqa: PLC0415 + proxy_logging_obj as _proxy_logging, + ) + + shared_cache = ( + _proxy_logging.internal_usage_cache.dual_cache + if _proxy_logging is not None + else DualCache() + ) + except Exception: + shared_cache = DualCache() + result = await signer.async_pre_call_hook( user_api_key_dict=user_api_key_dict, - cache=DualCache(), + cache=shared_cache, data=hook_data, call_type=call_type, )