The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(mcp_server_manager.py): support static headers
Krrish Dholakia65ef9b2ee78e
diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.pyindex c25f3938e43..1705d1e2ff8 100644--- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py+++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py@@ -218,6 +218,7 @@ class MCPServerManager:disallowed_tools=server_config.get("disallowed_tools", None),allowed_params=server_config.get("allowed_params", None),access_groups=server_config.get("access_groups", None),+ static_headers=server_config.get("static_headers", None),)self.config_mcp_servers[server_id] = new_server@@ -632,6 +633,11 @@ class MCPServerManager:client = Nonetry:+ if server.static_headers:+ if extra_headers is None:+ extra_headers = {}+ extra_headers.update(server.static_headers)+client = self._create_mcp_client(server=server,mcp_auth_header=mcp_auth_header,@@ -1098,12 +1104,16 @@ class MCPServerManager:server_auth_header: Optional[Union[Dict[str, str], str]] = Noneif mcp_server_auth_headers:# Normalize keys for case-insensitive lookup- normalized_headers = {k.lower(): v for k, v in mcp_server_auth_headers.items()}-+ normalized_headers = {+ k.lower(): v for k, v in mcp_server_auth_headers.items()+ }+if mcp_server.alias:server_auth_header = normalized_headers.get(mcp_server.alias.lower())if server_auth_header is None and mcp_server.server_name:- server_auth_header = normalized_headers.get(mcp_server.server_name.lower())+ server_auth_header = normalized_headers.get(+ mcp_server.server_name.lower()+ )# Fall back to deprecated mcp_auth_header if no server-specific header foundif server_auth_header is None:@@ -1121,6 +1131,11 @@ class MCPServerManager:if header in raw_headers:extra_headers[header] = raw_headers[header]+ if mcp_server.static_headers:+ if extra_headers is None:+ extra_headers = {}+ extra_headers.update(mcp_server.static_headers)+client = self._create_mcp_client(server=mcp_server,mcp_auth_header=server_auth_header,diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 2880e31e293..b22aa856749 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -19,3 +19,11 @@ vector_store_registry:api_base: https://krris-mh44uf7y-eastus2.cognitiveservices.azure.com/api_key: os.environ/AZURE_API_KEYapi_version: "2025-09-01"+mcp_servers:+ local_fake_mcp:+ url: "http://127.0.0.1:8001/mcp"+ transport: "http"+ description: "My custom MCP server"+ auth_type: "api_key"+ auth_value: "abc123"+ static_headers: {"X-API-Key": "abc123"}diff --git a/litellm/types/mcp_server/mcp_server_manager.py b/litellm/types/mcp_server/mcp_server_manager.pyindex 03bee94eb8b..b0ddc017d17 100644--- a/litellm/types/mcp_server/mcp_server_manager.py+++ b/litellm/types/mcp_server/mcp_server_manager.py@@ -22,7 +22,7 @@ class MCPServer(BaseModel):authentication_token: Optional[str] = Nonemcp_info: Optional[MCPInfo] = Noneextra_headers: Optional[List[str]] = (- None # allow admin to specify which headers to forward to the MCP server+ None # allow admin to specify which headers to forward from client to the MCP server)allowed_tools: Optional[List[str]] = Nonedisallowed_tools: Optional[List[str]] = None@@ -40,4 +40,7 @@ class MCPServer(BaseModel):args: Optional[List[str]] = Noneenv: Optional[Dict[str, str]] = Noneaccess_groups: Optional[List[str]] = None+ static_headers: Optional[Dict[str, str]] = (+ None # static headers to forward to the MCP server+ )model_config = ConfigDict(arbitrary_types_allowed=True)