fix(mcp_server_manager.py): support static headers

This commit is contained in:
Krrish Dholakia
2025-10-25 13:30:04 -07:00
parent 86524fcaf5
commit 65ef9b2ee7
3 changed files with 30 additions and 4 deletions
@@ -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 = 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,
@@ -1098,12 +1104,16 @@ class MCPServerManager:
server_auth_header: Optional[Union[Dict[str, str], str]] = None
if 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 found
if 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,
+8
View File
@@ -19,3 +19,11 @@ vector_store_registry:
api_base: https://krris-mh44uf7y-eastus2.cognitiveservices.azure.com/
api_key: os.environ/AZURE_API_KEY
api_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"}
@@ -22,7 +22,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
@@ -40,4 +40,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)