1111import threading
1212import time
1313import webbrowser
14- from datetime import timedelta
1514from http .server import BaseHTTPRequestHandler , HTTPServer
1615from typing import Any
1716from urllib .parse import parse_qs , urlparse
1817
18+ import httpx
1919from mcp .client .auth import OAuthClientProvider , TokenStorage
2020from mcp .client .session import ClientSession
2121from mcp .client .sse import sse_client
22- from mcp .client .streamable_http import streamablehttp_client
22+ from mcp .client .streamable_http import streamable_http_client
2323from mcp .shared .auth import OAuthClientInformationFull , OAuthClientMetadata , OAuthToken
2424
2525
@@ -193,7 +193,7 @@ async def _default_redirect_handler(authorization_url: str) -> None:
193193 # Create OAuth authentication handler using the new interface
194194 # Use client_metadata_url to enable CIMD when the server supports it
195195 oauth_auth = OAuthClientProvider (
196- server_url = self .server_url ,
196+ server_url = self .server_url . replace ( "/mcp" , "" ) ,
197197 client_metadata = OAuthClientMetadata .model_validate (client_metadata_dict ),
198198 storage = InMemoryTokenStorage (),
199199 redirect_handler = _default_redirect_handler ,
@@ -212,12 +212,12 @@ async def _default_redirect_handler(authorization_url: str) -> None:
212212 await self ._run_session (read_stream , write_stream , None )
213213 else :
214214 print ("📡 Opening StreamableHTTP transport connection with auth..." )
215- async with streamablehttp_client (
216- url = self . server_url ,
217- auth = oauth_auth ,
218- timeout = timedelta ( seconds = 60 ) ,
219- ) as (read_stream , write_stream , get_session_id ):
220- await self ._run_session (read_stream , write_stream , get_session_id )
215+ async with httpx . AsyncClient ( auth = oauth_auth , follow_redirects = True ) as custom_client :
216+ async with streamable_http_client (
217+ url = self . server_url ,
218+ http_client = custom_client ,
219+ ) as (read_stream , write_stream , get_session_id ):
220+ await self ._run_session (read_stream , write_stream , get_session_id )
221221
222222 except Exception as e :
223223 print (f"❌ Failed to connect: { e } " )
0 commit comments