mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
This adds two new config fields to streamable http mcp servers: `http_headers`: a map of key to value `env_http_headers` a map of key to env var which will be resolved at request time All headers will be passed to all MCP requests to that server just like authorization headers. There is a test ensuring that headers are not passed to other servers. Fixes #5180
63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use anyhow::Result;
|
|
use codex_protocol::protocol::McpAuthStatus;
|
|
use codex_rmcp_client::OAuthCredentialsStoreMode;
|
|
use codex_rmcp_client::determine_streamable_http_auth_status;
|
|
use futures::future::join_all;
|
|
use tracing::warn;
|
|
|
|
use crate::config_types::McpServerConfig;
|
|
use crate::config_types::McpServerTransportConfig;
|
|
|
|
pub async fn compute_auth_statuses<'a, I>(
|
|
servers: I,
|
|
store_mode: OAuthCredentialsStoreMode,
|
|
) -> HashMap<String, McpAuthStatus>
|
|
where
|
|
I: IntoIterator<Item = (&'a String, &'a McpServerConfig)>,
|
|
{
|
|
let futures = servers.into_iter().map(|(name, config)| {
|
|
let name = name.clone();
|
|
let config = config.clone();
|
|
async move {
|
|
let status = match compute_auth_status(&name, &config, store_mode).await {
|
|
Ok(status) => status,
|
|
Err(error) => {
|
|
warn!("failed to determine auth status for MCP server `{name}`: {error:?}");
|
|
McpAuthStatus::Unsupported
|
|
}
|
|
};
|
|
(name, status)
|
|
}
|
|
});
|
|
|
|
join_all(futures).await.into_iter().collect()
|
|
}
|
|
|
|
async fn compute_auth_status(
|
|
server_name: &str,
|
|
config: &McpServerConfig,
|
|
store_mode: OAuthCredentialsStoreMode,
|
|
) -> Result<McpAuthStatus> {
|
|
match &config.transport {
|
|
McpServerTransportConfig::Stdio { .. } => Ok(McpAuthStatus::Unsupported),
|
|
McpServerTransportConfig::StreamableHttp {
|
|
url,
|
|
bearer_token_env_var,
|
|
http_headers,
|
|
env_http_headers,
|
|
} => {
|
|
determine_streamable_http_auth_status(
|
|
server_name,
|
|
url,
|
|
bearer_token_env_var.as_deref(),
|
|
http_headers.clone(),
|
|
env_http_headers.clone(),
|
|
store_mode,
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
}
|