add auth client sse (#760)

This commit is contained in:
ihrpr 2025-05-20 15:21:14 +01:00 • committed by GitHub
commit 43ded92633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,12 +26,20 @@ async def sse_client(
headers: dict[str, Any] | None = None,
timeout: float = 5,
sse_read_timeout: float = 60 * 5,
auth: httpx.Auth | None = None,
):
"""
Client transport for SSE.
`sse_read_timeout` determines how long (in seconds) the client will wait for a new
event before disconnecting. All other HTTP operations are controlled by `timeout`.
Args:
url: The SSE endpoint URL.
headers: Optional headers to include in requests.
timeout: HTTP timeout for regular operations.
sse_read_timeout: Timeout for SSE read operations.
auth: Optional HTTPX authentication handler.
"""
read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]
read_stream_writer: MemoryObjectSendStream[SessionMessage | Exception]
@ -45,7 +53,7 @@ async def sse_client(
async with anyio.create_task_group() as tg:
try:
logger.info(f"Connecting to SSE endpoint: {remove_request_params(url)}")
async with create_mcp_http_client(headers=headers) as client:
async with create_mcp_http_client(headers=headers, auth=auth) as client:
async with aconnect_sse(
client,
"GET",