Skip to content

Commit aad9cb7

Browse files
committed
Fix OAuth merge conflict issues
This commit resolves two critical issues that arose after merging upstream changes: 1. Export missing OAuth providers: Added ClientCredentialsProvider and TokenExchangeProvider to mcp.client.auth module exports. These providers are essential for the client credentials and token exchange grant types that were added in the OAuth support fork. 2. Add redirect_uris validation: Implemented validation to ensure redirect_uris is provided when authorization_code is in the grant_types. This field is required for the authorization code flow but optional for client_credentials and token_exchange flows which don't use redirect URIs. These fixes ensure all tests pass while maintaining the integrity of the OAuth extensions including client credentials and token exchange grant types.
1 parent 7104629 commit aad9cb7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/mcp/client/auth/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
"""
66

77
from mcp.client.auth.oauth2 import (
8+
ClientCredentialsProvider,
89
OAuthClientProvider,
910
OAuthFlowError,
1011
OAuthRegistrationError,
1112
OAuthTokenError,
1213
PKCEParameters,
14+
TokenExchangeProvider,
1315
TokenStorage,
1416
)
1517

1618
__all__ = [
19+
"ClientCredentialsProvider",
1720
"OAuthClientProvider",
1821
"OAuthFlowError",
1922
"OAuthRegistrationError",
2023
"OAuthTokenError",
2124
"PKCEParameters",
25+
"TokenExchangeProvider",
2226
"TokenStorage",
2327
]

src/mcp/server/auth/handlers/register.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,19 @@ async def handle(self, request: Request) -> Response:
6868
),
6969
status_code=400,
7070
)
71+
72+
# Validate redirect_uris is provided for authorization_code grant type
7173
grant_types_set: set[str] = set(client_metadata.grant_types)
74+
if "authorization_code" in grant_types_set and (
75+
client_metadata.redirect_uris is None or len(client_metadata.redirect_uris) == 0
76+
):
77+
return PydanticJSONResponse(
78+
content=RegistrationErrorResponse(
79+
error="invalid_client_metadata",
80+
error_description="redirect_uris: Field required",
81+
),
82+
status_code=400,
83+
)
7284
required_sets = [
7385
{"authorization_code", "refresh_token"},
7486
{"client_credentials"},

0 commit comments

Comments
 (0)