Skip to content

use scopes_supported for OAuth when present on MCP servers#14419

Merged
jgershen-oai merged 3 commits intomainfrom
codex/jgershen/support-auth-scopes
Mar 12, 2026
Merged

use scopes_supported for OAuth when present on MCP servers#14419
jgershen-oai merged 3 commits intomainfrom
codex/jgershen/support-auth-scopes

Conversation

@jgershen-oai
Copy link
Copy Markdown
Collaborator

Fixes #8889.

Summary

  • Discover and use advertised MCP OAuth scopes_supported when no explicit or configured scopes are present.
  • Apply the same scope precedence across mcp add, mcp login, skill dependency auto-login, and app-server MCP OAuth login.
  • Keep discovered scopes ephemeral and non-persistent.
  • Retry once without scopes for CLI and skill auto-login flows if the OAuth provider rejects discovered scopes.

Motivation

Some MCP servers advertise the scopes they expect clients to request during OAuth, but Codex was ignoring that metadata and typically starting OAuth with no scopes unless the user manually passed --scopes or configured server.scopes.

That made compliant MCP servers harder to use out of the box and is the behavior described in #8889.

This change also brings our behavior in line with the MCP authorization spec's scope selection guidance:
https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#scope-selection-strategy

Behavior

Scope selection now follows this order everywhere:

  1. Explicit request scopes / CLI --scopes
  2. Configured server.scopes
  3. Discovered scopes_supported
  4. Legacy empty-scope behavior

Compatibility notes:

  • Existing working setups keep the same behavior because explicit and configured scopes still win.
  • Discovered scopes are never written back into config or token storage.
  • If discovery is missing, malformed, or empty, behavior falls back to the previous empty-scope path.
  • App-server login gets the same precedence rules, but does not add a transparent retry path in this change.

Implementation

  • Extend streamable HTTP OAuth discovery to parse and normalize scopes_supported.
  • Add a shared MCP scope resolver in core so all login entrypoints use the same precedence rules.
  • Preserve provider callback errors from the OAuth flow so CLI/skill flows can safely distinguish provider rejections from other failures.
  • Reuse discovered scopes from the existing OAuth support check where possible instead of persisting new config.
Discover and use advertised MCP OAuth scopes_supported when no explicit or configured scopes are specified. This also brings behavior in line with https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#scope-selection-strategy.
@jgershen-oai jgershen-oai requested a review from gpeal March 12, 2026 02:26
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@jgershen-oai
Copy link
Copy Markdown
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

}

#[allow(clippy::too_many_arguments)]
async fn perform_oauth_login_with_legacy_retry(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name legacy retry is pretty unclear here. Should it be perform_oauth_login_retry_without_scopes or something? Why is it necessary to have that fallback? Docs would be helpful, I think

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep the fallback to no-scope auth since that's how it works today, and I don't want this to be a breaking change for anyone. Good call on the name; added some docs

@jgershen-oai jgershen-oai merged commit 3e96c86 into main Mar 12, 2026
32 checks passed
@jgershen-oai jgershen-oai deleted the codex/jgershen/support-auth-scopes branch March 12, 2026 18:57
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants