|
80 | 80 | ;; HTTP transport (SSE or Streamable, inferred from URL) |
81 | 81 | (let [url (replace-env-vars (:url server-config)) |
82 | 82 | sse? (string/includes? url "/sse") |
| 83 | + config-headers (:headers server-config) |
83 | 84 | customizer (reify McpSyncHttpClientRequestCustomizer |
84 | 85 | (customize [_this builder _method _endpoint _body _context] |
| 86 | + ;; First apply configured static headers |
| 87 | + (doseq [[header-name header-value] config-headers] |
| 88 | + (.header builder (name header-name) (replace-env-vars (str header-value)))) |
| 89 | + ;; Then apply OAuth token if present (can override static Authorization) |
85 | 90 | (when-let [access-token (get-in db [:mcp-auth server-name :access-token])] |
86 | 91 | (.header builder "Authorization" (str "Bearer " access-token)))))] |
87 | 92 | (if sse? |
|
262 | 267 | workspaces (:workspace-folders @db*) |
263 | 268 | server-config (get-in config [:mcpServers name]) |
264 | 269 | url (:url server-config) |
| 270 | + ;; Skip OAuth entirely if Authorization header is configured |
| 271 | + has-static-auth? (some-> server-config :headers :Authorization some?) |
265 | 272 | mcp-auth (get-in @db* [:mcp-auth name]) |
266 | 273 | has-token? (some? (:access-token mcp-auth)) |
267 | 274 | token-expired? (token-expired? (:expires-at mcp-auth)) |
268 | 275 | ;; Try to refresh if token exists but is expired |
269 | 276 | refresh-succeeded? (when (and has-token? token-expired?) |
270 | 277 | (try-refresh-token! name db* url metrics)) |
271 | | - ;; Only get oauth-info if we don't have a token or refresh failed |
272 | | - needs-oauth? (or (not has-token?) |
273 | | - (and token-expired? (not refresh-succeeded?))) |
| 278 | + ;; Only get oauth-info if we don't have a token or refresh failed, and no static auth header |
| 279 | + needs-oauth? (and (not has-static-auth?) |
| 280 | + (or (not has-token?) |
| 281 | + (and token-expired? (not refresh-succeeded?)))) |
274 | 282 | oauth-info (when (and url needs-oauth?) |
275 | 283 | (oauth/oauth-info (replace-env-vars url)))] |
276 | 284 | (if oauth-info |
|
0 commit comments