+
    wiA                         ^ RI t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
 ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIHt ^ R	IHt ^ RIHt ^ R
IHtHt ^ RIHt ] P:                  ! ]4      tR R lt R R lt!]R^R]RR3R R ll4       t"R# )    N)Callable)asynccontextmanager)Any)parse_qsurljoinurlparse)
TaskStatus)MemoryObjectReceiveStreamMemoryObjectSendStream)aconnect_sse)SSEError)McpHttpClientFactorycreate_mcp_http_client)SessionMessagec                0    V ^8  d   QhR\         R\         /# )   urlreturnstr)formats   "B/home/ubuntu/.local/lib/python3.14/site-packages/mcp/client/sse.py__annotate__r      s     , ,s ,s ,    c                 @    \        V \        V 4      P                  4      # )N)r   r   path)r   s   &r   remove_request_paramsr      s    3**++r   c                >    V ^8  d   QhR\         R\         R,          /# )r   endpoint_urlr   Nr   )r   s   "r   r   r      s"     a aC aC$J ar   c                     \        \        V 4      P                  4      pVP                  R R.4      ^ ,          ;'       g    VP                  RR.4      ^ ,          # )	sessionIdN
session_id)r   r   queryget)r   query_paramss   & r   !_extract_session_id_from_endpointr&      sP    H\2889LK$03``|7G7GW[V\7]^_7``r   c                    V ^8  d   QhR\         R\        \         \        3,          R,          R\        R\        R\        R\
        P                  R,          R\        \         .R3,          R,          /# )	r   r   headersNtimeoutsse_read_timeouthttpx_client_factoryauthon_session_created)r   dictr   floatr   httpxAuthr   )r   s   "r   r   r      s}     E( E(	E(#s(^d"E( E( 	E(
 /E( **t
E( !#-4E(r   c               b  a aaaaaa"   \         P                  ! ^ 4      w  op\         P                  ! ^ 4      w  oo\         P                  ! 4       ;_uu_4       GRj  xL
 p \        P	                  R\        S 4       24       V! W\        P                  ! W#R7      R7      ;_uu_4       GRj  xL
 o\        SRS 4      ;_uu_4       GRj  xL
 oSP                  P                  4        \        P	                  R4       \         P                  3R VVVV 3R lllp	R	 VVV3R
 llp
VP                  V	4      G Rj  xL
 p\        P	                  RV 24       VP                  W4        VS35x  VP                  P                  4        RRR4      GRj  xL
  RRR4      GRj  xL
  SP!                  4       G Rj  xL
  SP!                  4       G Rj  xL
  RRR4      GRj  xL
  R#  EL ELC EL( L  TP                  P                  4        i ; i L  + GRj  xL 
 '       g   i     L; i L  + GRj  xL 
 '       g   i     L; i L L~  SP!                  4       G Rj  xL 
  SP!                  4       G Rj  xL 
  i ; i L  + GRj  xL 
 '       g   i     R# ; i5i)a  
Client transport for SSE.

`sse_read_timeout` determines how long (in seconds) the client will wait for a new
event before disconnecting. All other HTTP operations are controlled by `timeout`.

Args:
    url: The SSE 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.
    on_session_created: Optional callback invoked with the session ID when received.
NzConnecting to SSE endpoint: )read)r(   r,   r)   GETzSSE connection establishedc                :    V ^8  d   QhR\         \        ,          /# )r   task_status)r	   r   )r   s   "r   r    sse_client.<locals>.__annotate__M   s     7> 7>%/_7>r   c                   <"    SP                  4         R j  xL
  p\        P                  RVP                   24       VP                  ;R8X  d    \	        SVP
                  4      p\        P                  RV 24       \        S4      p\        V4      pVP                  VP                  8w  g   VP                  VP                  8w  d&   RV 2p\        P                  V4       \        V4      hS'       d   \        V4      pV'       d	   S! V4       V P                  V4       EK  R8X  d   VP
                  '       g   EK0   \        P                  P                  VP
                  4      p\        P                  RV 24       \'        T4      p	SP%                  T	4      G R j  xL
  EK   \        P)                  RVP                   24       EK   EL  \          d<   p\        P#                  R4       SP%                  T4      G R j  xL 
   R p?EK  R p?ii ; i LyEDMl  \*         d   p
\        P#                  R	4       T
hR p
?
i\          d:   p\        P#                  R
4       SP%                  T4      G R j  xL 
   R p?MR p?ii ; iSP-                  4       G R j  xL 
  R #   SP-                  4       G R j  xL 
  i ; i5i)NzReceived SSE event: endpointzReceived endpoint URL: z2Endpoint origin does not match connection origin: messagezReceived server message: zError parsing server messagezUnknown SSE event: zEncountered SSE exceptionzError in sse_reader)	aiter_sseloggerdebugeventr   datar   netlocschemeerror
