feat: OAuth 2.1 Authentication Support and Transport Layer Optimization #129
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
This PR adds comprehensive OAuth 2.1 authentication support to the MCP framework and optimizes the transport layer implementation by eliminating code duplication and improving type safety.
Features Added
OAuth 2.1 Authentication (RFC Compliant)
/.well-known/oauth-protected-resource)Transport Layer Optimizations
src/transports/utils/auth-handler.ts)src/transports/utils/oauth-metadata.ts)as anycasts by adding public getters to OAuthAuthProviderCode Quality Improvements
Testing
Documentation
docs/OAUTH.md)SECURITY_AUDIT.md)PERFORMANCE_REPORT.md)OAUTH_IMPLEMENTATION_PLAN.md)Integration Examples
Included working examples with Auth0, Okta, AWS Cognito, and Azure AD/Entra ID:
Architectural Compliance
Breaking Changes
None. All public APIs remain unchanged.
Migration Guide
Existing code continues to work without changes. OAuth is opt-in:
Performance Impact
Files Modified/Created
Modified:
src/auth/providers/oauth.ts(+8 lines - public getters)src/transports/http/server.ts(-74 lines - optimizations)src/transports/sse/server.ts(-54 lines - optimizations)CLAUDE.md(OAuth documentation)README.md(OAuth examples)Created:
src/auth/providers/oauth.ts(OAuth provider)src/auth/validators/jwt-validator.ts(JWT validation)src/auth/validators/introspection-validator.ts(Token introspection)src/auth/metadata/protected-resource.ts(RFC 9728 metadata)src/transports/utils/auth-handler.ts(Shared authentication)src/transports/utils/oauth-metadata.ts(OAuth metadata utility)docs/OAUTH.md(Integration guide)examples/oauth-server/(Working example)tests/auth/(OAuth test suite)tests/transports/*-oauth.test.ts(Transport OAuth tests)Related Issues
Implements OAuth 2.1 authentication as requested in the MCP specification.
Generated with Claude Code