Skip to content

Commit df06c15

Browse files
committed
style: Trim trailing blank lines to satisfy end-of-file-fixer hook
1 parent 5d05ef1 commit df06c15

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/mcp/client/streamable_http.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def _unwrap_exception(exc: BaseException) -> BaseException:
7676
return exc
7777

7878

79-
8079
@dataclass
8180
class RequestContext:
8281
"""Context for a request operation."""
@@ -248,7 +247,6 @@ async def handle_get_stream(self, client: httpx2.AsyncClient, read_stream_writer
248247
attempt += 1
249248
last_exc = exc
250249

251-
252250
if attempt >= MAX_RECONNECTION_ATTEMPTS:
253251
logger.debug(f"GET stream max reconnection attempts ({MAX_RECONNECTION_ATTEMPTS}) exceeded")
254252
raise StreamableHTTPError(
@@ -467,7 +465,6 @@ async def _handle_sse_response(
467465
except httpx2.HTTPError:
468466
logger.debug("SSE stream ended", exc_info=True) # pragma: lax no cover
469467

470-
471468
# Stream ended without response - reconnect if we received an event with ID
472469
if last_event_id is not None:
473470
logger.info("SSE stream disconnected, reconnecting...")
@@ -554,7 +551,6 @@ async def _handle_reconnection(
554551
# Try to reconnect again if we still have an event ID
555552
await self._handle_reconnection(ctx, last_event_id, retry_interval_ms, attempt + 1)
556553

557-
558554
async def post_writer(
559555
self,
560556
client: httpx2.AsyncClient,
@@ -744,4 +740,3 @@ def start_get_stream() -> None:
744740
if isinstance(unwrapped, StreamableHTTPError):
745741
raise unwrapped from exc
746742
raise
747-

tests/shared/test_streamable_http.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,15 +2339,17 @@ async def test_streamable_http_client_reconnect_failure_propagates_error() -> No
23392339
"content-type": "application/json",
23402340
"mcp-session-id": "test-session",
23412341
}
2342-
mock_response.aread.return_value = json.dumps({
2343-
"jsonrpc": "2.0",
2344-
"id": 1,
2345-
"result": {
2346-
"protocolVersion": "2025-06-18",
2347-
"capabilities": {},
2348-
"serverInfo": {"name": "test-server", "version": "1.0"},
2342+
mock_response.aread.return_value = json.dumps(
2343+
{
2344+
"jsonrpc": "2.0",
2345+
"id": 1,
2346+
"result": {
2347+
"protocolVersion": "2025-06-18",
2348+
"capabilities": {},
2349+
"serverInfo": {"name": "test-server", "version": "1.0"},
2350+
},
23492351
}
2350-
}).encode("utf-8")
2352+
).encode("utf-8")
23512353

23522354
mock_initialized_response = AsyncMock(spec=httpx2.Response)
23532355
mock_initialized_response.status_code = 202
@@ -2361,47 +2363,50 @@ async def mock_stream(*args: Any, **kwargs: Any):
23612363

23622364
client.stream = mock_stream
23632365

2364-
23652366
# Mock client.sse to raise httpx2.HTTPError
23662367
client.sse.side_effect = httpx2.HTTPError("SSE connection refused")
23672368

23682369
# Patch anyio.sleep to avoid waiting during reconnect attempts
23692370
with patch("mcp.client.streamable_http.anyio.sleep", new_callable=AsyncMock) as mock_sleep:
23702371
with pytest.raises(StreamableHTTPError) as exc_info:
23712372
with anyio.fail_after(5):
2372-
async with streamable_http_client("http://localhost:8000/mcp", http_client=client) as (read_stream, write_stream):
2373+
async with streamable_http_client("http://localhost:8000/mcp", http_client=client) as (
2374+
read_stream,
2375+
write_stream,
2376+
):
23732377
# Send initialize message
2374-
await write_stream.send(SessionMessage(
2375-
types.JSONRPCRequest(
2376-
jsonrpc="2.0",
2377-
id=1,
2378-
method="initialize",
2379-
params={
2380-
"protocolVersion": "2025-06-18",
2381-
"capabilities": {},
2382-
"clientInfo": {"name": "test-client", "version": "1.0"},
2383-
},
2378+
await write_stream.send(
2379+
SessionMessage(
2380+
types.JSONRPCRequest(
2381+
jsonrpc="2.0",
2382+
id=1,
2383+
method="initialize",
2384+
params={
2385+
"protocolVersion": "2025-06-18",
2386+
"capabilities": {},
2387+
"clientInfo": {"name": "test-client", "version": "1.0"},
2388+
},
2389+
)
23842390
)
2385-
))
2391+
)
23862392

23872393
# Receive the response
23882394
await read_stream.receive()
23892395

23902396
# Send notifications/initialized (which will trigger start_get_stream)
2391-
await write_stream.send(SessionMessage(
2392-
types.JSONRPCNotification(
2393-
jsonrpc="2.0",
2394-
method="notifications/initialized",
2397+
await write_stream.send(
2398+
SessionMessage(
2399+
types.JSONRPCNotification(
2400+
jsonrpc="2.0",
2401+
method="notifications/initialized",
2402+
)
23952403
)
2396-
))
2404+
)
23972405

23982406
# Wait for the task group to fail
23992407
event = anyio.Event()
24002408
await event.wait()
24012409

2402-
24032410
assert "Failed to connect to GET stream" in str(exc_info.value)
24042411
assert client.sse.call_count == 2
24052412
mock_sleep.assert_called_once_with(1.0)
2406-
2407-

0 commit comments

Comments
 (0)