
    )`in                     t   d Z ddlZddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ ddlZddlZdd	lmZ dd
lmZmZ ddlmZmZmZ ddlmZ ddlmZm Z  ddl!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,  ej-        e.          Z/e#e0z  Z1ee1         Z2ee#         Z3eg e4dz  f         Z5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ> e?            Z@ G d de0          ZA G d deA          ZBe	 G d d                      ZC G d d           ZDedd!d"d#e4d$ejE        dz  d%eFd&eeGee#e0z           ee#         e5f         df         fd'            ZHe ed(          dd)d*d!e dfd#e4d+eIe4e4f         dz  d,eJez  d-eJez  d%eFd.ed/ejK        dz  d&eeGee#e0z           ee#         e5f         df         fd0                        ZLdS )1z
StreamableHTTP Client Transport Module

This module implements the StreamableHTTP transport for MCP clients,
providing support for HTTP POST requests with optional SSE streaming responses
and session management.
    N)AsyncGenerator	AwaitableCallable)asynccontextmanager)	dataclass)	timedelta)Anyoverload)warn)	TaskGroup)MemoryObjectReceiveStreamMemoryObjectSendStream)EventSourceServerSentEventaconnect_sse)
deprecated)McpHttpClientFactorycreate_mcp_http_client)ClientMessageMetadataSessionMessage)	ErrorDataInitializeResultJSONRPCErrorJSONRPCMessageJSONRPCNotificationJSONRPCRequestJSONRPCResponse	RequestIdzmcp-session-idzmcp-protocol-versionzlast-event-idi     zcontent-typeacceptzapplication/jsonztext/event-streamc                       e Zd ZdZdS )StreamableHTTPErrorz3Base exception for StreamableHTTP transport errors.N__name__
__module____qualname____doc__     n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/mcp/client/streamable_http.pyr"   r"   C   s        ====r)   r"   c                       e Zd ZdZdS )ResumptionErrorz*Raised when resumption request is invalid.Nr#   r(   r)   r*   r,   r,   G   s        4444r)   r,   c                       e Zd ZU dZej        ed<   edz  ed<   eed<   e	dz  ed<   e
ed<   dZeeef         dz  ed<   dZedz  ed	<   dS )
RequestContextz Context for a request operation.clientN
session_idsession_messagemetadataread_stream_writerheaderssse_read_timeout)r$   r%   r&   r'   httpxAsyncClient__annotations__strr   r   StreamWriterr4   dictr5   floatr(   r)   r*   r.   r.   K   s         **d
#####d****$$$$%)GT#s(^d")))%)edl)))))r)   r.   c                      e Zd ZdZededdfd            Ze ed          	 	 	 	 d4ded	eeef         dz  d
e	e
z  de	e
z  dej        dz  ddfd                        Zeeeefded	ed
edededdfdZdeeef         fdZdedefdZdedefdZdej        ddfdZdeddfdZ	 	 	 d5dedededz  deeged         f         dz  dedefdZdej        deddfdZdeddfd Z deddfd!Z!	 d6dej        dededdfd"Z"	 d6dej        dededdfd#Z#	 	 d7ded%ed&e$dz  d'e$ddf
d(Z%d)ededdfd*Z&ded+eddfd,Z'dej        d-e(ded.e)e*         d/eg df         d0e+ddfd1Z,dej        ddfd2Z-dedz  fd3Z.dS )8StreamableHTTPTransportz/StreamableHTTP client transport implementation.urlreturnNc                     d S Nr(   )selfr?   s     r*   __init__z StreamableHTTPTransport.__init__[   s    *-#r)   zyParameters headers, timeout, sse_read_timeout, and auth are deprecated. Configure these on the httpx.AsyncClient instead.   ,  r4   timeoutr5   authc                     d S rB   r(   )rC   r?   r4   rG   r5   rH   s         r*   rD   z StreamableHTTPTransport.__init__^   s	     sr)   c                    g }|t           ur|                    d           |t           ur|                    d           |t           ur|                    d           |t           ur|                    d           |r.t          dd                    |           dt          d	           || _        d
| _        d
| _        d
S )aS  Initialize the StreamableHTTP transport.

        Args:
            url: The endpoint URL.
            headers: Optional headers to include in requests.
            timeout: HTTP timeout for regular operations.
            sse_read_timeout: Timeout for SSE read operations.
            auth: Optional HTTPX authentication handler.
        r4   rG   r5   rH   zParameters , zV are deprecated and will be ignored. Configure these on the httpx.AsyncClient instead.r   )
stacklevelN)_UNSETappendr   joinDeprecationWarningr?   r0   protocol_version)rC   r?   r4   rG   r5   rH   deprecated_paramss          r*   rD   z StreamableHTTPTransport.__init__l   s    $ (*&  $$Y///&  $$Y///6))$$%7888v$$V,,, 	Ddii(9:: D D D"	     $r)   c                     i }t            dt           |t          <   t           |t          <   | j        r| j        |t
          <   | j        r| j        |t          <   |S )zBuild MCP-specific request headers.

        These headers will be merged with the httpx.AsyncClient's default headers,
        with these MCP-specific headers taking precedence.
        rK   )JSONSSEACCEPTCONTENT_TYPEr0   MCP_SESSION_IDrQ   MCP_PROTOCOL_VERSION)rC   r4   s     r*   _prepare_headersz(StreamableHTTPTransport._prepare_headers   s_     #%!**S** $? 	6&*oGN#  	B,0,AG()r)   messagec                 V    t          |j        t                    o|j        j        dk    S )z2Check if the message is an initialization request.
initialize)
isinstancerootr   methodrC   r[   s     r*   _is_initialization_requestz2StreamableHTTPTransport._is_initialization_request   s$    ',77_GL<OS_<__r)   c                 V    t          |j        t                    o|j        j        dk    S )z4Check if the message is an initialized notification.znotifications/initialized)r^   r_   r   r`   ra   s     r*   _is_initialized_notificationz4StreamableHTTPTransport._is_initialized_notification   s%    ',(;<<sATXsAssr)   responsec                     |j                             t                    }|r+|| _        t                              d| j                    dS dS )z3Extract and store session ID from response headers.zReceived session ID: N)r4   getrX   r0   loggerinfo)rC   re   new_session_ids      r*   '_maybe_extract_session_id_from_responsez?StreamableHTTPTransport._maybe_extract_session_id_from_response   sY    
 ")--n== 	C,DOKKAAABBBBB	C 	Cr)   c                    t          |j        t                    r|j        j        r	 t	          j        |j        j                  }t          |j                  | _        t          
                    d| j                    dS # t          $ rO}t                              d|            t                              d|j        j                    Y d}~dS d}~ww xY wdS dS )z>Extract protocol version from initialization response message.zNegotiated protocol version: z=Failed to parse initialization response as InitializeResult: zRaw result: N)r^   r_   r   resultr   model_validater9   protocolVersionrQ   rh   ri   	Exceptionwarning)rC   r[   init_resultexcs       r*   ,_maybe_extract_protocol_version_from_messagezDStreamableHTTPTransport._maybe_extract_protocol_version_from_message   s	   
 glO44 
	E9L 
	E	E.=gl>QRR(+K,G(H(H%SD<QSSTTTTT E E EYTWYY   Cgl.ACCDDDDDDDDD	E
	E 
	E 
	E 
	Es   AB 
CACCFsser3   original_request_idresumption_callbackis_initializationc                 "  K   |j         dk    r^|j        s!|j        r|r ||j                   d{V  dS 	 t          j        |j                  }t
                              d|            |r|                     |           |.t          |j	        t          t          z            r||j	        _        t          |          }|                    |           d{V  |j        r|r ||j                   d{V  t          |j	        t          t          z            S # t          $ r@}t
                              d           |                    |           d{V  Y d}~dS d}~ww xY wt
                              d|j                     dS )z@Handle an SSE event, returning True if the response is complete.r[   NFzSSE message: zError parsing SSE messagezUnknown SSE event: )eventdataidr   model_validate_jsonrh   debugrt   r^   r_   r   r   r   sendrp   	exceptionrq   )	rC   ru   r3   rv   rw   rx   r[   r1   rs   s	            r*   _handle_sse_eventz)StreamableHTTPTransport._handle_sse_event   s      9	!!8 6 61 6--cf555555555u(<SXFF6W66777 % OEEgNNN '2z',P_bnPn7o7o2&9GLO"0"9"9(--o>>>>>>>>> 6 61 6--cf555555555 "',,0NOOO     !<===(--c222222222uuuuu
 NN<<<===5s   C'D   
E**5E%%E*r/   c                   K   d}d}d}|t           k     r	 | j        sdS |                                 }|r
||t          <   t	          |d| j        |          4 d{V 	 }|j                                         t          	                    d           |
                                2 3 d{V }|j        r|j        }|j        |j        }|                     ||           d{V  @6 d}ddd          d{V  n# 1 d{V swxY w Y   n9# t          $ r,}	t          	                    d|	            |dz  }Y d}	~	nd}	~	ww xY w|t           k    r%t          	                    dt            d	           dS ||nt          }
t                              d
|
 d           t#          j        |
dz             d{V  |t           k     dS dS )zDHandle GET stream for server-initiated messages with auto-reconnect.Nr   GETr4   zGET SSE connection establishedzGET stream error:    z&GET stream max reconnection attempts (
) exceededz)GET stream disconnected, reconnecting in zms...     @@)MAX_RECONNECTION_ATTEMPTSr0   rZ   LAST_EVENT_IDr   r?   re   raise_for_statusrh   r~   	aiter_sser|   retryr   rp   DEFAULT_RECONNECTION_DELAY_MSri   anyiosleep)rC   r/   r3   last_event_idretry_interval_msattemptr4   event_sourceru   rs   delay_mss              r*   handle_get_streamz)StreamableHTTPTransport.handle_get_stream   s      %)(,111  F//11  ;-:GM*'H#	                  
 " )::<<<LL!ABBB%1%;%;%=%= N N N N N N Nc6 3,/FM9003	-"44S:LMMMMMMMMMM &>  G)                                                     ,    7#778881 333kF_kkklll ->,I((OlHKKSHSSSTTT+h/000000000U 1111111sM   D >D AC;&C&,=C;)D ;
