Skip to content

Commit 131a58d

Browse files
committed
ruff
1 parent ab0c809 commit 131a58d

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

src/mcp/server/streamable_http_manager.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,17 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE
246246
# Only remove from instances if not terminated
247247
if (
248248
http_transport.mcp_session_id
249-
and http_transport.mcp_session_id
250-
in self._server_instances
249+
and http_transport.mcp_session_id in self._server_instances
251250
and not (
252-
hasattr(http_transport, "_terminated")
253-
and http_transport._terminated # pyright: ignore
251+
hasattr(http_transport, "_terminated") and http_transport._terminated # pyright: ignore
254252
)
255253
):
256254
logger.info(
257255
"Cleaning up crashed session "
258256
f"{http_transport.mcp_session_id} from "
259257
"active instances."
260258
)
261-
del self._server_instances[
262-
http_transport.mcp_session_id
263-
]
259+
del self._server_instances[http_transport.mcp_session_id]
264260

265261
# Assert task group is not None for type checking
266262
assert self._task_group is not None

tests/server/test_streamable_http_manager.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ async def send(message):
7373
with pytest.raises(RuntimeError) as excinfo:
7474
await manager.handle_request(scope, receive, send)
7575

76-
assert "Task group is not initialized. Make sure to use run()." in str(
77-
excinfo.value
78-
)
76+
assert "Task group is not initialized. Make sure to use run()." in str(excinfo.value)
7977

8078

8179
class TestException(Exception):
@@ -137,12 +135,10 @@ async def mock_receive():
137135
# Give other tasks a chance to run. This is important for the finally block.
138136
await anyio.sleep(0.01)
139137

140-
assert (
141-
session_id not in manager._server_instances
142-
), "Session ID should be removed from _server_instances after graceful exit"
143-
assert (
144-
not manager._server_instances
145-
), "No sessions should be tracked after the only session exits gracefully"
138+
assert session_id not in manager._server_instances, (
139+
"Session ID should be removed from _server_instances after graceful exit"
140+
)
141+
assert not manager._server_instances, "No sessions should be tracked after the only session exits gracefully"
146142

147143

148144
@pytest.mark.anyio
@@ -195,10 +191,7 @@ async def mock_receive():
195191
# Give other tasks a chance to run to ensure the finally block executes
196192
await anyio.sleep(0.01)
197193

198-
assert (
199-
session_id not in manager._server_instances
200-
), "Session ID should be removed from _server_instances after an exception"
201-
assert (
202-
not manager._server_instances
203-
), "No sessions should be tracked after the only session crashes"
204-
194+
assert session_id not in manager._server_instances, (
195+
"Session ID should be removed from _server_instances after an exception"
196+
)
197+
assert not manager._server_instances, "No sessions should be tracked after the only session crashes"

0 commit comments

Comments
 (0)