Skip to content

Commit 3ee5811

Browse files
wiggzzclaude
andcommitted
Fix CI: coverage, ruff format, and remove unused handle_list_tools
- Add anyio.sleep(0) between terminate() and cancel_scope.cancel() so the message router can observe the ClosedResourceError from the closed streams before the task group is cancelled (restores line 1022 coverage) - Remove handle_list_tools from test — it was never called (only call_tool is exercised), so its return was an uncovered line - Mark the CallToolResult return as pragma: no cover — intentionally unreachable in this test because the task is always cancelled at await tool_gate.wait() before the return executes - Collapse multi-line function signatures to satisfy ruff-format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d7bb2ea commit 3ee5811

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

src/mcp/server/streamable_http_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ async def run_request_handler(*, task_status: TaskStatus[None] = anyio.TASK_STAT
193193
await http_transport.handle_request(scope, receive, send)
194194
# Terminate the transport after the request is handled
195195
await http_transport.terminate()
196+
# Yield one scheduling step so other tasks (e.g. the message
197+
# router) can observe the closed streams before we cancel.
198+
await anyio.sleep(0)
196199
# Cancel the request-scoped task group to stop the server task
197200
request_tg.cancel_scope.cancel()
198201

tests/server/test_streamable_http_manager.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,13 @@ async def test_stateless_requests_task_leak_on_client_disconnect():
291291
tool_started = anyio.Event()
292292
tool_gate = anyio.Event()
293293

294-
async def handle_list_tools(
295-
ctx: ServerRequestContext, params: PaginatedRequestParams | None
296-
) -> ListToolsResult:
297-
return ListToolsResult(
298-
tools=[Tool(name="slow_tool", description="A slow tool", inputSchema={"type": "object"})]
299-
)
300-
301-
async def handle_call_tool(
302-
ctx: ServerRequestContext, params: Any
303-
) -> CallToolResult:
294+
async def handle_call_tool(ctx: ServerRequestContext, params: Any) -> CallToolResult:
304295
tool_started.set()
305-
# Simulate a slow tool (e.g., API call to Discovery/Snowflake)
306296
await tool_gate.wait()
307-
return CallToolResult(content=[TextContent(type="text", text="done")])
297+
return CallToolResult(content=[TextContent(type="text", text="done")]) # pragma: no cover
308298

309299
app = Server(
310300
"test-stateless-leak",
311-
on_list_tools=handle_list_tools,
312301
on_call_tool=handle_call_tool,
313302
)
314303

0 commit comments

Comments
 (0)