Skip to content

Commit fcc2d59

Browse files
authored
fix: include API key in CORS proxy requests for MCP connections (#21193)
* fix: include API key in CORS proxy requests for MCP connections When llama-server is started with --api-key-file and --webui-mcp-proxy, the /cors-proxy endpoint requires authentication. The WebUI was not including the Authorization header in proxy requests, causing MCP connections to fail with 401. Inject getAuthHeaders() into requestInit when useProxy is true so the proxy request carries the Bearer token alongside the forwarded target headers. Fixes #21167 * fix: simplify headers assignment based on reviewer suggestion Apply buildProxiedHeaders only when useProxy is true, pass headers directly to the transport otherwise.
1 parent 4453e77 commit fcc2d59

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tools/server/webui/src/lib/services/mcp.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type {
4242
import {
4343
buildProxiedUrl,
4444
buildProxiedHeaders,
45+
getAuthHeaders,
4546
throwIfAborted,
4647
isAbortError,
4748
createBase64DataUrl
@@ -124,7 +125,14 @@ export class MCPService {
124125
const requestInit: RequestInit = {};
125126

126127
if (config.headers) {
127-
requestInit.headers = buildProxiedHeaders(config.headers);
128+
requestInit.headers = config.useProxy ? buildProxiedHeaders(config.headers) : config.headers;
129+
}
130+
131+
if (useProxy) {
132+
requestInit.headers = {
133+
...getAuthHeaders(),
134+
...(requestInit.headers as Record<string, string>)
135+
};
128136
}
129137

130138
if (config.credentials) {

0 commit comments

Comments
 (0)