Skip to content

Commit 75b21f8

Browse files
committed
add fallback code
Signed-off-by: Anxhela Coba <acoba@redhat.com>
1 parent d0558bf commit 75b21f8

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

config/system.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ api:
5454
filesystem-tools:
5555
env_var: API_KEY # Environment variable containing the token/key
5656

57-
# Legacy authentication (fallback when mcp_headers.enabled is false)
57+
# Legacy authentication (fallback when mcp_headers is not configured or disabled)
5858
# Authentication via API_KEY environment variable only for MCP server
5959

6060
# Retry configuration for 429 Too Many Requests API errors

src/lightspeed_evaluation/core/api/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,16 @@ def _build_mcp_headers(self) -> dict[str, dict[str, str]]:
139139
mcp_headers[server_name] = {header_name: header_value}
140140

141141
if not mcp_headers:
142-
raise APIError(
143-
"MCP headers are enabled, but no valid server credentials were resolved. "
144-
"Check mcp_headers.servers and required environment variables."
145-
)
142+
# Fallback to API_KEY if MCP headers are enabled but no credentials found
143+
api_key = os.getenv("API_KEY")
144+
if not api_key:
145+
raise APIError(
146+
"MCP headers are enabled, but no valid server credentials were resolved "
147+
"and no API_KEY environment variable is set. Check mcp_headers.servers "
148+
"and required environment variables, or set API_KEY as fallback."
149+
)
150+
# Return empty dict to signal fallback to API_KEY authentication
151+
return {}
146152
return mcp_headers
147153

148154
# No MCP headers configured

0 commit comments

Comments
 (0)