DD D	D 
E"D>>Ectxc                   K   |                                  }|j        r!|j        j        r|j        j        |t          <   nt	          d          d}t          |j        j        j        t                    r|j        j        j        j
        }t          |j        d| j        |          4 d{V 	 }|j                                         t                               d           |                                2 3 d{V }|                     ||j        ||j        r|j        j        nd           d{V }|r!|j                                         d{V   na6 	 ddd          d{V  dS # 1 d{V swxY w Y   dS )z/Handle a resumption request using GET with SSE.z.Resumption request requires a resumption tokenNr   r   z)Resumption GET SSE connection established)rZ   r2   resumption_tokenr   r,   r^   r1   r[   r_   r   r|   r   r/   r?   re   r   rh   r~   r   r   r3   on_resumption_token_updateaclose)rC   r   r4   rv   r   ru   is_completes          r*   _handle_resumption_requestz2StreamableHTTPTransport._handle_resumption_request-  sa     ''))< 	TCL9 	T%(\%BGM""!"RSSS #c)16GG 	F"%"5"="B"EJH	
 
 
 	 	 	 	 	 	 	 	
 !22444LLDEEE)3355 	 	 	 	 	 	 	c$($:$:*'?B|UCL;;QU	% %        &/66888888888E 65	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    .AE,6E<AE,,
E69E6c           	        K   |                                  }|j        j        }|                     |          }|j                            d| j        |                    ddd          |          4 d{V 	 }|j        dk    r.t          
                    d           	 ddd          d{V  dS |j        d	k    rYt          |j        t                    r+|                     |j        |j        j                   d{V  	 ddd          d{V  dS |                                 |r|                     |           t          |j        t                    r|j                            t*          d
                                          }|                    t0                    r#|                     ||j        |           d{V  nY|                    t4                    r|                     |||           d{V  n!|                     ||j                   d{V  ddd          d{V  dS # 1 d{V swxY w Y   dS )z/Handle a POST request with response processing.POSTTjson)by_aliasmodeexclude_none)r   r4   N   zReceived 202 Acceptedi   )rZ   r1   r[   rb   r/   streamr?   
model_dumpstatus_coderh   r~   r^   r_   r   _send_session_terminated_errorr3   r|   r   rk   r4   rg   rW   lower
startswithrT   _handle_json_responserU   _handle_sse_response_handle_unexpected_content_type)rC   r   r4   r[   rx   re   content_types          r*   _handle_post_requestz,StreamableHTTPTransport._handle_post_requestN  s     ''))%- ;;GDD:$$H##TT#RR	 % 
 
 "	 "	 "	 "	 "	 "	 "	 "	
 #s**4555"	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 #s**glN;; ==.         !"	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	$ %%'''  G<<XFFF ',77 
