Skip to content

fix: perform auth server metadata discovery fallbacks on any 4xx #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

LucaButBoring
Copy link
Contributor

Updates the OAuth authorization server metadata discovery fallback behavior to attempt a fallback on any 4XX, rather than only 404s.

Motivation and Context

During auth server metadata discovery, the client SDK attempts to query the four supported metadata endpoints sequentially (#1061). However, it only falls back from one to another on 404 responses (source). This is stricter than the specification requires, and happens to break compatibility with Cognito, which returns a 400 at any endpoints it doesn't support (example).

Given that the spec doesn't limit fallback conditions to 404s, I think it should be changed to any 4XX. Arguably, it should fall back on 5XX responses as well, but I'm limiting this to 4XX responses to avoid the possibility of a load-sensitive 5XX being quadrupled in scale by fallback behaviors.

How Has This Been Tested?

Spot tested with Cognito, added a unit test.

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Closes #1192

@pcarleton pcarleton merged commit 35777b9 into modelcontextprotocol:main Jul 24, 2025
10 checks passed
@LucaButBoring LucaButBoring deleted the fix/as-metadata-fallback-conditions branch July 25, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auth server metadata fallbacks abort on non-404 failures
2 participants