Skip to content

fix: retry next endpoint on CORS error during auth server discovery #827

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

Merged

Conversation

xiaoyijun
Copy link
Contributor

Continue trying other discovery endpoints when CORS errors occur instead of failing immediately.

Motivation and Context

Authorization servers don't always allow CORS requests for all potential metadata discovery endpoints, especially for non-public information. The client tries multiple well-known endpoints, and CORS failures are common and expected. Previously, a CORS error on any endpoint would cause the entire discovery process to fail immediately, even though other endpoints might work.

How Has This Been Tested?

  • Unit test added
  • Tested implementation manually in MCP Inspector

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

Changed discoverAuthorizationServerMetadata to use continue instead of throwing when CORS errors occur, allowing the function to try all available discovery URLs before giving up.

@xiaoyijun xiaoyijun requested a review from a team as a code owner July 31, 2025 08:05
@xiaoyijun xiaoyijun requested a review from ochafik July 31, 2025 08:05
@xiaoyijun
Copy link
Contributor Author

Hi @pcarleton , I have a fix for CORS error handling in auth server discovery - could you take a look when you have a chance? Thanks! ❤️

@ochafik ochafik requested review from pcarleton and removed request for ochafik August 4, 2025 14:16
Copy link
Contributor

@pcarleton pcarleton left a comment

Choose a reason for hiding this comment

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

thanks for this!

@pcarleton pcarleton merged commit f657ead into modelcontextprotocol:main Aug 4, 2025
2 checks passed
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.

2 participants