fix(oauth): handle rate limiting in resource auto-detection #277
+778
−85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When
autoDetectResource()encounters a 429 rate limit response, retry with appropriate backoff instead of immediately falling back to the server URL.Related #271
Problem
Some OAuth providers (e.g., Runlayer/Anysphere) aggressively rate limit preflight requests, causing resource auto-detection to fail during OAuth login flows. This results in the
resourceparameter being set to the server URL instead of the correct value from Protected Resource Metadata, which can cause authentication failures.Solution
Rate Limit Handling (
internal/oauth/config.go)parseRateLimitWait()helper to extract wait duration from:Retry-Afterheader (seconds or HTTP-date per RFC 7231)reset_atfield (Unix timestamp)autoDetectResource()with retry loop:Test Infrastructure (
tests/oauthserver/)ErrorMode:MCPRateLimitCount- return 429 N times before real responseMCPRateLimitRetryAfter- Retry-After header valueMCPRateLimitUseResetAt- use JSON body with reset_at instead/.well-known/oauth-protected-resourceendpoint (RFC 9728)MCPURLandProtectedResourceMetadataURLtoServerResultResetRateLimitCounter()helper for test isolationTest plan
parseRateLimitWait()(7 test cases)autoDetectResource()rate limit handling (4 test cases)🤖 Generated with Claude Code