Skip to content

Commit 103431f

Browse files
committed
Do not try to oauth remote mcp servers if they have Authorization header.
1 parent 5e10b7e commit 103431f

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ ECA Agent Guide (AGENTS.md)
2727
- Tests:
2828
- Use `clojure.test` + `nubank/matcher-combinators`; keep tests deterministic.
2929
- Put shared test helpers under `test/eca/test_helper.clj`.
30+
- Use java class typing to avoid GraalVM reflection issues

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Do not try to oauth remote mcp servers if they have Authorization header.
6+
57
## 0.97.1
68

79
- Fix regression in last release MCPs not being started properly.

src/eca/features/tools/mcp.clj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@
8080
;; HTTP transport (SSE or Streamable, inferred from URL)
8181
(let [url (replace-env-vars (:url server-config))
8282
sse? (string/includes? url "/sse")
83+
config-headers (:headers server-config)
8384
customizer (reify McpSyncHttpClientRequestCustomizer
8485
(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)
8590
(when-let [access-token (get-in db [:mcp-auth server-name :access-token])]
8691
(.header builder "Authorization" (str "Bearer " access-token)))))]
8792
(if sse?
@@ -262,15 +267,18 @@
262267
workspaces (:workspace-folders @db*)
263268
server-config (get-in config [:mcpServers name])
264269
url (:url server-config)
270+
;; Skip OAuth entirely if Authorization header is configured
271+
has-static-auth? (some-> server-config :headers :Authorization some?)
265272
mcp-auth (get-in @db* [:mcp-auth name])
266273
has-token? (some? (:access-token mcp-auth))
267274
token-expired? (token-expired? (:expires-at mcp-auth))
268275
;; Try to refresh if token exists but is expired
269276
refresh-succeeded? (when (and has-token? token-expired?)
270277
(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?))))
274282
oauth-info (when (and url needs-oauth?)
275283
(oauth/oauth-info (replace-env-vars url)))]
276284
(if oauth-info

0 commit comments

Comments
 (0)