Support custom httpx client creation (#752)

This commit is contained in:
Nick Cooper 2025-05-23 05:55:01 -07:00 • committed by GitHub
commit 10cf0f78a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,7 @@ from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStre
from httpx_sse import aconnect_sse
import mcp.types as types
from mcp.shared._httpx_utils import create_mcp_http_client
from mcp.shared._httpx_utils import McpHttpClientFactory, create_mcp_http_client
from mcp.shared.message import SessionMessage
logger = logging.getLogger(__name__)
@ -26,6 +26,7 @@ async def sse_client(
headers: dict[str, Any] | None = None,
timeout: float = 5,
sse_read_timeout: float = 60 * 5,
httpx_client_factory: McpHttpClientFactory = create_mcp_http_client,
auth: httpx.Auth | None = None,
):
"""
@ -53,7 +54,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, auth=auth) as client:
async with httpx_client_factory(headers=headers, auth=auth) as client:
async with aconnect_sse(
client,
"GET",