@@ -177,7 +177,7 @@ def is_terminated(self) -> bool:
177177 """Check if this transport has been explicitly terminated."""
178178 return self ._terminated
179179
180- def close_sse_stream (self , request_id : RequestId ) -> None : # pragma: no cover
180+ def close_sse_stream (self , request_id : RequestId ) -> None :
181181 """Close SSE connection for a specific request without terminating the stream.
182182
183183 This method closes the HTTP connection for the specified request, triggering
@@ -205,7 +205,7 @@ def close_sse_stream(self, request_id: RequestId) -> None: # pragma: no cover
205205 send_stream .close ()
206206 receive_stream .close ()
207207
208- def close_standalone_sse_stream (self ) -> None : # pragma: no cover
208+ def close_standalone_sse_stream (self ) -> None :
209209 """Close the standalone GET SSE stream, triggering client reconnection.
210210
211211 This method closes the HTTP connection for the standalone GET stream used
@@ -240,10 +240,10 @@ def _create_session_message(
240240 # Only provide close callbacks when client supports resumability
241241 if self ._event_store and protocol_version >= "2025-11-25" :
242242
243- async def close_stream_callback () -> None : # pragma: no cover
243+ async def close_stream_callback () -> None :
244244 self .close_sse_stream (request_id )
245245
246- async def close_standalone_stream_callback () -> None : # pragma: no cover
246+ async def close_standalone_stream_callback () -> None :
247247 self .close_standalone_sse_stream ()
248248
249249 metadata = ServerMessageMetadata (
@@ -291,7 +291,7 @@ def _create_error_response(
291291 ) -> Response :
292292 """Create an error response with a simple string message."""
293293 response_headers = {"Content-Type" : CONTENT_TYPE_JSON }
294- if headers : # pragma: no cover
294+ if headers :
295295 response_headers .update (headers )
296296
297297 if self .mcp_session_id :
@@ -318,7 +318,7 @@ def _create_json_response(
318318 ) -> Response :
319319 """Create a JSON response from a JSONRPCMessage."""
320320 response_headers = {"Content-Type" : CONTENT_TYPE_JSON }
321- if headers : # pragma: lax no cover
321+ if headers :
322322 response_headers .update (headers )
323323
324324 if self .mcp_session_id : # pragma: lax no cover
@@ -342,7 +342,7 @@ def _create_event_data(self, event_message: EventMessage) -> dict[str, str]:
342342 }
343343
344344 # If an event ID was provided, include it
345- if event_message .event_id : # pragma: no cover
345+ if event_message .event_id :
346346 event_data ["id" ] = event_message .event_id
347347
348348 return event_data
@@ -354,7 +354,7 @@ async def _clean_up_memory_streams(self, request_id: RequestId) -> None:
354354 # Close the request stream
355355 await self ._request_streams [request_id ][0 ].aclose ()
356356 await self ._request_streams [request_id ][1 ].aclose ()
357- except Exception : # pragma: no cover
357+ except Exception :
358358 # During cleanup, we catch all exceptions since streams might be in various states
359359 logger .debug ("Error closing memory streams - may already be closed" )
360360 finally :
@@ -372,7 +372,7 @@ async def handle_request(self, scope: Scope, receive: Receive, send: Send) -> No
372372 await error_response (scope , receive , send )
373373 return
374374
375- if self ._terminated : # pragma: no cover
375+ if self ._terminated :
376376 # If the session has been terminated, return 404 Not Found
377377 response = self ._create_error_response (
378378 "Not Found: Session has been terminated" ,
@@ -387,7 +387,7 @@ async def handle_request(self, scope: Scope, receive: Receive, send: Send) -> No
387387 await self ._handle_get_request (request , send )
388388 elif request .method == "DELETE" :
389389 await self ._handle_delete_request (request , send )
390- else : # pragma: no cover
390+ else :
391391 await self ._handle_unsupported_request (request , send )
392392
393393 def _check_accept_headers (self , request : Request ) -> tuple [bool , bool ]:
@@ -419,7 +419,7 @@ async def _validate_accept_header(self, request: Request, scope: Scope, send: Se
419419 has_json , has_sse = self ._check_accept_headers (request )
420420 if self .is_json_response_enabled :
421421 # For JSON-only responses, only require application/json
422- if not has_json : # pragma: lax no cover
422+ if not has_json :
423423 response = self ._create_error_response (
424424 "Not Acceptable: Client must accept application/json" ,
425425 HTTPStatus .NOT_ACCEPTABLE ,
@@ -439,15 +439,15 @@ async def _validate_accept_header(self, request: Request, scope: Scope, send: Se
439439 async def _handle_post_request (self , scope : Scope , request : Request , receive : Receive , send : Send ) -> None :
440440 """Handle POST requests containing JSON-RPC messages."""
441441 writer = self ._read_stream_writer
442- if writer is None : # pragma: no cover
442+ if writer is None :
443443 raise ValueError ("No read stream writer available. Ensure connect() is called first." )
444444 try :
445445 # Validate Accept header
446446 if not await self ._validate_accept_header (request , scope , send ):
447447 return
448448
449449 # Validate Content-Type
450- if not self ._check_content_type (request ): # pragma: no cover
450+ if not self ._check_content_type (request ):
451451 response = self ._create_error_response (
452452 "Unsupported Media Type: Content-Type must be application/json" ,
453453 HTTPStatus .UNSUPPORTED_MEDIA_TYPE ,
@@ -467,7 +467,7 @@ async def _handle_post_request(self, scope: Scope, request: Request, receive: Re
467467
468468 try :
469469 message = jsonrpc_message_adapter .validate_python (raw_message , by_name = False )
470- except ValidationError as e : # pragma: no cover
470+ except ValidationError as e :
471471 response = self ._create_error_response (
472472 f"Validation error: { str (e )} " ,
473473 HTTPStatus .BAD_REQUEST ,
@@ -493,7 +493,7 @@ async def _handle_post_request(self, scope: Scope, request: Request, receive: Re
493493 )
494494 await response (scope , receive , send )
495495 return
496- elif not await self ._validate_request_headers (request , send ): # pragma: no cover
496+ elif not await self ._validate_request_headers (request , send ):
497497 return
498498
499499 # For notifications and responses only, return 202 Accepted
@@ -626,7 +626,7 @@ 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 )
@@ -653,25 +653,25 @@ async def _handle_get_request(self, request: Request, send: Send) -> None:
653653 and notifications on this stream.
654654 """
655655 writer = self ._read_stream_writer
656- if writer is None : # pragma: no cover
656+ if writer is None :
657657 raise ValueError ("No read stream writer available. Ensure connect() is called first." )
658658
659659 # Validate Accept header - must include text/event-stream
660660 _ , has_sse = self ._check_accept_headers (request )
661661
662- if not has_sse : # pragma: no cover
662+ if not has_sse :
663663 response = self ._create_error_response (
664664 "Not Acceptable: Client must accept text/event-stream" ,
665665 HTTPStatus .NOT_ACCEPTABLE ,
666666 )
667667 await response (request .scope , request .receive , send )
668668 return
669669
670- if not await self ._validate_request_headers (request , send ): # pragma: no cover
670+ if not await self ._validate_request_headers (request , send ):
671671 return
672672
673673 # Handle resumability: check for Last-Event-ID header
674- if last_event_id := request .headers .get (LAST_EVENT_ID_HEADER ): # pragma: no cover
674+ if last_event_id := request .headers .get (LAST_EVENT_ID_HEADER ):
675675 await self ._replay_events (last_event_id , request , send )
676676 return
677677
@@ -685,7 +685,7 @@ async def _handle_get_request(self, request: Request, send: Send) -> None:
685685 headers [MCP_SESSION_ID_HEADER ] = self .mcp_session_id
686686
687687 # Check if we already have an active GET stream
688- if GET_STREAM_KEY in self ._request_streams : # pragma: no cover
688+ if GET_STREAM_KEY in self ._request_streams :
689689 response = self ._create_error_response (
690690 "Conflict: Only one SSE stream is allowed per session" ,
691691 HTTPStatus .CONFLICT ,
@@ -705,7 +705,7 @@ async def standalone_sse_writer():
705705
706706 async with sse_stream_writer , standalone_stream_reader :
707707 # Process messages from the standalone stream
708- async for event_message in standalone_stream_reader : # pragma: lax no cover
708+ async for event_message in standalone_stream_reader :
709709 # For the standalone stream, we handle:
710710 # - JSONRPCNotification (server sends notifications to client)
711711 # - JSONRPCRequest (server sends requests to client)
@@ -714,7 +714,7 @@ async def standalone_sse_writer():
714714 # Send the message via SSE
715715 event_data = self ._create_event_data (event_message )
716716 await sse_stream_writer .send (event_data )
717- except Exception : # pragma: no cover
717+ except Exception :
718718 logger .exception ("Error in standalone SSE writer" )
719719 finally :
720720 logger .debug ("Closing standalone SSE writer" )
@@ -749,7 +749,7 @@ async def _handle_delete_request(self, request: Request, send: Send) -> None:
749749 await response (request .scope , request .receive , send )
750750 return
751751
752- if not await self ._validate_request_headers (request , send ): # pragma: no cover
752+ if not await self ._validate_request_headers (request , send ):
753753 return
754754
755755 await self .terminate ()
@@ -773,7 +773,7 @@ async def terminate(self) -> None:
773773 request_stream_keys = list (self ._request_streams .keys ())
774774
775775 # Close all request streams asynchronously
776- for key in request_stream_keys : # pragma: lax no cover
776+ for key in request_stream_keys :
777777 await self ._clean_up_memory_streams (key )
778778
779779 # Clear the request streams dictionary immediately
@@ -787,11 +787,11 @@ async def terminate(self) -> None:
787787 await self ._write_stream_reader .aclose ()
788788 if self ._write_stream is not None : # pragma: no branch
789789 await self ._write_stream .aclose ()
790- except Exception as e : # pragma: no cover
790+ except Exception as e :
791791 # During cleanup, we catch all exceptions since streams might be in various states
792792 logger .debug (f"Error closing streams: { e } " )
793793
794- async def _handle_unsupported_request (self , request : Request , send : Send ) -> None : # pragma: no cover
794+ async def _handle_unsupported_request (self , request : Request , send : Send ) -> None :
795795 """Handle unsupported HTTP methods."""
796796 headers = {
797797 "Content-Type" : CONTENT_TYPE_JSON ,
@@ -807,7 +807,7 @@ async def _handle_unsupported_request(self, request: Request, send: Send) -> Non
807807 )
808808 await response (request .scope , request .receive , send )
809809
810- async def _validate_request_headers (self , request : Request , send : Send ) -> bool : # pragma: lax no cover
810+ async def _validate_request_headers (self , request : Request , send : Send ) -> bool :
811811 if not await self ._validate_session (request , send ):
812812 return False
813813 if not await self ._validate_protocol_version (request , send ):
@@ -816,15 +816,15 @@ 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
823823 # Get the session ID from the request headers
824824 request_session_id = self ._get_session_id (request )
825825
826826 # If no session ID provided but required, return error
827- if not request_session_id : # pragma: no cover
827+ if not request_session_id :
828828 response = self ._create_error_response (
829829 "Bad Request: Missing session ID" ,
830830 HTTPStatus .BAD_REQUEST ,
@@ -833,7 +833,7 @@ async def _validate_session(self, request: Request, send: Send) -> bool:
833833 return False
834834
835835 # If session ID doesn't match, return error
836- if request_session_id != self .mcp_session_id : # pragma: no cover
836+ if request_session_id != self .mcp_session_id :
837837 response = self ._create_error_response (
838838 "Not Found: Invalid or expired session ID" ,
839839 HTTPStatus .NOT_FOUND ,
@@ -849,11 +849,11 @@ async def _validate_protocol_version(self, request: Request, send: Send) -> bool
849849 protocol_version = request .headers .get (MCP_PROTOCOL_VERSION_HEADER )
850850
851851 # If no protocol version provided, assume default version
852- if protocol_version is None : # pragma: no cover
852+ if protocol_version is None :
853853 protocol_version = DEFAULT_NEGOTIATED_VERSION
854854
855855 # Check if the protocol version is supported
856- if protocol_version not in SUPPORTED_PROTOCOL_VERSIONS : # pragma: no cover
856+ if protocol_version not in SUPPORTED_PROTOCOL_VERSIONS :
857857 supported_versions = ", " .join (SUPPORTED_PROTOCOL_VERSIONS )
858858 response = self ._create_error_response (
859859 f"Bad Request: Unsupported protocol version: { protocol_version } . "
@@ -865,7 +865,7 @@ async def _validate_protocol_version(self, request: Request, send: Send) -> bool
865865
866866 return True
867867
868- async def _replay_events (self , last_event_id : str , request : Request , send : Send ) -> None : # pragma: no cover
868+ async def _replay_events (self , last_event_id : str , request : Request , send : Send ) -> None :
869869 """Replays events that would have been sent after the specified event ID.
870870
871871 Only used when resumability is enabled.
@@ -991,7 +991,7 @@ async def message_router():
991991 if isinstance (message , JSONRPCResponse | JSONRPCError ) and message .id is not None :
992992 target_request_id = str (message .id )
993993 # Extract related_request_id from meta if it exists
994- elif ( # pragma: no cover
994+ elif (
995995 session_message .metadata is not None
996996 and isinstance (
997997 session_message .metadata ,
@@ -1018,7 +1018,7 @@ async def message_router():
10181018 except (anyio .BrokenResourceError , anyio .ClosedResourceError ): # pragma: no cover
10191019 # Stream might be closed, remove from registry
10201020 self ._request_streams .pop (request_stream_id , None )
1021- else : # pragma: no cover
1021+ else :
10221022 logger .debug (
10231023 f"""Request stream { request_stream_id } not found
10241024 for message. Still processing message as the client
0 commit comments