Support for requesting specific OAuth scopes #24
+5,652
−4
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.
Added support for requesting specific OAuth scopes in BrowserOAuthClientProvider.
Motivation and Context
Only specific scopes are necessary to request with most OAuth-protected MCP servers, thus always requesting all available permissions violates the principle of least privilege and makes it difficult to implement scope-specific authorization flows.
How Has This Been Tested?
Tested:
✓ should use default scope when no scopes provided
✓ should use default scope when empty scopes array provided
✓ should store and use custom scopes when provided
✓ should handle single scope correctly
✓ should preserve scope order
✓ should include scopes in client metadata
✓ should handle special characters in scopes
[mcp:auth] Redirecting to authorization URL in popup.
✓ should store scopes in state during authorization redirect
[test-prefix] Redirecting to authorization URL in popup.
✓ should preserve all provider options including scopes in state
✓ should work with old constructor calls (no scopes)
✓ should maintain existing functionality when scopes are added
✓ should handle undefined scopes gracefully
✓ should handle scopes with whitespace
✓ should clear scope-related state during clearStorage
✓ should reconstruct provider with correct scopes from stored state
✓ should handle many scopes
✓ should handle OAuth standard scopes
Results: 17 passed, 0 failed
All tests passed!
Breaking Changes
No. This new feature is backward-compatible and tested with original functionality. Existing code without the new scopes parameter continues to work unchanged, default behavior with the 'openid' scope, and all existing constructor options are preserved. If a user wants to implement this new feature, they will have to add their respective scopes (i.e. 'openid profile email')
Types of changes
Checklist
Additional context
Using use-mcp and need the ability to request specific scopes.