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
This commit is contained in:
Krrish Dholakia 2025-10-04 18:34:47 -07:00
parent a49a19e784
commit 3700e5d760
3 changed files with 17 additions and 2 deletions

View file

@ -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,

View file

@ -22,4 +22,5 @@ mcp_servers:
transport: "http"
description: "My custom MCP server"
auth_type: "api_key"
auth_value: "abc123"
auth_value: "abc123"
static_headers: {"X-API-Key": "abc123"}

View file

@ -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)