diff --git a/litellm/proxy/_experimental/mcp_server/oauth_utils.py b/litellm/proxy/_experimental/mcp_server/oauth_utils.py index 6ac3c8cf2a7..3f99784f2c4 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_utils.py +++ b/litellm/proxy/_experimental/mcp_server/oauth_utils.py @@ -13,6 +13,7 @@ from litellm.proxy.auth.ip_address_utils import IPAddressUtils # must not be cached — both success and error bodies may reveal secrets. TOKEN_NO_CACHE_HEADERS = {"Cache-Control": "no-store", "Pragma": "no-cache"} + def get_request_base_url(request: Request) -> str: """ Get the base URL for the request, considering X-Forwarded-* headers. diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 002c1725d1a..f9e34f4e8c4 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -15276,7 +15276,8 @@ async def dynamic_mcp_route(mcp_server_name: str, request: Request): # Create a new scope with the correct path format that the MCP handler expects # Transform /{mcp_server_name}/mcp to /mcp/{mcp_server_name} scope = dict(request.scope) - scope["_original_path"] = scope.get("path", "") # preserve for 401 URL form selection + # Preserve the public request path for OAuth challenge URL selection. + scope["_original_path"] = scope.get("path", "") scope["path"] = f"/mcp/{mcp_server_name}" # Import the MCP handler