Skip to content

Commit d73055c

Browse files
authored
[MCP] Fix the bearer token authorization header (#4846)
`http_config.auth_header` automatically added `Bearer `. By adding it ourselves, we were sending `Bearer Bearer <token>`. I confirmed that the GitHub MCP initialization 400s before and works now. I also optimized the oauth flow to not check the keyring if you explicitly pass in a bearer token.
1 parent 7e3a272 commit d73055c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

codex-rs/rmcp-client/src/rmcp_client.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ impl RmcpClient {
120120
url: &str,
121121
bearer_token: Option<String>,
122122
) -> Result<Self> {
123-
let initial_tokens = match load_oauth_tokens(server_name, url) {
124-
Ok(tokens) => tokens,
125-
Err(err) => {
126-
warn!("failed to read tokens for server `{server_name}`: {err}");
127-
None
128-
}
123+
let initial_oauth_tokens = match bearer_token {
124+
Some(_) => None,
125+
None => match load_oauth_tokens(server_name, url) {
126+
Ok(tokens) => tokens,
127+
Err(err) => {
128+
warn!("failed to read tokens for server `{server_name}`: {err}");
129+
None
130+
}
131+
},
129132
};
130-
let transport = if let Some(initial_tokens) = initial_tokens.clone() {
133+
let transport = if let Some(initial_tokens) = initial_oauth_tokens.clone() {
131134
let (transport, oauth_persistor) =
132135
create_oauth_transport_and_runtime(server_name, url, initial_tokens).await?;
133136
PendingTransport::StreamableHttpWithOAuth {
@@ -137,7 +140,7 @@ impl RmcpClient {
137140
} else {
138141
let mut http_config = StreamableHttpClientTransportConfig::with_uri(url.to_string());
139142
if let Some(bearer_token) = bearer_token {
140-
http_config = http_config.auth_header(format!("Bearer {bearer_token}"));
143+
http_config = http_config.auth_header(bearer_token);
141144
}
142145

143146
let transport = StreamableHttpClientTransport::from_config(http_config);

0 commit comments

Comments
 (0)