Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/_experimental/mcp_server/auth/litellm_auth_handler.py: 100%
12 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
1from mcp.server.auth.middleware.bearer_auth import AuthenticatedUser
3from litellm.proxy._types import UserAPIKeyAuth
6class MCPAuthenticatedUser(AuthenticatedUser):
7 """
8 Wrapper class to make LiteLLM's authentication and configuration compatible with MCP's AuthenticatedUser.
10 This class handles:
11 1. User API key authentication information
12 2. MCP authentication header (deprecated)
13 3. MCP server configuration (can include access groups)
14 4. Server-specific authentication headers
15 5. OAuth2 headers
16 6. Raw headers - allows forwarding specific headers to the MCP server, specified by the admin.
17 """
19 def __init__(
20 self,
21 user_api_key_auth: UserAPIKeyAuth | None,
22 mcp_auth_header: str | None = None,
23 mcp_servers: list[str] | None = None,
24 mcp_server_auth_headers: dict[str, dict[str, str]] | None = None,
25 oauth2_headers: dict[str, str] | None = None,
26 mcp_protocol_version: str | None = None,
27 raw_headers: dict[str, str] | None = None,
28 client_ip: str | None = None,
29 ):
30 self.user_api_key_auth = user_api_key_auth
31 self.mcp_auth_header = mcp_auth_header
32 self.mcp_servers = mcp_servers
33 self.mcp_server_auth_headers = mcp_server_auth_headers or {}
34 self.mcp_protocol_version = mcp_protocol_version
35 self.oauth2_headers = oauth2_headers
36 self.raw_headers = raw_headers
37 self.client_ip = client_ip