'/33L"EEKKMM**400 44Xs?UWhiiiiiiiiii!,,S11 33HcCTUUUUUUUUUU>>$.        ?"	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	 "	s    8'H62AH6DH66
I I c                   K   	 |                                  d{V }t          j        |          }|r|                     |           t	          |          }|                    |           d{V  dS # t          $ r@}t                              d           |                    |           d{V  Y d}~dS d}~ww xY w)z%Handle JSON response from the server.NzError parsing JSON response)	areadr   r}   rt   r   r   rp   rh   r   )rC   re   r3   rx   contentr[   r1   rs   s           r*   r   z-StreamableHTTPTransport._handle_json_responsex  s      	/$NN,,,,,,,,G$8AAG ! KAA'JJJ,W55O$))/::::::::::: 	/ 	/ 	/:;;;$))#...............	/s   A/A5 5
B??5B::B?c                 0  K   d}d}	 t          |          }|                                2 3 d{V }|j        r|j        }|j        |j        }|                     ||j        |j        r|j        j        nd|           d{V }|r|                                 d{V   dS z6 n4# t          $ r'}	t                              d|	            Y d}	~	nd}	~	ww xY w|9t                              d           |                     |||           d{V  dS dS )z$Handle SSE response from the server.N)rw   rx   zSSE stream ended: (SSE stream disconnected, reconnecting...)r   r   r|   r   r   r3   r2   r   r   rp   rh   r~   ri   _handle_reconnection)
rC   re   r   rx   r   r   r   ru   r   es
             r*   r   z,StreamableHTTPTransport._handle_sse_response  s      %)(,	3&x00L)3355       c6 +$'FM 9((+	%$($:$:*TWT`)j)P)Pfj&7	 %; % %        "//+++++++++FF# 65(  	3 	3 	3LL1a1122222222	3 $KKBCCC++C@QRRRRRRRRRRR %$s(   #B' B%A1B' $B' '
