Skip to content

Commit 4116e02

Browse files
wiggzzclaude
andcommitted
Remove over-conservative pragma: no cover annotations
The sleep(0) yield in the stateless request handler allows the event loop to exercise exception paths that were previously unreachable with mocked tests. These paths are legitimately reachable and the more realistic test now covers them consistently: - streamable_http_manager.py: except Exception in run_stateless_server - streamable_http.py: except Exception in SSE pipeline (x2) - streamable_http.py: if not self.mcp_session_id (always true in stateless mode) - session.py: except Exception in receive loop cleanup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bc59032 commit 4116e02

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/mcp/server/streamable_http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,14 @@ async def sse_writer(): # pragma: lax no cover
626626
# Then send the message to be processed by the server
627627
session_message = self._create_session_message(message, request, request_id, protocol_version)
628628
await writer.send(session_message)
629-
except Exception: # pragma: no cover
629+
except Exception:
630630
logger.exception("SSE response error")
631631
await sse_stream_writer.aclose()
632632
await self._clean_up_memory_streams(request_id)
633633
finally:
634634
await sse_stream_reader.aclose()
635635

636-
except Exception as err: # pragma: no cover
636+
except Exception as err:
637637
logger.exception("Error handling POST request")
638638
response = self._create_error_response(
639639
f"Error handling POST request: {err}",
@@ -816,7 +816,7 @@ async def _validate_request_headers(self, request: Request, send: Send) -> bool:
816816

817817
async def _validate_session(self, request: Request, send: Send) -> bool:
818818
"""Validate the session ID in the request."""
819-
if not self.mcp_session_id: # pragma: no cover
819+
if not self.mcp_session_id:
820820
# If we're not using session IDs, return True
821821
return True
822822

src/mcp/server/streamable_http_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async def run_stateless_server(*, task_status: TaskStatus[None] = anyio.TASK_STA
178178
self.app.create_initialization_options(),
179179
stateless=True,
180180
)
181-
except Exception: # pragma: no cover
181+
except Exception:
182182
logger.exception("Stateless session crashed")
183183

184184
# Use a request-scoped task group instead of the global one.

src/mcp/shared/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ async def _receive_loop(self) -> None:
423423
try:
424424
await stream.send(JSONRPCError(jsonrpc="2.0", id=id, error=error))
425425
await stream.aclose()
426-
except Exception: # pragma: no cover
426+
except Exception:
427427
# Stream might already be closed
428428
pass
429429
self._response_streams.clear()

0 commit comments

Comments
 (0)