From 3700e5d760e1bc44e77c1290dfc0dd7464791df2 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 4 Oct 2025 18:34:47 -0700 Subject: [PATCH] feat(mcp_server_manager.py): add `static_header` support for MCP's Allow admin to configure static custom headers to send on each mcp request to a backend server Closes LIT-1186 --- .../_experimental/mcp_server/mcp_server_manager.py | 11 +++++++++++ litellm/proxy/_new_secret_config.yaml | 3 ++- litellm/types/mcp_server/mcp_server_manager.py | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index bfe7a3e4679..e228b3d6b05 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -216,6 +216,7 @@ class MCPServerManager: allowed_tools=server_config.get("allowed_tools", None), disallowed_tools=server_config.get("disallowed_tools", 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 verbose_logger.debug( @@ -475,6 +476,11 @@ class MCPServerManager: client = None try: + 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, @@ -770,6 +776,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.yaml index 50d36fee048..7de2eaa43aa 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -22,4 +22,5 @@ mcp_servers: transport: "http" description: "My custom MCP server" auth_type: "api_key" - auth_value: "abc123" \ No newline at end of file + 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.py index 3e0c2b20e39..5ad1fd6f244 100644 --- a/litellm/types/mcp_server/mcp_server_manager.py +++ b/litellm/types/mcp_server/mcp_server_manager.py @@ -21,7 +21,7 @@ class MCPServer(BaseModel): authentication_token: Optional[str] = None mcp_info: Optional[MCPInfo] = None extra_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]] = None disallowed_tools: Optional[List[str]] = None @@ -36,4 +36,7 @@ class MCPServer(BaseModel): args: Optional[List[str]] = None env: Optional[Dict[str, str]] = None access_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)