C1CCr   r   r   r   c                   K   |t           k    r%t                              dt            d           dS ||nt          }t	          j        |dz             d{V  |                                 }||t          <   d}t          |j	        j
        j        t                    r|j	        j
        j        j        }	 t          |j        d| j        |          4 d{V 	 }|j                                         t                              d           |}	|}
|                                2 3 d{V }|j        r|j        }	|j        |j        }
|                     ||j        ||j        r|j        j        nd           d{V }|r3|j                                         d{V   ddd          d{V  dS 6 t                              d           |                     ||	|
d	           d{V  ddd          d{V  dS # 1 d{V swxY w Y   dS # t8          $ rI}t                              d
|            |                     ||||dz              d{V  Y d}~dS d}~ww xY w)zFReconnect with Last-Event-ID to resume stream after server disconnect.zMax reconnection attempts (r   Nr   r   r   zReconnected to SSE streamr   r   zReconnection failed: r   )r   rh   r~   r   r   r   rZ   r   r^   r1   r[   r_   r   r|   r   r/   r?   re   r   ri   r   r   r   r3   r2   r   r   r   rp   )rC   r   r   r   r   r   r4   rv   r   reconnect_last_event_idreconnect_retry_msru   r   r   s                 r*   r   z,StreamableHTTPTransport._handle_reconnection  s      ///LL\7P\\\]]]F ):(E$$Khk(V+,,,,,,,,,''))!. #c)16GG 	F"%"5"="B"E$	`#
	   e e e e e e e e
 %668887888 0='%6"!-!7!7!9!9       #v 925&/y,-0Y*(,(>(>.+CF<Y??UY	) ) # # # # # #K # *3::<<<<<<<<<7e e e e e e e e e e e e e e2 ":" FGGG//5LN`bcddddddddd?e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e@  	` 	` 	`LL444555++C@QSZ]^S^_______________	`sV   6#H AH&F5,A5H!H 4:H.H 
HH HH 
I'>I""I'r   c                    K   d| }t                               |           |                    t          |                     d{V  dS )z+Handle unexpected content type in response.zUnexpected content type: N)rh   errorr   
ValueError)rC   r   r3   	error_msgs       r*   r   z7StreamableHTTPTransport._handle_unexpected_content_type  s[       ?>>	Y %%j&;&;<<<<<<<<<<<r)   
request_idc                    K   t          d|t          dd                    }t          t          |                    }|                    |           d{V  dS )z)Send a session terminated error response.z2.0iX  zSession terminated)coder[   )jsonrpcr|   r   N)r   r   r   r   r   )rC   r3   r   jsonrpc_errorr1   s        r*   r   z6StreamableHTTPTransport._send_session_terminated_error  sv       %0DEEE
 
 

 ))F)FGG %%o66666666666r)   write_stream_readerwrite_streamstart_get_streamtgc           	      j   K   	 |4 d{V  |2 3 d{V }|j         }t          |j        t                    r|j        nd}	t	          |	o|	j                  t                              d|                                 |          r
 |             t          | j
        ||	|           fd}