ValueErrorr&   startedtypesJSONRPCMessagemodel_validate_json	Exception	exceptionsendr   warningr   aclose)r6   sser   
url_parsedendpoint_parsed	error_msgr"   r:   excsession_messagesse_excevent_sourcer-   read_stream_writerr   s   &          r   
sse_readersse_client.<locals>.sse_readerM   sF    4>-9-C-C-E +Z +Zc &/CCII;-O P&)ii)37>sCHH7M(.7N|n5](^5=c]
:B<:P,6,=,=AWAW,W/9/@/@ODZDZ/Z 3eeqdr0s -6 -3LL,C2<Y2G,G+=9Z[g9hJ/90B:0N(3(;(;L(I)2/2xxx,4)56;6J6J6^6^037.G -3LL;TU\T]9^,_ ;I:Q.@.E.Eo.V(V(V)*(.9LSYYK7X(YW+ZF 09 )5,2,<,<=[,\2D2I2I#2N,N,N,4)5 )WS .FX  ( *",,-HI")M( ?",,-BC"4"9"9#">>>? #5";";"==="4";";"===s   K
H% H"GH"CH% ;AH% H% AGH% &H '-H% H"H")HHHH% HH% "H% $J, %J0IJJ)J	>J?J	J, 	JJ, K
$J'%K
,K KKK
c                $    V ^8  d   QhR\         /# )r   r   r   )r   s   "r   r   r7      s     8 8 8r   c                 z  <"    S;_uu_4       GR j  xL
  S  R j  xL
  p\         P                  RV 24       SP                  V VP                  P	                  RRRR7      R7      G R j  xL
 pVP                  4        \         P                  RVP                   24       K   L L L<DR R R 4      GR j  xL 
  MB  + GR j  xL 
 '       g   i     M); i  \         d    \         P                  R4        Mi ; iSP                  4       G R j  xL 
  R #   SP                  4       G R j  xL 
  i ; i5i)NzSending client message: Tjson)by_aliasmodeexclude_none)rZ   z"Client message sent successfully: zError in post_writer)
r<   r=   postr:   
model_dumpraise_for_statusstatus_coderH   rI   rL   )r   rR   responseclientwrite_streamwrite_stream_readers   &  r   post_writersse_client.<locals>.post_writer   s    8':':':=P !n !n/$*LL3KOK\1]$^5;[[(4-<-D-D-O-O59179= .P .* 6A 6& 0&H %-$=$=$?$*LL3UV^VjVjUk1l$m (;!n0& >Q (;':':':':':  ) E",,-CDE #/"5"5"777,"5"5"777s   D;C B'C C B-B)
B-AC .B+
/8C 'C )B-+C -C .C 9B<:C ?D  C	C	
C	C	C D C  C?<D >C??D D;DD;D81D42D88D;z(Starting post writer with endpoint URL: )anyiocreate_memory_object_streamcreate_task_groupr<   r=   r   r0   Timeoutr   rb   r`   TASK_STATUS_IGNOREDstart
start_sooncancel_scopecancelrL   )r   r(   r)   r*   r+   r,   r-   read_streamtgrV   rf   r   rc   rT   rU   rd   re   s   f&&&&&f     @@@@@r   
sse_clientrs      s    < ',&G&G&J#(-(I(I!(L%L%&&(((Bd	(LL78Mc8R7STU+EMM'4a  '   " ))::<LL!=> 8=7P7P7> 7>r8 8( *,*)=#=LLL#KL>!Z[MM+<1)<77..0y  B %++---%%'''K )((j $> ..0y      B .' %++---%%'''K )(((sj  AJ/G/J/!J#AI/G20I3H9	G5H9	A,H=G8>-H,G:3HH9	HH9	I(H7)I-J IJIJJ/(J)J/2I5H9	8H:HHH9	H4!H$"
H4-H4/H9	7I9I?I 
IIIJJJ-I0.JJ	JJJ/J,	J
J,	$J,	&	J/i,  )#loggingcollections.abcr   
contextlibr   typingr   urllib.parser   r   r   rh   r0   	anyio.abcr	   anyio.streams.memoryr
   r   	httpx_sser   httpx_sse._exceptionsr   	mcp.typesrE   mcp.shared._httpx_utilsr   r   mcp.shared.messager   	getLogger__name__r<   r   r&   rs    r   r   <module>r      sw     $ *  4 4     R " *  P -			8	$,a
  &*$1G"7;E( E(r   