+
    ÆÚjÀ+  ã                   óz  € R t ^ RIt^ RIHtHtHt ^ RIHtHtH	t	H
t
Ht ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ]P(                  ! ]4      t. ROt]
! R]RR7      tR R ltR R lt ! R R]4      t ! R R]	RR7      t] ! R R
]4      4       t ! R R]]],          4      t]]],          ]]]]3,          R,          .]] ]]3,          ,          3,          t! ]]],          ]]]]3,          R,          .]R,          3,          t" ]]]]]3,          R,          .]#3,          t$ R R lt% ! R R	]]],          4      t&R# )a3  Dispatcher Protocol - the call/return boundary between transports and handlers.

A Dispatcher turns a duplex message channel into two things:

* an outbound API: `send_raw_request(method, params)` and `notify(method, params)`
* an inbound pump: `run(on_request, on_notify)` that drives the receive loop
  and invokes the supplied handlers for each incoming request/notification

It is deliberately *not* MCP-aware. Method names are strings, params and
results are `dict[str, Any]`. The MCP type layer (request/result models,
capability negotiation, `Context`) sits above this; the wire encoding
(JSON-RPC, gRPC, in-process direct calls) sits below it.

See `JSONRPCDispatcher` for the production implementation and
`DirectDispatcher` for an in-memory implementation used in tests and for
embedding a server in-process.
N)Ú	AwaitableÚCallableÚMapping)ÚAnyÚProtocolÚ	TypedDictÚTypeVarÚruntime_checkable©Ú	RequestId©ÚMessageMetadata)ÚTransportContextÚCallOptionsÚDispatchContextÚ
DispatcherÚOutboundÚProgressFnTÚTransportT_coT)ÚboundÚ	covariantc                ó>   € V ^8„  d   QhR\         R\        R,          /# )é   ÚvalueÚreturnN)Úobjectr   )Úformats   "ÚŒ/opt/data/installs/351f81cc06284494/environments/aa258815729c481f8402f54f4c368f83/venv/lib/python3.14/site-packages/mcp/shared/dispatcher.pyÚ__annotate__r   1   s   € ÷ ñ œð ¤I°Õ$4ñ ó    c                óx   € \        V \        \        ,          4      '       d   \        V \        4      '       g   V # R# )zeNarrow an untyped wire value to a `RequestId`, or None; rejects bool (True would alias request id 1).N)Ú
isinstanceÚstrÚintÚbool)r   s   &r   Úas_request_idr%   1   s'   € ä�%œœs�×#Ò#¬J°u¼d×,CÒ,CØˆÙr   c                ó0   € V ^8„  d   QhR\         R\         /# )r   Ú
request_idr   r
   )r   s   "r   r   r   8   s   € ÷ ñ ¤)ð ´	ñ r   c                ón   € \        V \        4      '       d    \        V 4      # V #   \         d     T # i ; i)a  Coerce a stringified int request id back to int so a peer-echoed id still correlates (matches the TS SDK).

This is the collision/correlation domain dispatchers share: "7" and 7 are one
id for correlation purposes, even where the wire carries the verbatim value.
)r!   r"   r#   Ú
ValueError)r'   s   &r   Úcoerce_request_idr*   8   sB   € ô �*œc×"Ò"ð	Ü�z“?Ð"ð Ðøô ô 	ØØÐð	ús   ˜
% ¥4³4c                   ó6   a € ] tR t^Ft o RtV 3R lR ltRtV tR# )r   zLCallback invoked when a progress notification arrives for a pending request.c                óL   <€ V ^8„  d   QhRS[ RS[ R,          RS[R,          RR/# ©r   ÚprogressÚtotalNÚmessager   ©Úfloatr"   )r   Ú__classdict__s   "€r   r   ÚProgressFnT.__annotate__I   s'   ø€ ×dÑd¡uÐd±U¸Tµ\ÐdÉCÐRVÍJÐdÐ[_Ñdr   c              ƒ  ó   "  € R # 5i©N© ©Úselfr.   r/   r0   s   &&&&r   Ú__call__ÚProgressFnT.__call__I   s   é € Ñadùó   ‚r7   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r:   Ú__static_attributes__Ú__classdictcell__©r3   s   @r   r   r   F   s   ø‡ € ÙVçdÖdr   c                   ó>   a € ] tR t^Lt o Rt       V 3R ltRtV tR# )r   zzPer-call options for `Outbound.send_raw_request`.