t          |j        t                    r|                    |
            |
             d{V  6 	 ddd          d{V  n# 1 d{V swxY w Y   n*# t          $ r t                              d           Y nw xY w|                                 d{V  |                                 d{V  dS # |                                 d{V  |                                 d{V  w xY w)z&Handle writing requests to the server.NzSending client message: )r/   r0   r1   r2   r3   c                     K   r                                 d {V  d S                                 d {V  d S rB   )r   r   )r   is_resumptionrC   s   r*   handle_request_asynczAStreamableHTTPTransport.post_writer.<locals>.handle_request_async1  sh      ( A"&"A"A#"F"FFFFFFFFFF"&";";C"@"@@@@@@@@@@r)   zError in post_writer)r[   r^   r2   r   boolr   rh   r~   rd   r.   r0   r_   r   
start_soonrp   r   r   )rC   r/   r   r3   r   r   r   r1   r[   r2   r   r   r   s   `          @@r*   post_writerz#StreamableHTTPTransport.post_writer  s     +	(* $5 $5 $5 $5 $5 $5 $5 $5-@ #5 #5 #5 #5 #5 #5 #5/-5G &o&>@UVV"00!  %))Oh6O$P$PMLL!EG!E!EFFF 88AA +((***(%#'?(7!)+=  CA A A A A A A "',?? 5&:;;;;224444444444G .A-@$5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5 $5L  	5 	5 	5344444	5 %++---------%%''''''''''' %++---------%%''''''''''sW   D D
C6CD
8D 

DD DD E< $E E< EE< <6F2c                   K   | j         sdS 	 |                                 }|                    | j        |           d{V }|j        dk    rt
                              d           dS |j        dvr$t
                              d|j                    dS dS # t          $ r(}t
                              d|            Y d}~dS d}~ww xY w)z2Terminate the session by sending a DELETE request.Nr   i  z)Server does not allow session termination)      zSession termination failed: )	r0   rZ   deleter?   r   rh   r~   rq   rp   )rC   r/   r4   re   rs   s        r*   terminate_sessionz)StreamableHTTPTransport.terminate_sessionC  s      	F		A++--G#]]48W]EEEEEEEEH#s**HIIIII%Z77Th>RTTUUUUU 87 	A 	A 	ANN?#??@@@@@@@@@	As   AB *+B 
C#CCc                     | j         S )zGet the current session ID.)r0   )rC   s    r*   get_session_idz&StreamableHTTPTransport.get_session_idS  s
    r)   )NrE   rF   N)NNF)F)Nr   )/r$   r%   r&   r'   r
   r9   rD   r   r;   r<   r   r6   AuthrM   r	   rZ   r   r   rb   rd   Responserk   rt   r   r:   r   r   r   r   r7   r   r.   r   r   r   r   intr   r   r   StreamReaderr   r   r   r   r   r   r(   r)   r*   r>   r>   X   s       99-C-D--- X-Z	<  *.%'.4"&  c3h$& "	
  )+ j4 
  	  X
  &&% &%&% &% 	&%
 &% &% 
&% &% &% &%P$sCx.    "`. `T ` ` ` `tN tt t t t tC.C 
C C C CEE 
E E E E* 15GK"'- -- )- '-	-
 &seYt_&<=D-  - 
- - - -^41!41 )41 
	41 41 41 41lN t    B(n ( ( ( ( (\ #(	/ /./ )/  	/
 
/ / / /2 #(	&S &S.&S &S  	&S
 
&S &S &S &SX )-=` =`=` =` :	=`
 =` 
=` =` =` =`~== )= 
	= = = =7(7 7 
	7 7 7 75(!5( *5( )	5(
 -^<5( #2t8,5( 5( 
5( 5( 5( 5(nAe.? AD A A A A d
      r)   r>   Thttp_clientterminate_on_closer?   r   r   r@   c                 	
K   t          j        t          t          z           d          \  
}t          j        t                   d          \  }}|du}|		t	                      	t          |           t          j                    4 d{V 	 t                              d|             t          j
                    4 d{V }|s|                    	           d{V  d	
fd}                    j        	|
||           	 ||j        fW V  j        r|r                    	           d{V  j                                         nB# j        r|r                    	           d{V  j                                         w xY w	 ddd          d{V  n# 1 d{V swxY w Y   
                                 d{V  |                                 d{V  n9# 
                                 d{V  |                                 d{V  w xY w	 ddd          d{V  dS # 1 d{V swxY w Y   dS )a8  
    Client transport for StreamableHTTP.

    Args:
        url: The MCP server endpoint URL.
        http_client: Optional pre-configured httpx.AsyncClient. If None, a default
            client with recommended MCP timeouts will be created. To configure headers,
            authentication, or other HTTP settings, create an httpx.AsyncClient and pass it here.
        terminate_on_close: If True, send a DELETE request to terminate the session
            when the context exits.

    Yields:
        Tuple containing:
            - read_stream: Stream for reading messages from the server
            - write_stream: Stream for sending messages to the server
            - get_session_id_callback: Function to retrieve the current session ID

    Example:
        See examples/snippets/clients/ for usage patterns.
    r   Nz'Connecting to StreamableHTTP endpoint: r@   c                  @                         j                    d S rB   )r   r   )r/   r3   r   	transports   r*   r   z0streamable_http_client.<locals>.start_get_stream  s#    MM)"=vGYZZZZZr)   )r@   N)r   create_memory_object_streamr   rp   r   r>   create_task_grouprh   r~   
contextlibAsyncExitStackenter_async_contextr   r   r   r0   r   cancel_scopecancelr   )r?   r   r   read_streamr   r   client_providedstackr   r/   r3   r   r   s            @@@@r*   streamable_http_clientr   X  s-     D ',&GYbHb&cde&f&f#(-(I.(YZ[(\(\%L% "-OF~'))',,I&(( "( "( "( "( "( "( "(B!	(LLH3HHIII!022 - - - - - - -e& <33F;;;;;;;;;[ [ [ [ [ [ [ [ [ )'& $  	-#$!0     !+ B0B B'99&AAAAAAAAAO**,,,, !+ B0B B'99&AAAAAAAAAO**,,,,,7- - - - - - - - - - - - - - - - - - - - - - - - - - -: %++---------%%'''''''''' %++---------%%'''''''''''E"( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "( "(sg   I6G7	AF1E>F1?FF1G71
F;	;G7>F;	?G75I76H--I
IIz%Use `streamable_http_client` instead.rE   rF   r4   rG   r5   httpx_client_factoryrH   c                  K   t          |t                    r|                                n|}t          |t                    r|                                n|} ||t          j        ||          |          }	|	4 d {V  t          | |	|          4 d {V 	 }
|
W V  d d d           d {V  n# 1 d {V swxY w Y   d d d           d {V  d S # 1 d {V swxY w Y   d S )N)read)r4   rG   rH   r   )r^   r   total_secondsr6   Timeoutr   )r?   r4   rG   r5   r   r   rH   timeout_secondssse_read_timeout_secondsr/   streamss              r*   streamablehttp_clientr     s.     & 2<GY1O1O\g++---U\O,67G,S,Si&&(((Yi 
 "!o4LMMM  F         )1
 
 
 	 	 	 	 	 	 	 	 MMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                             s6   CB5#C5
B?	?CB?	C
C#&C#)Mr'   r   loggingcollections.abcr   r   r   r   dataclassesr   datetimer   typingr	   r
   warningsr   r   r6   	anyio.abcr   anyio.streams.memoryr   r   	httpx_sser   r   r   typing_extensionsr   mcp.shared._httpx_utilsr   r   mcp.shared.messager   r   	mcp.typesr   r   r   r   r   r   r   r   	getLoggerr$   rh   rp   SessionMessageOrErrorr:   r   r9   GetSessionIdCallbackrX   rY   r   r   r   rW   rV   rT   rU   objectrM   r"   r,   r.   r>   r7   r   tupler   r;   r<   r   r   r(   r)   r*   <module>r     s         ? ? ? ? ? ? ? ? ? ? * * * * * * ! ! ! ! ! !                                     R R R R R R R R @ @ @ @ @ @ @ @ @ @ ( ( ( ( ( (        E D D D D D D D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
	8	$	$ '2 %&;<(8C$J/ !-  !%  	  
> > > > >) > > >5 5 5 5 5) 5 5 5 	* 	* 	* 	* 	* 	* 	* 	*} } } } } } } }@  -1#	P( P( P(	P( "T)P( 	P(
 	!.9"<=~.	
 	
P( P( P( P(f 344 &*!#*0#1G"$ $	$#s(^d"$ Y$ i'	$
 $ /$ *t
$ 	!.9"<=~.	
 	
$ $ $ 54 $ $ $r)   