Skip to content

Commit

Permalink
revert unintended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-merrill committed Jan 14, 2025
1 parent 7b35ab8 commit 5097bb7
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions src/mcp/client/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,12 @@ async def sse_client(
headers: dict[str, Any] | None = None,
timeout: float = 5,
sse_read_timeout: float = 60 * 5,
client: httpx.AsyncClient | 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 URL to connect to
headers: Optional headers to send with the request
timeout: Connection timeout in seconds
sse_read_timeout: Read timeout in seconds
client: Optional httpx.AsyncClient instance to use for requests
"""
read_stream: MemoryObjectReceiveStream[types.JSONRPCMessage | Exception]
read_stream_writer: MemoryObjectSendStream[types.JSONRPCMessage | Exception]
Expand All @@ -51,13 +43,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)}")
if client is None:
client = httpx.AsyncClient(headers=headers)
should_close_client = True
else:
should_close_client = False

try:
async with httpx.AsyncClient(headers=headers) as client:
async with aconnect_sse(
client,
"GET",
Expand Down Expand Up @@ -151,9 +137,6 @@ async def post_writer(endpoint_url: str):
yield read_stream, write_stream
finally:
tg.cancel_scope.cancel()
finally:
if should_close_client:
await client.aclose()
finally:
await read_stream_writer.aclose()
await write_stream.aclose()

0 comments on commit 5097bb7

Please sign in to comment.