All keys are optional. Dispatchers ignore keys they do not understand.
c                óª   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[;R&   S[S[.S[R,          3,          ;R&   S[S[S[3,          ;R&   # )	r   r'   ÚtimeoutÚcancel_on_abandonÚon_progressÚresumption_tokenNÚon_resumption_tokenÚheaders)r   r2   r$   r   r"   r   r   Údict)r   r3   s   "€r   r   ÚCallOptions.__annotate__L   s   ø‡ ‚ ñ Ññ ñ0 �Nñ1 ñ6 Ññ7 ñD ÑñE ñJ ÑñK ñ^ "¡3 %©°4­Ð"8Õ9Ñ9ñ_ ñr ‘#‘s�(�^Ñòs r   r7   N)r=   r>   r?   r@   rA   Ú__annotate_func__rB   rC   rD   s   @r   r   r   L   s8   ø‡ € ñðð$ ]ðð Eððð s÷u ƒ r   F)r/   c                   óP   a € ] tR t^‰t o RtRV 3R lR lltRV 3R lR lltRtV tR# )	r   a1  Anything that can send requests and notifications to the peer.

Both `Dispatcher` (top-level outbound) and `DispatchContext` (back-channel
during an inbound request) extend this. The MCP type layer (`ClientPeer`,
`Connection`) builds typed `send_request` / convenience methods on top of
this raw channel.
Nc          
      óz   <€ V ^8„  d   QhRS[ RS[S[ S[3,          R,          RS[R,          RS[S[ S[3,          /# ©r   ÚmethodÚparamsNÚoptsr   )r"   r   r   r   rM   )r   r3   s   "€r   r   ÚOutbound.__annotate__“   sN   ø€ ÷ ñ áðñ ™™S˜Õ! DÕ(ðñ ˜DÕ ð	ñ
 
‰c‘3ˆh�ñr   c              ƒ  ó   "  € R# 5i)zøSend a request and await its raw result dict.

Raises:
    MCPError: If the peer responded with an error, or the handler
        raised. Implementations normalize all handler exceptions to
        `MCPError` so callers see a single exception type.
Nr7   ©r9   rS   rT   rU   s   &&&&r   Úsend_raw_requestÚOutbound.send_raw_request“   s
   é € ñ 	ùr<   c                ób   <€ V ^8„  d   QhRS[ RS[S[ S[3,          R,          RS[R,          RR/# rR   )r"   r   r   r   )r   r3   s   "€r   r   rV   ¢   s?   ø€ ÷ ñ ¡3ð ±¹¹S¸Õ0AÀDÕ0Hð ÑP[Ð^bÕPbð Ðnrñ r   c              ƒ  ó   "  € R# 5i)z$Send a fire-and-forget notification.Nr7   rX   s   &&&&r   ÚnotifyÚOutbound.notify¢   s   é € áùr<   r7   r6   )	r=   r>   r?   r@   rA   rY   r]   rB   rC   rD   s   @r   r   r   ‰   s#   ø‡ € ñ÷ò ÷÷ ð r   c                   óÆ   a € ] tR t^§t o Rt]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR	 l4       t	]V 3R
 lR l4       t
RV 3R lR lltRtV tR# )r   a#  Per-request context handed to `on_request` / `on_notify`.

Carries the transport metadata for the inbound message and provides the
back-channel for sending requests/notifications to the peer while handling
it. `send_raw_request` raises `NoBackChannelError` if `can_send_request`
is `False`.
c                ó    <€ V ^8„  d   QhRS[ /# ©r   r   )r   )r   r3   s   "€r   r   ÚDispatchContext.__annotate__±   s   ø€ ÷ ñ ™=ñ r   c                ó   € R# )z5Transport-specific metadata for this inbound message.Nr7   ©r9   s   &r   Ú	transportÚDispatchContext.transport°   ó   € ñ 	r   c                ó    <€ V ^8„  d   QhRS[ /# ra   )r$   )r   r3   s   "€r   r   rb   ¶   s   ø€ ÷ ñ ¡$ñ r   c                ó   € R# )a  Whether the back-channel can currently deliver server-initiated requests.

`False` when the transport has no back-channel, or when this context has
been closed (the inbound request finished). `send_raw_request` raises
`NoBackChannelError` exactly when this is `False`.
Nr7   rd   s   &r   Úcan_send_requestÚ DispatchContext.can_send_requestµ   ó   € ñ 	r   c                ó.   <€ V ^8„  d   QhRS[ R,          /# )r   r   Nr
   )r   r3   s   "€r   r   rb   À   s   ø€ ÷ ñ ™I¨Õ,ñ r   c                ó   € R# )a  The id of the inbound request, or `None` for a notification.

For JSON-RPC this is the wire `id` field. Handlers thread it through
as `related_request_id` on outbound notifications so HTTP transports
can route them onto the originating request's response stream.
Nr7   rd   s   &r   r'   ÚDispatchContext.request_id¿   rl   r   c                ó    <€ V ^8„  d   QhRS[ /# ra   r   )r   r3   s   "€r   r   rb   Ê   s   ø€ ÷ 
ñ 
¡/ñ 
r   c                ó   € R# )au  The metadata the transport attached to this inbound message, if any.

This is `SessionMessage.metadata` passed through verbatim: HTTP
transports attach `ServerMessageMetadata` (the HTTP request, SSE
stream-close callbacks); stdio and in-memory dispatch attach nothing.
Tied to the `SessionMessage` wire format - goes away when transports
stop delivering messages that way.
Nr7   rd   s   &r   Úmessage_metadataÚ DispatchContext.message_metadataÉ   s   € ñ 	r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# ra   )ÚanyioÚEvent)r   r3   s   "€r   r   rb   ×   s   ø€ ÷ ñ ¡%§+¡+ñ r   c                ó   € R# )zCSet when the peer sends `notifications/cancelled` for this request.Nr7   rd   s   &r   Úcancel_requestedÚ DispatchContext.cancel_requestedÖ   rg   r   Nc                óL   <€ V ^8„  d   QhRS[ RS[ R,          RS[R,          RR/# r-   r1   )r   r3   s   "€r   r   rb   Û   s5   ø€ ÷ ñ ¡uð ±U¸Tµ\ð ÑSVÐY]ÕS]ð Ðimñ r   c              ƒ  ó   "  € R# 5i)zuReport progress for the inbound request, if the peer supplied a progress token.

A no-op when no token was supplied.
Nr7   r8   s   &&&&r   r.   ÚDispatchContext.progressÛ   s
   é € ñ
 	ùr<   r7   )NN)r=   r>   r?   r@   rA   Úpropertyre   rj   r'   rr   rx   r.   rB   rC   rD   s   @r   r   r   §   s}   ø‡ € ñð ÷ó ðð ÷ó ðð ÷ó ðð ÷
ó ð
ð ÷ó ð÷÷ ð r   c                ó†   € V ^8„  d   QhR\         R,          R\        R\        \        \        3,          R,          R\        /# )r   Ú	interceptNrS   rT   r   )ÚOnNotifyInterceptr"   r   r   r$   )r   s   "r   r   r   ò   sB   € ÷ ñ Ô$5¸Õ$<ð Äcð ÔSZÔ[^Ô`cÐ[cÕSdÐgkÕSkð Ôptñ r   c                óp   € V f   R#  V ! W4      #   \          d    \        P                  RT4        R# i ; i)zYInvoke `intercept`, containing a raise to that one notification (never the receive loop).Fz1notification intercept raised; passing %r through)Ú	ExceptionÚloggerÚ	exception)r   rS   rT   s   &&&r   Úrun_notify_interceptr…   ò   s>   € àÒÙðÙ˜Ó(Ð(øÜô Ü×ÑÐLÈfÔUÚðús   ˆ �!5´5c                   óV   a € ] tR t^ýt o RtRR]P                  /V 3R lR llltRtV t	R# )r   a+  A duplex request/notification channel with call-return semantics.

Implementations own correlation of outbound requests to inbound results, the
receive loop, per-request concurrency, and cancellation/progress wiring.

The lifecycle surface is provisional; `run()` may change in a 2.x minor
release.
NÚtask_statusc          
      óz   <€ V ^8„  d   QhRS[ RS[RS[R,          RS[P                  P
                  R,          RR/# )r   Ú
on_requestÚ	on_notifyÚon_notify_interceptNr‡   r   )Ú	OnRequestÚOnNotifyr€   ru   ÚabcÚ
TaskStatus)r   r3   s   "€r   r   ÚDispatcher.__annotate__  sQ   ø€ ÷ ñ áðñ ðñ /°Õ5ð	ñ —Y‘Y×)Ñ)¨$Õ/ðð 
ñr   c             ƒ  ó   "  € R# 5i)a6  Drive the receive loop until the underlying channel closes.

Each inbound request is dispatched to `on_request` in its own task;
the returned dict (or raised `MCPError`) is sent back as the response.
Implementations MUST offer every inbound notification to
`on_notify_intercept` synchronously in receive order (via
`run_notify_intercept`), handing only unconsumed ones to `on_notify`.

`task_status.started()` is called once the dispatcher is ready to
accept `send_request`/`notify` calls, so callers can use
`await tg.start(dispatcher.run, on_request, on_notify)`.
Nr7   )r9   r‰   rŠ   r‹   r‡   s   &&&&$r   ÚrunÚDispatcher.run  s
   é € ñ( 	ùr<   r7   r6   )
r=   r>   r?   r@   rA   ru   ÚTASK_STATUS_IGNOREDr’   rB   rC   rD   s   @r   r   r   ý   s)   ø‡ € ññð 38×2KÑ2K÷÷ ñ r   )r   r   r   r�   r€   rŒ   r   r   r%   r*   r…   )'rA   ÚloggingÚcollections.abcr   r   r   Útypingr   r   r   r   r	   ru   Ú	anyio.abcÚ	mcp_typesr   Úmcp.shared.messager   Úmcp.shared.transport_contextr   Ú	getLoggerr=   rƒ   Ú__all__r   r%   r*   r   r   r   r   r"   rM   rŒ   r�   r$   r€   r…   r   r7   r   r   Ú<module>rž      sb  ðñó$ ß 8Ñ 8ß GÕ Gã Û Ý å .Ý 9à	×	Ò	˜8Ó	$€ò€ñ ˜Ð/?È4ÔP€õõôe�(ô eô:s�) 5õ :sðz ôˆxó ó ðô:9�h ¨Õ 7ô 9ðx �oÐ&6Õ7¸¸gÀcÈ3ÀhÕ>OÐRVÕ>VÐWÐYbÐcgÐhkÐmpÐhpÕcqÕYrÐrÕs€	Ø rà�_Ð%5Õ6¸¸WÀSÈ#ÀXÕ=NÐQUÕ=UÐVÐXaÐbfÕXgÐgÕh€Ø Aà˜c 7¨3°¨8Õ#4°tÕ#;Ð<¸dÐBÕCÐ ðõô�˜8 MÕ2ö r   