Introduce a function to create a standard AsyncClient with options (#655)
Some checks failed
Main branch checks / checks (push) Has been cancelled
Some checks failed
Main branch checks / checks (push) Has been cancelled
This commit is contained in:
parent
72003d9cc0
commit
ed25167fa5
2 changed files with 95 additions and 8 deletions
|
|
@ -10,6 +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.message import SessionMessage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -44,7 +45,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 httpx.AsyncClient(headers=headers) as client:
|
||||
async with create_mcp_http_client(headers=headers) as client:
|
||||
async with aconnect_sse(
|
||||
client,
|
||||
"GET",
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import httpx
|
|||
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
||||
from httpx_sse import EventSource, ServerSentEvent, aconnect_sse
|
||||
|
||||
from mcp.shared._httpx_utils import create_mcp_http_client
|
||||
from mcp.shared.message import ClientMessageMetadata, SessionMessage
|
||||
from mcp.types import (
|
||||
ErrorData,
|
||||
|
|
@ -446,12 +447,11 @@ async def streamablehttp_client(
|
|||
try:
|
||||
logger.info(f"Connecting to StreamableHTTP endpoint: {url}")
|
||||
|
||||
async with httpx.AsyncClient(
|
||||
async with create_mcp_http_client(
|
||||
headers=transport.request_headers,
|
||||
timeout=httpx.Timeout(
|
||||
transport.timeout.seconds, read=transport.sse_read_timeout.seconds
|
||||
),
|
||||
follow_redirects=True,
|
||||
) as client:
|
||||
# Define callbacks that need access to tg
|
||||
def start_get_stream() -> None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue