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.
This PR implements authorization support as per RFC 9728 (#686).
It introduces robust token generation and validation methods, fully aligned with the new MCP authorization specification.
The changes include:
Implementation of token generation using JWT with proper encoding and expiration.
Validation of JWT tokens with issuer and audience verification.
Error handling for expired or invalid tokens.
Unit tests for token generation, validation, claim extraction, and expiration scenarios.
Motivation and Context
The primary motivation for this change is to ensure MCP Python SDK’s compliance with RFC 9728, the new authorization specification.
By adding proper token management, it
*Enhances security by leveraging JWT-based authentication.
*Aligns with the authorization standards outlined in the MCP specification.
*Provides a robust framework for secure client-server communication.
*This change addresses Issue #686 by implementing the authorization flow, including token creation, validation, and handling edge cases like expiration and invalid claims.
How Has This Been Tested?
*All unit tests have been executed and passed successfully, covering the following scenarios:
*Generating a valid token and verifying its claims.
*Detecting an expired token.
*Extracting a specific claim from a valid token.
*Handling a token with invalid claims.
Handling a completely invalid or malformed token.
Breaking Changes
None.
The introduced features are additive and do not affect existing functionality.
Types of changes
Checklist
Additional context
This feature aligns the MCP Python SDK with the latest authorization standards as outlined in RFC 9728.
It also improves security practices by ensuring token validity and proper claim extraction in a structured and standardized way.