+
    ÆÚj+-  ã                  ó¢  € R t ^ RIHt ^ RIHtHtHtHt ^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIt^ RIt^ RIHt ^ RIHt ^ R	IHt ^ R
IHtHtHtHtHtHt ]'       d   ^ RIH t  . ROt!]! ^4      t" Rt# ]R,          t$ ! R R]%4      t& ! R R]%4      t' ! R R4      t(]].]R,          3,          t)  ! R R4      t*]	RRRRRRRRRR/R R ll4       t+R# ) aš  Client-side `subscriptions/listen` driver (2026-07-28, SEP-2575).

`listen()` opens the stream as an async context manager: entering waits for
the server's acknowledgment, iteration yields typed change events, a graceful
server close ends the loop, and an abrupt drop raises `SubscriptionLost`.
There is no replay and no automatic re-listen: a client that re-opens a
subscription refetches what it depends on.
)Úannotations)ÚAsyncIteratorÚ	AwaitableÚCallableÚSequence)Úasynccontextmanager)Úcount)ÚTYPE_CHECKINGÚLiteralN)ÚMODERN_PROTOCOL_VERSIONS)ÚCallOptions)ÚMCPError)ÚPromptsListChangedÚResourcesListChangedÚResourceUpdatedÚServerEventÚToolsListChangedÚevent_matches)ÚClientSessionÚListenNotSupportedErrorÚSubscriptionÚSubscriptionLosti   c                  ó2   a € ] tR t^;tRtR V 3R lltRtV ;t# )r   z8`subscriptions/listen` requires a 2026-07-28 connection.c               ó    € V ^8„  d   QhRRRR/# )é   Únegotiated_versionz
str | NoneÚreturnÚNone© )Úformats   "Ú�/opt/data/installs/351f81cc06284494/environments/aa258815729c481f8402f54f4c368f83/venv/lib/python3.14/site-packages/mcp/client/subscriptions.pyÚ__annotate__Ú$ListenNotSupportedError.__annotate__>   s   € ÷ 
ñ 
¨:ð 
¸$ñ 
ó    c                	ó<   <€ Wn         \        SV `	  R V: R24       R# )z:subscriptions/listen is not available at protocol version z†; it requires 2026-07-28. On earlier versions use subscribe_resource() and the change notifications delivered through message_handler.N)r   ÚsuperÚ__init__)Úselfr   Ú	__class__s   &&€r    r&   Ú ListenNotSupportedError.__init__>   s*   ø€ Ø"4ÔÜ‰ÑØHÐI[ÑH^ð _'ð 'ö	
r#   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r&   Ú__static_attributes__Ú__classcell__)r(   s   @r    r   r   ;   s   ø† ÙB÷
ö 
r#   c                  ó   € ] tR t^GtRtRtR# )r   zLThe stream ended without the server's graceful close; re-listen and refetch.r   N)r*   r+   r,   r-   r.   r/   r   r#   r    r   r   G   s   † ÝVr#   c                  óf   € ] tR t^KtRtR R ltR R ltR R ltRR	 R
 lltR R lt	R R lt
RtR# )ÚListenRoutezfPackage-internal demux state for one listen stream, fed synchronously in receive order by the session.c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r    r!   ÚListenRoute.__annotate__N   s   € ÷ #ñ #˜$ñ #r#   c                	óÄ   € R V n         \        P                  ! 4       V n        R V n        R V n        \        4       V n        / V n        \        P                  ! 4       V n	        R # ©N)
ÚhonoredÚanyioÚEventÚackedÚerrorÚendÚ	frozensetÚ_honored_urisÚ_pendingÚ_wake©r'   s   &r    r&   ÚListenRoute.__init__N   sB   € Ø8<ˆŒÜ—[’[“]ˆŒ
Ø&*ˆŒ
Ø,0ˆŒÜ-6«[ˆÔØ13ˆŒÜ—[’[“]ˆŽ
r#   c               ó    € V ^8„  d   QhRRRR/# )r   r9   útypes.SubscriptionFilterr   r   r   )r   s   "r    r!   r6   W   s   € ÷ ñ Ð!9ð ¸dñ r#   c                óÒ   € V P                   P                  4       '       gG   Wn        \        VP                  ;'       g    R4      V n        V P                   P                  4        R# R# )z3Record the acknowledged filter; the first ack wins.Nr   )r<   Úis_setr9   r?   Úresource_subscriptionsr@   Úset)r'   r9   s   &&r    Ú	set_ackedÚListenRoute.set_ackedW   sH   € à�z‰z× Ñ ×"Ò"Ø"ŒLÜ!*¨7×+IÑ+I×+OÐ+OÈRÓ!PˆDÔØ�J‰J�N‰NÖñ #r#   c               ó    € V ^8„  d   QhRRRR/# ©r   Úeventr   r   r   r   )r   s   "r    r!   r6   ^   s   € ÷ ñ ˜[ð ¨Tñ r#   c           	     ó  € V P                   f   V P                  f   R# \        V\        4      '       d   \	        V P
                  4      pM!\        V P                  V P
                  V4      pV'       d   WP                  9   d   R# \        V P                  4      \        8¼  d6   V P                  R\        \        P                  R\         R24      R7       R# RV P                  V&   V P                  P                  4        R# )zåQueue an event within the honored filter, deduplicated against the backlog.

Any `ResourceUpdated` is admitted once URI subscriptions were honored at
all: the spec allows the stamped URI to be a sub-resource of a subscribed one.
NÚlostzsubscription backlog exceeded z) unconsumed events; re-listen and refetch©r=   )r>   r9   Ú
isinstancer   Úboolr@   r   rA   ÚlenÚ_MAX_PENDING_EVENTSÚsettler   ÚtypesÚINTERNAL_ERRORrB   rJ   )r'   rO   Úadmitteds   && r    ÚdeliverÚListenRoute.deliver^   sÅ   € ð �8‰8Ò 4§<¡<Ò#7ÙÜ�eœ_×-Ò-Ü˜D×.Ñ.Ó/‰Hä$ T§\¡\°4×3EÑ3EÀuÓMˆHß˜5§M¡MÔ1ÙÜˆt�}‰}ÓÔ!4Ô4Ø�K‰KØÜÜ×(Ñ(Ø4Ô5HÐ4IÐIrÐsóð ô ñ Ø#ˆ�‰�eÑØ�
‰
�‰Ör#   Nc               ó$   € V ^8„  d   QhRRRRRR/# )r   r>   Ú_SubscriptionEndr=   zMCPError | Noner   r   r   )r   s   "r    r!   r6   x   s"   € ÷ ñ Ð*ð °?ð Èdñ r#   c                ó¦   € V P                   fC   Wn         W n        V P                  P                  4        V P                  P                  4        R# R# )zFRecord the stream's end; the first reason wins and wakes both waiters.N)r>   r=   r<   rJ   rB   )r'   r>   r=   s   &&&r    rW   ÚListenRoute.settlex   s7   € à�8‰8ÒØŒHØŒJØ�J‰J�N‰NÔØ�J‰J�N‰NÖñ	 r#   c               ó   € V ^8„  d   QhRR/# )r   r   zServerEvent | _SubscriptionEndr   )r   s   "r    r!   r6   €   s   € ÷ 'ñ 'Ð"@ñ 'r#   c              ƒ  ó^  "  €  V P                   pV P                  R8X  d   V P                  # V P                  '       d   \        \	        V P                  4      4      # V P                  e   V P                  # VP                  4       G Rj  x€L
  \        P                  ! 4       V n         K¨   L 5i)zÓPeek the next pending event, or the stream's end once the backlog drains.

A "local" end short-circuits the backlog; the other endings drain it first,
so a graceful close never swallows events that preceded it.
ÚlocalN)rB   r>   rA   ÚnextÚiterÚwaitr:   r;   )r'   Úwakes   & r    Ú
next_eventÚListenRoute.next_event€   sy   é € ð à—:‘:ˆDØ�x‰x˜7Ô"Ø—x‘x�Ø�}�}ˆ}ÜœD §¡Ó/Ó0Ð0Ø�x‰xÒ#Ø—x‘x�Ø—)‘)“+×ÐÜŸš›ˆDŽJñ ùs   ‚<B-¿AB-Â
B+Â!B-c               ó    € V ^8„  d   QhRRRR/# rN   r   )r   s   "r    r!   r6   ’   s   € ÷ 'ñ '˜[ð '¨Tñ 'r#   c                ó>   € V P                   P                  VR4       R# )z'Remove a peeked event from the backlog.N)rA   Úpop)r'   rO   s   &&r    ÚconsumeÚListenRoute.consume’   s   € à�‰×Ñ˜% Ö&r#   )r@   rA   rB   r<   r>   r=   r9   r8   )r*   r+   r,   r-   r.   r&   rK   r[   rW   rh   rm   r/   r   r#   r    r3   r3   K   s(   † Ùpõ#õõ÷4õ'÷$'ñ 'r#   r3   c                  óB   € ] tR t^›tRtR
R R lltR R ltR R ltR	tR# )r   z’One open `subscriptions/listen` stream: an async iterator of typed events.

Produced by `listen()` / `Client.listen()`, not constructed directly.
Nc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Úrouter3   Úsubscription_idztypes.RequestIdr9   rF   Úon_eventúOnEvent | Noner   )r   s   "r    r!   ÚSubscription.__annotate__¡   s8   € ÷ Oñ OàðOð )ðOð *ð	Oð
 !ñOr#   c                	ó8   € Wn         W@n        W n         W0n        R # r8   )Ú_routeÚ	_on_eventrr   r9   )r'   rq   rr   r9   rs   s   &&&&&r    r&   ÚSubscription.__init__¡   s   € ð ŒØ!ŒØ.ÔØSØŒÙNr#   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r    r!   ru   ¯   s   € ÷ ñ ˜<ñ r#   c                	ó   € V # r8   r   rC   s   &r    Ú	__aiter__ÚSubscription.__aiter__¯   s   € Øˆr#   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r    r!   ru   ²   s   € ÷ ñ  ñ r#   c              ƒ  ó‚  "  € V P                   P                  4       G Rj  x€L
 p\        V\        4      '       d=   VR8X  d0   \	        RV P
                  : R24      V P                   P                  h\        hV P                  e   V P                  V4      G Rj  x€L
  V P                   P                  V4       V#  Lš L#5i)z˜Yield the next change event; the loop ends when the stream does.

Raises:
    SubscriptionLost: the stream dropped without the server's graceful close.
NrQ   úsubscription zA ended without the server's graceful close; re-listen and refetch)
rw   rh   rS   Ústrr   rr   r=   ÚStopAsyncIterationrx   rm   )r'   Úoutcomes   & r    Ú	__anext__ÚSubscription.__anext__²   s¬   é € ð Ÿ™×.Ñ.Ó0×0ˆÜ�gœs×#Ò#Ø˜&Ô Ü&Ø# D×$8Ñ$8Ñ#;ð <-ð -óð —{‘{×(Ñ(ð)ô %Ð$Ø�>‰>Ò%ð —.‘. Ó)×)Ð)Ø�‰×Ñ˜GÔ$Øˆñ 1ñ *ùs"   ‚B? B;¡A8B?ÂB=Â"B?Â=B?)rx   rw   r9   rr   r8   )	r*   r+   r,   r-   r.   r&   r|   r„   r/   r   r#   r    r   r   ›   s   † ñ÷
Oõ÷ñ r#   Útools_list_changedFÚprompts_list_changedÚresources_list_changedrI   rs   c               ó4   € V ^8„  d   QhRRRRRRRRRRR	R
RR/# )r   Úsessionr   r†   rT   r‡   rˆ   rI   zSequence[str]rs   rt   r   zAsyncIterator[Subscription]r   )r   s   "r    r!   r!   É   sY   € ÷ Q5ñ Q5ØðQ5ð ðQ5ð ð	Q5ð
 !ðQ5ð *ðQ5ð ðQ5ð !ñQ5r#   c              ó  a a	a
aaa"  € S P                   \        9  d   \        S P                   4      h\        V\        4      '       d   \        R4      h\        P                  ! \        P                  ! \        P                  ! T;'       g    RT;'       g    RT;'       g    R\        V4      ;'       g    RR7      R7      R7      pS P                  pVf   \        R4      hR\        \        4       2oVP                  RR	RR
7      o	RS/oS P!                  S	S4       \"        P$                  ! 4       o
R V	V
VVVV 3R llpS P'                  S4      o VP)                  V4       \"        P*                  ! S P,                  4      ;_uu_ 4        SP.                  P1                  4       G Rj  x€L
  RRR4       SP2                  f+   SP4                  e   SP4                  h\7        RS: R24      h\9        SSSP2                  V4      5x € SP;                  R4       S
P=                  4        S P?                  S4       R#  L“  + '       g   i     L™; i  SP;                  R4       S
P=                  4        S P?                  S4       i ; i5i)ax  Open one `subscriptions/listen` stream on `session` (2026-07-28 only).

Entering sends the request and returns once the server's acknowledgment
arrives; exiting ends the subscription. `on_event` is awaited before each
event is returned - the seam `Client.listen` uses to finish cache eviction
before the consumer can refetch.

Raises:
    ListenNotSupportedError: negotiated version predates 2026-07-28.
    MCPError: the server rejected the request, or the connection failed pre-ack.
    SubscriptionLost: the stream ended before it was acknowledged.
    TimeoutError: the session's read timeout elapsed before the acknowledgment.
zBresource_subscriptions takes a sequence of URIs, not a bare stringN)r†   r‡   rˆ   rI   )Únotifications)Úparamsz$listen() requires an entered sessionzlisten-TÚjson)Úby_aliasÚmodeÚexclude_noneÚ
request_idc               ó   € V ^8„  d   QhRR/# r5   r   )r   s   "r    r!   Úlisten.<locals>.__annotate__ö   s   € ÷ %ñ %˜ñ %r#   c               “  ón  <"  € S;_uu_ 4         SP                   P                  SR ,          SP                  R4      S4      G Rj  x€L
  SP                  \        P                  ! 4       4       SP	                  R4       RRR4       R#  LC  \         d'   p SP	                  RT R7        Rp ? RRR4       R# Rp ? i\
         dY   p SP                  S4       SP	                  R\        \        P                  \        T 4      4      R7        Rp ? RRR4       R# Rp ? ii ; i  + '       g   i     R# ; i5i)Úmethodr�   NrQ   rR   Úgraceful)Ú_dispatcherÚsend_raw_requestÚgetr   rW   Ú
ValueErrorÚ_unregister_listen_routerX   rY   r�   rK   ÚSubscriptionFilter)r=   ÚdataÚdriver_scopeÚoptsr’   rq   rŠ   s    €€€€€€r    ÚdriveÚlisten.<locals>.driveö   sì   øé € çŠ\ðØ×)Ñ)×:Ñ:Ø˜•N D§H¡H¨XÓ$6¸ó÷ ð ð �O‰OœE×4Ò4Ó6Ô7Ø�L‰L˜Ô$÷# ‰\ñøô ô Ø—‘˜V¨5�Ô1Û÷ ‰\ûô ô ð ×0Ñ0°Ô<Ø—‘˜V¬8´E×4HÑ4HÌ#ÈeË*Ó+U�ÔVÛ÷ ‰\ûðú÷ �\ˆ\üs|   ƒD5ŽD!�6BÁB
ÁBÁ5D!Â 
D5Â
BÂDÂB8Â*D!Â.
D5Â8DÃDÃADÄD!Ä
D5ÄDÄD!Ä!D2	Ä,	D5r€   z! ended before it was acknowledgedrc   ) Úprotocol_versionr   r   rS   r�   Ú	TypeErrorrX   ÚSubscriptionsListenRequestÚ SubscriptionsListenRequestParamsr�   ÚlistÚ_task_groupÚRuntimeErrorrd   Ú_listen_idsÚ
model_dumpÚ_stampr:   ÚCancelScopeÚ_register_listen_routeÚ
start_soonÚ
fail_afterÚ_session_read_timeout_secondsr<   rf   r9   r=   r   r   rW   Úcancelrœ   )rŠ   r†   r‡   rˆ   rI   rs   ÚrequestÚ
task_groupr¡   rž   rŸ   r    r’   rq   s   f$$$$$   @@@@@r    Úlistenrµ   È   s  ýé € ð. ×ÑÔ'?Ô?Ü% g×&>Ñ&>Ó?Ð?ÜÐ(¬#×.Ò.ÜÐ\Ó]Ð]Ü×.Ò.Ü×5Ò5Ü×2Ò2Ø#5×#=Ð#=¸Ø%9×%AÐ%A¸TØ'=×'EÐ'EÀÜ'+Ð,BÓ'C×'KÐ'KÀtô	ô
ô	€Gð ×$Ñ$€JØÒÜÐAÓBÐBØ$+¬D´Ó,=Ð+>Ð"?€JØ×Ñ t°&ÀtÐÓL€DØ% zÐ2€DØ‡N�N�4˜ÔÜ×$Ò$Ó&€L÷%õ %ð, ×*Ñ*¨:Ó6€Eð5Ø×Ñ˜eÔ$Ü×Ò˜g×CÑC×DÕDØ—+‘+×"Ñ"Ó$×$Ð$÷ Eà�=‰=Ò à�{‰{Ò&Ø—k‘kÐ!Ü" ]°:±.Ð@aÐ#bÓcÐcÜ˜5 *¨e¯m©m¸XÓFÓFà�‰�WÔØ×ÑÔØ×(Ñ(¨Ö4ñ %÷ E×Dûð 	�‰�WÔØ×ÑÔØ×(Ñ(¨Õ4üsb   ˆBJÂ
JÂ
JÂ#JÂ7BJÅ9I ÆIÆ,I Æ-IÆ1AI È4JÉ IÉI	ÉI É4J	Ê	J)
r   ÚOnEventr   r   r   r   r   r   r   rµ   )r—   rQ   rc   r   ),r.   Ú
__future__r   Úcollections.abcr   r   r   r   Ú
contextlibr   Ú	itertoolsr   Útypingr	   r
   r:   Ú	mcp_typesrX   Úmcp_types.versionr   Úmcp.shared.dispatcherr   Úmcp.shared.exceptionsr   Úmcp.shared.subscriptionsr   r   r   r   r   r   Úmcp.client.sessionr   Ú__all__rª   rV   r^   r©   r   r   r3   r¶   r   rµ   r   r#   r    Ú<module>rÃ      s  ðñõ #ç HÓ HÝ *Ý ß )ã Û Ý 6å -Ý *÷÷ ÷ Ý0ò€ñ �A‹h€Ø eàÐ ð8ð Ð6Õ7Ð ô	
˜lô 	
ôW�|ô W÷I'ñ I'ðX �K�= )¨D¥/Ð1Õ
2€Ø [÷*ñ *ðZ ðQ5ð  %ðQ5ð "'ð	Q5ð
 $)ðQ5ð -/ðQ5ð  $öQ5ó òQ5r#   