1919import httpx
2020from pydantic import BaseModel , Field , ValidationError
2121
22- from mcp .client .auth import OAuthFlowError , OAuthTokenError
22+ from mcp .client .auth . exceptions import OAuthFlowError , OAuthRegistrationError , OAuthTokenError
2323from mcp .client .auth .utils import (
2424 build_oauth_authorization_server_metadata_discovery_urls ,
2525 build_protected_resource_metadata_discovery_urls ,
@@ -193,7 +193,7 @@ def prepare_token_auth(
193193
194194 auth_method = self .client_info .token_endpoint_auth_method
195195
196- if auth_method == "client_secret_basic" and self .client_info .client_secret :
196+ if auth_method == "client_secret_basic" and self .client_info .client_id and self . client_info . client_secret :
197197 # URL-encode client ID and secret per RFC 6749 Section 2.3.1
198198 encoded_id = quote (self .client_info .client_id , safe = "" )
199199 encoded_secret = quote (self .client_info .client_secret , safe = "" )
@@ -426,7 +426,7 @@ async def _refresh_token(self) -> httpx.Request:
426426 if not self .context .current_tokens or not self .context .current_tokens .refresh_token :
427427 raise OAuthTokenError ("No refresh token available" ) # pragma: no cover
428428
429- if not self .context .client_info :
429+ if not self .context .client_info or not self . context . client_info . client_id :
430430 raise OAuthTokenError ("No client info available" ) # pragma: no cover
431431
432432 if self .context .oauth_metadata and self .context .oauth_metadata .token_endpoint :
@@ -435,7 +435,7 @@ async def _refresh_token(self) -> httpx.Request:
435435 auth_base_url = self .context .get_authorization_base_url (self .context .server_url )
436436 token_url = urljoin (auth_base_url , "/token" )
437437
438- refresh_data = {
438+ refresh_data : dict [ str , str ] = {
439439 "grant_type" : "refresh_token" ,
440440 "refresh_token" : self .context .current_tokens .refresh_token ,
441441 "client_id" : self .context .client_info .client_id ,
0 commit comments