11import re
22from urllib .parse import urljoin , urlparse
33
4- from httpx import Request , Response
54from pydantic import AnyUrl , ValidationError
65
76from mcp .client .auth import OAuthRegistrationError , OAuthTokenError
87from mcp .client .streamable_http import MCP_PROTOCOL_VERSION
8+ from mcp .shared ._httpx import httpx
99from mcp .shared .auth import (
1010 OAuthClientInformationFull ,
1111 OAuthClientMetadata ,
1616from mcp .types import LATEST_PROTOCOL_VERSION
1717
1818
19- def extract_field_from_www_auth (response : Response , field_name : str ) -> str | None :
19+ def extract_field_from_www_auth (response : httpx . Response , field_name : str ) -> str | None :
2020 """Extract field from WWW-Authenticate header.
2121
2222 Returns:
@@ -37,7 +37,7 @@ def extract_field_from_www_auth(response: Response, field_name: str) -> str | No
3737 return None
3838
3939
40- def extract_scope_from_www_auth (response : Response ) -> str | None :
40+ def extract_scope_from_www_auth (response : httpx . Response ) -> str | None :
4141 """Extract scope parameter from WWW-Authenticate header as per RFC 6750.
4242
4343 Returns:
@@ -46,7 +46,7 @@ def extract_scope_from_www_auth(response: Response) -> str | None:
4646 return extract_field_from_www_auth (response , "scope" )
4747
4848
49- def extract_resource_metadata_from_www_auth (response : Response ) -> str | None :
49+ def extract_resource_metadata_from_www_auth (response : httpx . Response ) -> str | None :
5050 """Extract protected resource metadata URL from WWW-Authenticate header as per RFC 9728.
5151
5252 Returns:
@@ -175,7 +175,7 @@ def build_oauth_authorization_server_metadata_discovery_urls(auth_server_url: st
175175
176176
177177async def handle_protected_resource_response (
178- response : Response ,
178+ response : httpx . Response ,
179179) -> ProtectedResourceMetadata | None :
180180 """Handle protected resource metadata discovery response.
181181
@@ -198,7 +198,7 @@ async def handle_protected_resource_response(
198198 return None
199199
200200
201- async def handle_auth_metadata_response (response : Response ) -> tuple [bool , OAuthMetadata | None ]:
201+ async def handle_auth_metadata_response (response : httpx . Response ) -> tuple [bool , OAuthMetadata | None ]:
202202 if response .status_code == 200 :
203203 try :
204204 content = await response .aread ()
@@ -211,13 +211,13 @@ async def handle_auth_metadata_response(response: Response) -> tuple[bool, OAuth
211211 return True , None
212212
213213
214- def create_oauth_metadata_request (url : str ) -> Request :
215- return Request ("GET" , url , headers = {MCP_PROTOCOL_VERSION : LATEST_PROTOCOL_VERSION })
214+ def create_oauth_metadata_request (url : str ) -> httpx . Request :
215+ return httpx . Request ("GET" , url , headers = {MCP_PROTOCOL_VERSION : LATEST_PROTOCOL_VERSION })
216216
217217
218218def create_client_registration_request (
219219 auth_server_metadata : OAuthMetadata | None , client_metadata : OAuthClientMetadata , auth_base_url : str
220- ) -> Request :
220+ ) -> httpx . Request :
221221 """Build a client registration request."""
222222
223223 if auth_server_metadata and auth_server_metadata .registration_endpoint :
@@ -227,10 +227,10 @@ def create_client_registration_request(
227227
228228 registration_data = client_metadata .model_dump (by_alias = True , mode = "json" , exclude_none = True )
229229
230- return Request ("POST" , registration_url , json = registration_data , headers = {"Content-Type" : "application/json" })
230+ return httpx . Request ("POST" , registration_url , json = registration_data , headers = {"Content-Type" : "application/json" })
231231
232232
233- async def handle_registration_response (response : Response ) -> OAuthClientInformationFull :
233+ async def handle_registration_response (response : httpx . Response ) -> OAuthClientInformationFull :
234234 """Handle registration response."""
235235 if response .status_code not in (200 , 201 ):
236236 await response .aread ()
@@ -316,7 +316,7 @@ def create_client_info_from_metadata_url(
316316
317317
318318async def handle_token_response_scopes (
319- response : Response ,
319+ response : httpx . Response ,
320320) -> OAuthToken :
321321 """Parse and validate a token response.
322322
0 commit comments