[MCP] When MCP auth expires, prompt the user to log in again. (#5300)
Similar to https://github.com/openai/codex/pull/5193 but catches a case where the user _has_ authenticated but the auth expired or was revoked. Before: <img width="2976" height="632" alt="CleanShot 2025-10-17 at 14 28 11" src="https://github.com/user-attachments/assets/7c1bd11d-c075-46cb-9298-48891eaa77fe" /> After: <img width="591" height="283" alt="image" src="https://github.com/user-attachments/assets/fc14e08c-1a33-4077-8757-ff4ed3f00f8f" />
This commit is contained in:
@@ -426,13 +426,16 @@ impl Session {
|
|||||||
// Surface individual client start-up failures to the user.
|
// Surface individual client start-up failures to the user.
|
||||||
if !failed_clients.is_empty() {
|
if !failed_clients.is_empty() {
|
||||||
for (server_name, err) in failed_clients {
|
for (server_name, err) in failed_clients {
|
||||||
|
let auth_status = auth_statuses.get(&server_name);
|
||||||
|
let requires_login = match auth_status {
|
||||||
|
Some(McpAuthStatus::NotLoggedIn) => true,
|
||||||
|
Some(McpAuthStatus::OAuth) => is_mcp_client_auth_required_error(&err),
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
let log_message =
|
let log_message =
|
||||||
format!("MCP client for `{server_name}` failed to start: {err:#}");
|
format!("MCP client for `{server_name}` failed to start: {err:#}");
|
||||||
error!("{log_message}");
|
error!("{log_message}");
|
||||||
let display_message = if matches!(
|
let display_message = if requires_login {
|
||||||
auth_statuses.get(&server_name),
|
|
||||||
Some(McpAuthStatus::NotLoggedIn)
|
|
||||||
) {
|
|
||||||
format!(
|
format!(
|
||||||
"The {server_name} MCP server is not logged in. Run `codex mcp login {server_name}` to log in."
|
"The {server_name} MCP server is not logged in. Run `codex mcp login {server_name}` to log in."
|
||||||
)
|
)
|
||||||
@@ -2524,6 +2527,11 @@ pub(crate) async fn exit_review_mode(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_mcp_client_auth_required_error(error: &anyhow::Error) -> bool {
|
||||||
|
// StreamableHttpError::AuthRequired from the MCP SDK.
|
||||||
|
error.to_string().contains("Auth required")
|
||||||
|
}
|
||||||
|
|
||||||
use crate::executor::errors::ExecError;
|
use crate::executor::errors::ExecError;
|
||||||
use crate::executor::linkers::PreparedExec;
|
use crate::executor::linkers::PreparedExec;
|
||||||
use crate::tools::context::ApplyPatchCommandContext;
|
use crate::tools::context::ApplyPatchCommandContext;
|
||||||
|
|||||||
Reference in New Issue
Block a user