@@ -84,27 +84,41 @@ async def _handle_error_response(response: httpx.Response) -> None:
8484 No raises. let the mcp http client handle the errors.
8585 """
8686 if response .is_error :
87+ # warning only because the SDK logs error
88+ log_level = logging .WARNING
89+ if (
90+ # The server MAY respond 405 to GET (SSE) and DELETE (session).
91+ response .status_code == 405 and response .request .method in ('GET' , 'DELETE' )
92+ ) or (
93+ # The server MAY terminate the session at any time, after which it MUST
94+ # respond to requests containing that session ID with HTTP 404 Not Found.
95+ response .status_code == 404 and response .request .method == 'POST'
96+ ):
97+ log_level = logging .DEBUG
98+
8799 try :
88100 # read the content and settle the response content. required to get body (.json(), .text)
89101 await response .aread ()
90102 except Exception as e :
91- logger .error ('Failed to read response: %s' , e )
92- # do nothing and let the client handle the error
103+ logger .debug ('Failed to read response: %s' , e )
104+ # do nothing and let the client and SDK handle the error
93105 return
94106
95107 # Try to extract error details with fallbacks
96108 try :
97109 # Try to parse JSON error details
98110 error_details = response .json ()
99- logger .error ( 'HTTP %d Error Details: %s' , response .status_code , error_details )
111+ logger .log ( log_level , 'HTTP %d Error Details: %s' , response .status_code , error_details )
100112 except Exception :
101113 # If JSON parsing fails, use response text or status code
102114 try :
103115 response_text = response .text
104- logger .error ( 'HTTP %d Error: %s' , response .status_code , response_text )
116+ logger .log ( log_level , 'HTTP %d Error: %s' , response .status_code , response_text )
105117 except Exception :
106118 # Fallback to just status code and URL
107- logger .error ('HTTP %d Error for url %s' , response .status_code , response .url )
119+ logger .log (
120+ log_level , 'HTTP %d Error for url %s' , response .status_code , response .url
121+ )
108122
109123
110124def create_aws_session (profile : Optional [str ] = None ) -> boto3 .Session :
0 commit comments