Skip to content

Commit 3d68f9e

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 3ee5811 commit 3d68f9e

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
@@ -619,14 +619,14 @@ async def sse_writer(): # pragma: lax no cover
619619
# Then send the message to be processed by the server
620620
session_message = self._create_session_message(message, request, request_id, protocol_version)
621621
await writer.send(session_message)
622-
except Exception: # pragma: no cover
622+
except Exception:
623623
logger.exception("SSE response error")
624624
await sse_stream_writer.aclose()
625625
await self._clean_up_memory_streams(request_id)
626626
finally:
627627
await sse_stream_reader.aclose()
628628

629-
except Exception as err: # pragma: no cover
629+
except Exception as err:
630630
logger.exception("Error handling POST request")
631631
response = self._create_error_response(
632632
f"Error handling POST request: {err}",
@@ -809,7 +809,7 @@ async def _validate_request_headers(self, request: Request, send: Send) -> bool:
809809

810810
async def _validate_session(self, request: Request, send: Send) -> bool:
811811
"""Validate the session ID in the request."""
812-
if not self.mcp_session_id: # pragma: no cover
812+
if not self.mcp_session_id:
813813
# If we're not using session IDs, return True
814814
return True
815815

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)