From 069dc2895f7099efbcc20e60e3a8f5c072cb7c4b Mon Sep 17 00:00:00 2001 From: pakrym-oai Date: Thu, 8 Jan 2026 11:40:08 -0800 Subject: [PATCH] auto fail oauth loading in debug --- codex-rs/rmcp-client/src/oauth.rs | 16 ++++++++++++++++ docs/config.md | 2 ++ 2 files changed, 18 insertions(+) diff --git a/codex-rs/rmcp-client/src/oauth.rs b/codex-rs/rmcp-client/src/oauth.rs index f8eafaf23e..37aac64d1d 100644 --- a/codex-rs/rmcp-client/src/oauth.rs +++ b/codex-rs/rmcp-client/src/oauth.rs @@ -50,6 +50,7 @@ use tokio::sync::Mutex; use crate::find_codex_home::find_codex_home; const KEYRING_SERVICE: &str = "Codex MCP Credentials"; +const MCP_OAUTH_KEYRING_DEBUG_ALLOW_ENV_VAR: &str = "CODEX_MCP_OAUTH_KEYRING_DEBUG_ALLOW"; const REFRESH_SKEW_MILLIS: u64 = 30_000; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] @@ -95,6 +96,15 @@ pub(crate) fn load_oauth_tokens( url: &str, store_mode: OAuthCredentialsStoreMode, ) -> Result> { + if keyring_load_disabled_in_debug() { + if store_mode == OAuthCredentialsStoreMode::Keyring { + return Err(anyhow::anyhow!( + "MCP OAuth keyring access is disabled in debug builds on macOS; set {MCP_OAUTH_KEYRING_DEBUG_ALLOW_ENV_VAR}=1 to enable." + )); + } + return load_oauth_tokens_from_file(server_name, url); + } + let keyring_store = DefaultKeyringStore; match store_mode { OAuthCredentialsStoreMode::Auto => { @@ -116,6 +126,12 @@ pub(crate) fn has_oauth_tokens( Ok(load_oauth_tokens(server_name, url, store_mode)?.is_some()) } +fn keyring_load_disabled_in_debug() -> bool { + cfg!(debug_assertions) + && cfg!(target_os = "macos") + && std::env::var_os(MCP_OAUTH_KEYRING_DEBUG_ALLOW_ENV_VAR).is_none() +} + fn refresh_expires_in_from_timestamp(tokens: &mut StoredOAuthTokens) { let Some(expires_at) = tokens.expires_at else { return; diff --git a/docs/config.md b/docs/config.md index 2b64253d30..c6e9e9257e 100644 --- a/docs/config.md +++ b/docs/config.md @@ -12,6 +12,8 @@ Codex can connect to MCP servers configured in `~/.codex/config.toml`. See the c - https://developers.openai.com/codex/config-reference +On macOS debug builds, Codex skips reading MCP OAuth tokens from the system keychain to avoid repeated access prompts. Set `CODEX_MCP_OAUTH_KEYRING_DEBUG_ALLOW=1` to allow keychain reads when debugging. + ## Notify Codex can run a notification hook when the agent finishes a turn. See the configuration reference for the latest notification settings: