Add per-login MCP OAuth client registration selection (#38052)

## What changed

- Add `--oauth-client-registration` with `auto` and `dcr` choices to `codex mcp add` and `codex mcp login`.
- Add the equivalent optional `clientRegistration` field to `mcpServer/oauth/login` and the generated protocol schemas.
- Keep automatic dynamic client registration as the default, prefer a configured OAuth client ID when present, and apply the selection only to the current login without persisting it in MCP configuration.

## Testing

- Cover dynamic registration and configured-client OAuth flows through the app server.
- Verify the CLI does not persist the per-login registration choice.

GitOrigin-RevId: 653a4a1054ff43c2c5d52ae863b6a96d21692a53
This commit is contained in:
stevenlee-oai authored and copyberry committed 2026-08-11 18:35:03 +00:00
1 parent 965b9f263a
commit 6dc3ac8721
22 files changed
+407 -65

No files matched your search

@@ -0,0 +1,40 @@
use std::sync::Arc;
use anyhow::Result;
use rmcp::transport::AuthorizationManager;
use rmcp::transport::AuthorizationRequest;
use rmcp::transport::auth::OAuthHttpClient;
use rmcp::transport::auth::OAuthState;
/// OAuth client-registration strategy for one interactive HTTP MCP login.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum McpOAuthClientRegistration {
/// Preserve the current automatic Dynamic Client Registration flow.
#[default]
Auto,
/// Require the authorization server's Dynamic Client Registration endpoint.
Dcr,
}
pub(crate) async fn start_authorization(
server_url: &str,
http_client: Arc<dyn OAuthHttpClient>,
scopes: &[&str],
redirect_uri: &str,
client_registration: McpOAuthClientRegistration,
) -> Result<OAuthState> {
let request = match client_registration {
McpOAuthClientRegistration::Auto | McpOAuthClientRegistration::Dcr => {
AuthorizationRequest::new(redirect_uri)
.with_scopes(scopes.iter().copied())
.with_client_name("Codex")
}
};
let mut auth_manager =
AuthorizationManager::new_with_oauth_http_client(server_url, http_client).await?;
auth_manager.set_allow_missing_issuer(true);
let mut oauth_state = OAuthState::Unauthorized(auth_manager);
oauth_state.start_authorization(request).await?;
Ok(oauth_state)
}