xj%UddlmZddlZddlZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZmZmZmZmZmZmZmZmZddlZddlZddlZddlZdd lmZm Z dd lm!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd lm,Z-dd l.m/Z/m0Z0m1Z1m2Z2dd l3m4Z4m5Z5m6Z6m7Z7m8Z8ddl9m:Z:m;Z;mZ>m?Z?ddl@mAZAmBZBmCZCddlDmEZEddlFmGZGddlHmIZImJZJmKZKmLZLmMZMddlNmOZOmPZPddlQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYddlZm[Z[m\Z\ddl]m^Z^m_Z_ddl`maZambZbddlcmdZderddlemfZfejddZhdZidZjd ekd!<ejd"ZmdQd#ZndRd$ZodSd%ZpdTd&ZqdUd'Zrdd( dVd)Zse;d*e4+Zte d,-Gd.d/ZuGd0d1eZvGd2d3eZwGd4d5eZxGd6d7eZyeje{zZ|d8ekd9< Gd:d;eZ}dWd<Z~ dXd=Z dYd>Z dZd?Z d[d@Ze7ejejzZdAekdB<e7ej ejzZdCekdD<e7ejejzZdEekdF<e7ejejzZdGekdH<d\dIZ d]dJZ d^dKZ d_dLZ d`dMZdadNZGdOdPZy)b) annotationsN)CallableMappingSequence) dataclass)reduce)or_) TracebackType) TYPE_CHECKING AnnotatedAnyFinalLiteralProtocol TypeAliascastoverload)MemoryObjectReceiveStreamMemoryObjectSendStream) CLIENT_CAPABILITIES_META_KEYCLIENT_INFO_META_KEYCONNECTION_CLOSEDINTERNAL_ERRORLOG_LEVEL_META_KEYMETHOD_NOT_FOUNDPROTOCOL_VERSION_META_KEYSERVER_INFO_META_KEYUNSUPPORTED_PROTOCOL_VERSION RequestIdRequestParamsMeta)methods)HANDSHAKE_PROTOCOL_VERSIONSLATEST_HANDSHAKE_VERSIONLATEST_MODERN_VERSIONMODERN_PROTOCOL_VERSIONS) BaseModel DiscriminatorTag TypeAdapterValidationError)SelfTypeVar deprecated) ReadStream WriteStream)NotificationBinding ResultClaimUnexpectedClaimedResult) ListenRoute) resync_tracer) CallOptionsDispatchContext Dispatcher ProgressFnT as_request_id)MCPDeprecationWarningMCPError)MCP_METHOD_HEADERMCP_NAME_HEADERMCP_PROTOCOL_VERSION_HEADERNAME_BEARING_METHODSencode_header_valuefind_invalid_x_mcp_headermcp_param_headersx_mcp_header_map)JSONRPCDispatcher cancelled_request_id_from_params)ClientMessageMetadataSessionMessage)SUBSCRIPTION_ID_META_KEYevent_from_wire)TransportContext) Validatormcpz0.1.0)nameversiong$@r_NOTIFICATION_QUEUE_SIZEclientc|jd}t|ttzrt|ts |dkrd|d<yyyy)zjFloor a negative inbound `ttlMs` to 0 before `ge=0` validation fails the call (2026-07-28 caching SHOULD).ttlMsrN)get isinstanceintfloatbool)rawttls f/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/mcp/client/session.py_clamp_inbound_ttlr\IsC ''' C#sU{#JsD,AcAgG GN,A#c`tj|dtj|dk(S)acJSON equality for two output schemas. Python `==` is not JSON equality: it conflates `True`/`1` and `False`/`0`, which JSON Schema keeps distinct (`const: true` vs `const: 1`). Canonical serialization compares as JSON does; where it is stricter (`1` vs `1.0`), erring toward "changed" only costs a recompile, never a stale validator. T) sort_keys)jsondumps)abs r[ _same_schemardPs% ::a4 (DJJqD,I IIr]c|ddvrd|d<yy)Nmethod initializezserver/discoverFcancel_on_abandon)dataoptss r[_preconnect_stamprm[s! H~::$) !;r]c|jxsijt}|y tjj |S#t $rYywxYw)zThe typed identity from a discover result's `_meta` serverInfo stamp. The stamp is display-only per the spec, so absent and malformed both read as `None` rather than failing the connection. N)metarTrtypesImplementationmodel_validater*)resultrYs r[_parse_server_info_stamprtbsT ;; " ! !"6 7C {##22377 sA AAcdfd }|S)Nc8|jdit<y)Nheaders) setdefaultr>)rkrlprotocol_versions r[stampz$_make_handshake_stamp..stamprsFV 2&'BCr]rkdict[str, Any]rlr5returnNonerj)ryrzs` r[_make_handshake_stamprqsW Lr] log_levelc$dfd }|S)Nc`|jdi}|jdi} |t<|t<|t< |jt |ddvrd|d<|jdi} |t <|d|t <tj|d}|3t|j|x}trt||t<|ddk(rNt|jd x}tr,|j ||jd xsiyyy) Nparams_metarfrgFrirwz tools/callrM arguments)rxrrrrr>r<r?rTrUstrr@r=update) rkrlrrorwname_keyrM capabilities client_inforryresolve_param_headerss r[rzz!_make_modern_stamp..stamps12.  "-*: &'%0 !"-9 )*  OO. : >> >(-D$ %//)R0/?+,%)(^!"'++DN;  Jvzz(7K/KtS$Q':4'@GO $ >\ )jFAS9SUX.Y NN0vzz+7N7TRTU V/Z )r]r{rj)ryrrrrrzs````` r[_make_modern_stamprxsWW< Lr]ReceiveResultT)boundT)kw_onlyc4eZdZUdZded<ded<dZded<y) ClientRequestContextz`Context for a server-initiated request, passed to the sampling/elicitation/list-roots callbacks. ClientSessionsessionr request_idNRequestParamsMeta | Nonero)__name__ __module__ __qualname____doc____annotations__rorjr]r[rrsj %)D ")r]rc eZdZ ddZy) SamplingFnTc KywNrjselfcontextrs r[__call__zSamplingFnT.__call__s \_Nrrrz types.CreateMessageRequestParamsr}zPtypes.CreateMessageResult | types.CreateMessageResultWithTools | types.ErrorDatarrrrrjr]r[rrs(_%_1_ Z _r]rc eZdZ ddZy)ElicitationFnTc Kywrrjrs r[rzElicitationFnT.__call__s 03rNrrrztypes.ElicitRequestParamsr}z$types.ElicitResult | types.ErrorDatarrjr]r[rrs#3%3*3 . 3r]rceZdZ ddZy) ListRootsFnTc Kywrrj)rrs r[rzListRootsFnT.__call__s 25rNrrr}z'types.ListRootsResult | types.ErrorDatarrjr]r[rrs6+6 06r]rceZdZddZy) LoggingFnTc Kywrrjrrs r[rzLoggingFnT.__call__rNrz&types.LoggingMessageNotificationParamsr}r~rrjr]r[rrsYr]rrIncomingMessageceZdZddZy)MessageHandlerFnTc Kywrrj)rmessages r[rzMessageHandlerFnT.__call__rrNrrr}r~rrjr]r[rrsCr]rc\Ktjjd{y7wr)anyiolowlevel checkpoint)rs r[_default_message_handlerrs .. # # %%%s ",*,cTKtjtjdSw)NzSampling not supportedcoderrp ErrorDataINVALID_REQUESTrrs r[_default_sampling_callbackrs% ??  " "( &(cTKtjtjdSw)NzElicitation not supportedrrrs r[_default_elicitation_callbackrs% ??  " "+ rcTKtjtjdSw)NzList roots not supportedrr)rs r[_default_list_roots_callbackrs% ??  " "* rc Kywrrjrs r[_default_logging_callbackrs  rz1TypeAdapter[types.ClientResult | types.ErrorData]ClientResponseLTypeAdapter[types.CallToolResult | types.InputRequiredResult | types.Result]_CallToolResultAdapterz>TypeAdapter[types.GetPromptResult | types.InputRequiredResult]_GetPromptResultAdapterzATypeAdapter[types.ReadResourceResult | types.InputRequiredResult]_ReadResourceResultAdaptercR|tvxr|jduxs||jvS)zSA claim is active at modern versions only, narrowed by its optional version subset.N)r%protocol_versions)claimrNs r[ _claim_activer s3 . .  4'M7e6M6M+Mr]c |jDcic]"}|D]}t||r |j|$c}}Scc}}w)zKClaims active at `version`, keyed by wire tag; empty at any legacy version.)valuesr result_type)claims_by_extensionrNclaimsrs r[_active_claims_atrsW *002      ( 5    s'?c |stSt|dvr dz vr dfd }ttjtj zt fg}||jDcgc]#\}}t|jt |f%c}}z }tttt|t|fScc}}w)zSBuild a discriminated tools/call adapter: a core arm plus one arm per active claim.core-ct|trtd|jd}n t |dd}t|t r|vr|SS)Nr| resultTyper)rUdictrrTgetattrr)valuetagcore_armtagss r[_routez(_build_call_tool_adapter.._route'sO eT "'/33LAC%5C c*sd{sHHr])rr r}r) r frozensetr rpCallToolResultInputRequiredResultr(itemsmodelr)rr r')activerarmsrrrrs @@r[_build_call_tool_adapterrs %% V DH d C d I!!5!58Q8Q!QSVW_S`!`abD  O*#uYu{{CH, - OOD yT!2M&4I!IJ KK Ps5(CcNi}t}|xsijD]\}}|||vrtd|d|std|d|D]C}|j|vrtd|j|j |jEt |||<|S)z2Validate and copy the claims-by-extension mapping.zresult_claims key zZ has no extensions entry; a claim is only advertised through its extension's capability adzresult_claims[ze] is empty and would drop the extension from the capability ad at every version. Omit the key insteadz&duplicate result claim for resultType )setr ValueErrorraddtuple) result_claims extensionsindexedseen identifierrrs r[ _index_claimsr6s 8:GUD,299;, F  :!=$ZN3CC  /KK  (E  D( #I%J[J[I^!_`` HHU&& ' ($Fm , Nr]ci}|xsdD]7}|j|vrtd|j|||j<9|S)z4Index bindings by wire method, rejecting duplicates.rjz*duplicate notification binding for method )rfr)notification_bindingsrbindings r[_index_bindingsrPsV46G(.B* >>W $I'..I[\] ]")* Nr]c td|dS)Nz\Server returned InputRequiredResult; pass allow_input_required=True to receive it and retry z?(..., input_responses=..., request_state=result.request_state).) RuntimeError)rfs r[_input_required_unexpectedr\s"  H[ ] r]ceZdZdZ dFddddddd dGdZdHdZ dIdZdJdZ dKdZ dL dMd Z dNd Z dOd Z dPd Z dQd Z dRdZdSdZedTdZedUdZedVdZedWdZedXdZedVdZdddYdZede dZdd d[dZededd d\dZddd]dZdd d^dZedddd d! d_d"Zedddd# d`d$Zdddd d! d`d%Zed&edddad'Z ed(edddad)Z!e dLdddd d d* dbd+Z"e dLdddd d, dcd-Z"e dLdddd d! ddd.Z"e dLdddd# ded/Z" dLdddd d d* ded0Z"dfd1Z#dgd2Z$dhd3Z%dddid4Z&e djdddd d! dkd5Z'e djdddd# dld6Z' djdddd d! dld7Z' dj dmd8Z(dddnd9Z)dod:Z*ed;edJd<Z+ dpd=Z, dqd>Z-drd?Z.dsd@Z/dJdAZ0dtdBZ1 dudCZ2dvdDZ3dvdEZ4y)wraClient half of an MCP connection, running on a `Dispatcher`. Construct it over a transport's stream pair (or pass a pre-built `dispatcher=`), enter as an async context manager, then call `initialize()`. The dispatcher owns the receive loop and request correlation; this class owns the typed MCP layer and the constructor callbacks. Transport `Exception` items reach `message_handler` on any stream-backed dispatcher (`JSONRPCDispatcher`), whether built here from a stream pair or supplied without a stream-exception hook of its own; an in-process `DirectDispatcher` carries none. Extension `result_claims` fold into tools/call parsing at `adopt()`; `notification_bindings` observe vendor notifications via bounded FIFOs. N)rsampling_capabilitiesrrr dispatcherc ||_| xst|_|xst|_| |_| t | nd|_t| | |_ t||_ i|_ t|_i|_|xst |_|xst$|_|xst(|_| |_|xst.|_i|_i|_i|_d|_d|_d|_d|_t@|_!d|_"i|_#|F|| tId||_%tM|tNr|jP|jR|_(yyy|| tIdtO|||jR|_%y)Nz5pass read_stream/write_stream or dispatcher, not bothzEread_stream and write_stream are required when no dispatcher is given)on_stream_exception)*_session_read_timeout_secondsDEFAULT_CLIENT_INFO _client_infor_sampling_callback_sampling_capabilitiesr _extensionsr_result_claimsr_notification_bindings_active_claimsr_call_tool_adapter_binding_queuesr_elicitation_callbackr_list_roots_callbackr_logging_callback _log_levelr_message_handler_tool_output_schemas_tool_output_validators_x_mcp_header_maps_initialize_result_discover_result_discover_server_info_negotiated_versionrm_stamp _task_group_listen_routesr _dispatcherrUrDr _on_stream_exception)r read_stream write_streamread_timeout_secondssampling_callbackelicitation_callbacklist_roots_callbacklogging_callbackmessage_handlerrrrrrrrs r[__init__zClientSession.__init__ss&.B*'>+>"3"Q7Q&;#/9/E4 +4+M:F&56K&L#;="8  &:%Z=Z"$7$W;W!!1!N5N5> / K3KFH!>@$IKAE=ABF"/3 EV 7;<>  !&,*B !XYY0:D *&78Z=[=[=c261J1J .>d8"l&: !hii0\t?X?X D r]cKtj|_|jjd{ |jj D]@}tj tt\}}||f|j|j<B|jj|jj|j|j|j d{|jj D]E}|j|j\}}|jj#|j$||G |S7 7l#t&$r|j}d|_|j(j+d|j(_ |j/dddd{7|j1#|j1wxYwwxYww)NT)rcreate_task_groupr" __aenter__rrcreate_memory_object_streamr&rPrrfstartr$run _on_request _on_notify_intercept_notification start_soon_deliver_bound_notifications BaseException cancel_scopecancelshield __aexit___close_binding_queues)rrsendreceive_ task_groups r[r1zClientSession.__aenter__s 224))+++ 66==? G % A A) LMe f g8r?_settle_listen_routes_closedr4)rexc_typeexc_valexc_tbrss r[r>zClientSession.__aexit__s+++ %%,,. 0++55hPPF  & & (  - - /o Q  & & (  - - /s:3B8 BBB-B8B6 B8B"B33B8c|jjD]%\}}|j|j'|jjyr)rrcloseclear)rr@rAs r[r?z#ClientSession._close_binding_queuessJ!1188: MD' JJL MMO  ""$r]cK |jd{} |j|d{377#t$r#tj d|j Y0wxYww)zYConsume one binding's FIFO, decoupled from the dispatcher so handlers can do session I/O.Nz*notification binding handler for %r raised)rAhandler Exceptionlogger exceptionrf)rrrArs r[r9z*ClientSession._deliver_bound_notificationssc"??,,F _oof---,- _  !Mw~~^ _s:A*7A*;9;A*;)A'$A*&A''A*cK|jddd}|d}i}|j|||jdi} t|jx} at | vrY|j dxsi} | j | } t| tst|d| d t| | t <||n |j} | | |d <|||d <|6|j|j|d <|j|j|d <|jj||j d|d{}t!||j"xsd} t%j&|||t|t*r|j-|dS|j/|dS7m#t($rYCwxYww)a Send a request and wait for its typed result. Args: metadata: Streamable HTTP resumption hints. Raises: MCPError: Error response, read timeout, or connection closed. RuntimeError: Called before entering the context manager. ValueError: The request declares `name_param` but its params carry no string name. pydantic.ValidationError: The server returned a result that does not conform to the negotiated protocol version. Tr`by_aliasmode exclude_nonerfrwNrz requires params[z] for Mcp-Nametimeout on_progressresumption_tokenon_resumption_token 2025-11-25F)by_name) model_dumpr!rxtype name_paramr=rTrUrrr@r rXon_resumption_token_updater$send_raw_requestr\r _methodsvalidate_server_resultKeyErrorr)validate_pythonrr)rrequestrrequest_read_timeout_secondsmetadataprogress_callbackrkrfrlrwkey params_datarMrVrYrNs r[ send_requestzClientSession.send_requests(!!4f4!P8n D$//)R0=++ +C 8_T[=[*.((8*<*BK??3'DdC( F8+!RSS':4'@GO $,7 )33   %DO  ("3D   ((4+3+D+D'(22>.6.Q.Q*+$$55fdhhx>PRVWW3**:l   + +FGS A k; /..sE.B B))#u)==X    s6D=F>?F-F> F/77F>/ F;8F>:F;;F>cK|jddd}i}|j|||jj|d|j d|d{y7w)zSend a one-way notification. Usable before entering the context manager. Fire-and-forget: after the connection has closed, the notification is dropped with a debug log instead of raising. Tr`rRrfrN)r\r!r$notifyrT)r notificationrkrls r[send_notificationzClientSession.send_notification5s^ &&6PT&U D$%%d8ndhhx6H$OOOsAA%A#A%c |j}|c|jrW|jDcic]7\}}||jvs!tfd|j|Dr||9c}}xsd}|jt ur"|j xstjnd}|jtur;tjtjtjnd}|jturtj dnd}tj"||d||Scc}}w)a Build the capability ad for a wire speaking `version`. Claim-bearing identifiers whose claims are all inactive at `version` drop, so the client never advertises result shapes it would reject; claim-less identifiers always advertise. Nc36K|]}t|ywr)r).0rrNs r[ z4ClientSession._build_capabilities..Msb}UG4bs)formurlT) list_changed)sampling elicitation experimentalrroots)rrranyr rrrpSamplingCapabilityrrElicitationCapabilityFormElicitationCapabilityUrlElicitationCapabilityrrRootsCapabilityClientCapabilities)rrNrrsettingsrwrxrzs ` r[_build_capabilitiesz!ClientSession._build_capabilities@s?%%  !d&9&9-7,<,<,>(JT%8%88b$BUBUV`BabbH$  &&.HH ( ( FE,D,D,F ))1NN  ' 'U-L-L-NTYTrTrTt u ((0LL  ! !t 4 '';TV`hm  1sr<r$r`rTr\)rrNrrrerkrlrYs r[ send_discoverzClientSession.send_discovers''22Dv\`2a //8CCTX^mqCr ''&&-w(+0, !!4f4!P/!&3W>OQUV^Q_`  $$55d8ndhhxFXZ^__3 `sCC3C1 C3cLK|j |jS |jtd{}t jj|}|j||S76#t$r}|jt k7r t jj|jj}n#t$r|dwxYwtDcgc]}||jvs|ncc}w}}|s|j|dd{7}Yd}~d}~wwxYww)u0Probe `server/discover` and adopt the result. Sends a single `server/discover` proposing the newest modern protocol version. On `UNSUPPORTED_PROTOCOL_VERSION` (-32022) the server's `supported` list is intersected with `MODERN_PROTOCOL_VERSIONS` and the probe is retried once at the highest mutual version. Any other error — including `METHOD_NOT_FOUND` (-32601) and `REQUEST_TIMEOUT` (-32001) — propagates; the legacy `initialize()` fallback is the caller's policy. Raises: MCPError: The server rejected `server/discover`, the probe timed out, or the -32022 retry found no mutual version / failed again. RuntimeError: `adopt()` found no mutual version in the returned `supported_versions`. Nr)rrr$r;rrrp#UnsupportedProtocolVersionErrorDatarrerrorrkr*r% supportedrr)rrYerkrrrss r[discoverzClientSession.discovers   ,(( ( 7**+@AAC%%44S9 6 !B 7vv55 "@@OOPQPWPWP\P\]" "T! "":QAQ$..=PaQQFQ**6":666C 7ssD$A-A+A-2D$+A-- D!6D 3B?>D? C  DC0+C0/"DDDD$D!!D$c|jS)zOThe server's InitializeResult. None unless `initialize()` ran (or was adopted).)rrs r[initialize_resultzClientSession.initialize_results&&&r]c|jS)zThe server's DiscoverResult. None unless `discover()` ran (or was adopted). Retained intact (supported_versions, ttl_ms, cache_scope) so callers can round-trip it as ``prior_discover=``. )rrs r[discover_resultzClientSession.discover_results$$$r]c|jS)zSNegotiated protocol version. None until `initialize()`, `discover()`, or `adopt()`.)r rs r[ryzClientSession.protocol_versions'''r]cx|j |jS|j|jjSy)aServer name/version. None until `initialize()`, `discover()`, or `adopt()`. On 2026-era connections this is the discover result's optional `_meta` `serverInfo` stamp, parsed once at adopt time; `None` when the server did not identify itself. The stamp is display-only per the spec, so a malformed value reads as absent rather than failing the connection. N)rrr server_infors r[rzClientSession.server_infos=  ,-- -  " " .**66 6r]c|j|jjS|j|jjSy)zKServer capabilities. None until `initialize()`, `discover()`, or `adopt()`.N)rrrrs r[server_capabilitiesz!ClientSession.server_capabilitiesC  ,((55 5  " " .**77 7r]c|j|jjS|j|jjSy)z*Server-provided instructions text, if any.N)r instructionsrrs r[rzClientSession.instructions rr])rocK|jtjtj|tjd{S7w)zSend a ping request.rrN)rkrp PingRequestr EmptyResult)rros r[ send_pingzClientSession.send_ping)s=&&u'8'8@S@SZ^@_'`bgbsbsttttsA AAAz\Client-to-server progress is deprecated as of 2026-07-28; progress is server-to-client only.)categoryc K|jtjtj|||||d{y7w)zSend a progress notification.)progress_tokenprogresstotalrrrN)rorpProgressNotificationProgressNotificationParams)rrrrrros r[send_progress_notificationz(ClientSession.send_progress_notification-sK$$  & &77#1%#    sAA A A zAThe logging capability is deprecated as of 2026-07-28 (SEP-2577).cK|jtjtj||tjd{S7w)z Send a logging/setLevel request.)levelrrN)rkrpSetLevelRequestSetLevelRequestParamsr)rrros r[set_logging_levelzClientSession.set_logging_levelGsJ&&  ! !)D)D5X\)] ^       A AAArcK|jtj|tjd{S7w)zSend a resources/list request. Args: params: Full pagination parameters including cursor and any future fields rN)rkrpListResourcesRequestListResourcesResultrs r[list_resourceszClientSession.list_resourcesTs3 &&u'A'A'PRWRkRkllll8A?AcK|jtj|tjd{S7w)zSend a resources/templates/list request. Args: params: Full pagination parameters including cursor and any future fields rN)rkrpListResourceTemplatesRequestListResourceTemplatesResultrs r[list_resource_templatesz%ClientSession.list_resource_templates\s<&&  . .f =  - -    rF)input_responses request_stateroallow_input_requiredc Kywrrjrurirrrors r[ read_resourcezClientSession.read_resourceis $'r)rrroc Kywrrjrs r[rzClientSession.read_resourcets @Crc K|jtjtj||||td{}t |tj r |s td|S7-w)aZSend a resources/read request. Args: input_responses: Responses to a prior `InputRequiredResult.input_requests`. request_state: Opaque state echoed from a prior `InputRequiredResult`. allow_input_required: When `False` (default), an `InputRequiredResult` from the server raises `RuntimeError`; when `True`, it is returned so the caller can resolve the requests and retry. Raises: RuntimeError: If the server returns an `InputRequiredResult` and `allow_input_required` is `False`. )rrrrrNr)rkrpReadResourceRequestReadResourceRequestParamsrrUrr)rrrrrorrss r[rzClientSession.read_resourcest,((  % %66$3"/   '    fe77 8AU,_= =   sAA7A5.A7zMresources/subscribe is removed as of 2026-07-28; use Client.listen() instead.cK|jtjtj||tjd{S7w)z;Send a resources/subscribe request (2025-era servers only).rrrN)rkrpSubscribeRequestSubscribeRequestParamsrrrros r[subscribe_resourcez ClientSession.subscribe_resourcesJ &&  " "%*F*F3VZ*[ \       rzOresources/unsubscribe is removed as of 2026-07-28; use Client.listen() instead.cK|jtjtj||tjd{S7w)z=Send a resources/unsubscribe request (2025-era servers only).rrN)rkrpUnsubscribeRequestUnsubscribeRequestParamsrrs r[unsubscribe_resourcez"ClientSession.unsubscribe_resourcesJ &&  $ $E,J,JsZ^,_ `       r)rrror allow_claimedc Kywrrj rrMrr(rhrrrorrs r[ call_toolzClientSession.call_tools  #r)rrrorc Kywrrjrs r[rzClientSession.call_tools BcK|jtj|tjd{}|duxs|jduxr|j du}|j ||S7;w)zSend a tools/list request. Args: params: Full pagination parameters including cursor and any future fields rN)r)rkrpListToolsRequestListToolsResultcursor next_cursor_absorb_tool_listing)rrrsrs r[rzClientSession.list_toolssy ((  " "& 1  ! !  dN;fmmt&;[ASASW[A[((((CC  s8A8A6:S:S:Y:Y:[(j$!Q_`di_iA(jD %=A=Y=Y=_=_=a+pTQefjoeoAqD+pD ( 9&f(j+ps*5H4' H94H9 H?,H? I$Iz?The roots capability is deprecated as of 2026-07-28 (SEP-2577).cfK|jtjd{y7w)z'Send a roots/list_changed notification.N)rorpRootsListChangedNotificationrs r[send_roots_list_changedz%ClientSession.send_roots_list_changeds%$$U%G%G%IJJJs '1/1c>K|jxsd} ttjt j |||}t|tjrtj}nb|jJt||j|jr|jjnd}|j!||d{}t"j%|}t|tj&rtj(||j+ddd} t j,||| | S#t $rttd|dwxYw7#t.$r)t0j3d |tt4d dwxYww) z?Answer a server-initiated request via the registered callbacks.rZzMethod not found)rrrkN)rrroTr`rRz1client callback for %r returned an invalid resultz*Client callback returned an invalid resultr)r rrp ServerRequestraparse_server_requestrcr;rrUrrrrrrodispatch_input_requestrrdrfrom_error_datar\validate_client_resultr*rOrPr) rdctxrfrrNreresponsectxclient_responsedumpeds r[r5zClientSession._on_request s|**:l e5..0M0MfV]_e0fgG gu00 1((*H??. ..&V]VdVdw~~?R?RjnC"88gFFH(88B ou 7**?; ; ++TUY+Z p  + +FGV D - e 0:LSYZ`d d eG p   PRX Y8deko o psBF/EB FE&AF-E(FE##F(2FFcDK|xtjdx\}|j||d{Sxtjdx\}|j ||d{Stj dx\|j |d{Sy7h777 w)uRoute an input request through the client's callback table. Shared by the legacy server→client RPC path (`_on_request`) and the 2026-07-28 multi-round-trip driver, which dispatches the embedded `InputRequiredResult.input_requests` through the same callbacks. Returns the callback's `InputResponse`, or `ErrorData` when the callback declines. rNrj)rpCreateMessageRequestr  ElicitRequestrListRootsRequestr)rr0reps r[r+z$ClientSession.dispatch_input_request/s5++5!44S!<<<6.$$.!77Q???/'')!66s;;;*=?;s3/B B2B $B%.B BB B B c8t}||j|<|S)zTCreate the demux route for a listen request id; the caller registers BEFORE sending.)r3r#)rrroutes r[_register_listen_routez$ClientSession._register_listen_routeBs */J' r]c<|jj|dy)zMDrop a listen route; the handle owns membership, so a missing key is a no-op.N)r#r)rrs r[_unregister_listen_routez&ClientSession._unregister_listen_routeHs  D1r]cttd}|jjD]}|j d||jj y)zUSettle all open listen routes as lost on session exit; cancelled driver tasks cannot.zConnection closedrlost)rN)r;rr#rsettlerK)rclosedr9s r[rEz*ClientSession._settle_listen_routes_closedLsP0:MN((//1 /E LLvL . / !!#r]cl|jsy|dk(rrMapping[str, Any]z(notifications/subscriptions/acknowledged notificationsT)r#rErTr?rUrr9rrHrpSubscriptionFilterrrr* set_ackedrIdeliver) rrfrr listen_routerosubscription_id raw_filterhonoredevents r[r7z%ClientSession._intercept_notificationSs@"" . .9&AJ%4;N;N;R;RS];^+^<*k##F+ >zz'"$('-@$(G(K(KLd(ef  "t7J7J7N7N7_'_|&h ? ?O4J! 22AA*M  " "7 +$VV4 4E A   ' #  sD'' D32D3cK|jxsd} ttjt j |||}t)|tj*ry t)|tj,r#|j/|j0d{|j3|d{y#t $r|jj|}|tjd||Yy |jj|xsi}n(#t$rtjd|dYYywxYw|j|\}} |j!|Yy#t"j$$r;| j'tjd||j!|YYywxYwt$rtjd|dYywxYw7D7.#t4$rtj7d|YywxYww) zVRoute a server notification: validate, run the typed callback, tee to message_handler.rZNzdropped %r: not defined at %sz#Failed to validate notification: %sT)exc_infoz;notification queue for %r is full; dropped the oldest eventz#notification callback for %r raised)r rrpServerNotificationraparse_server_notificationrcrrTrOdebug params_typerrr*rr send_nowaitr WouldBlockreceive_nowaitrUCancelledNotificationLoggingMessageNotificationrrrrNrP) rr.rfrrNrnr bound_paramsr@rAs r[r6zClientSession._on_notifyzs **:l  8 8(:\:\]celnt:uvL4 lE$?$? @  L,(H(HI,,\-@-@AAA'' 5 5 5? 1155f=G r?r9rkrorrhrrrpropertyrrryrrrrr-r:rrrrrrrrrrrrrrrrrr'r5r+r:r<rEr7r6r%rYrjr]r[rrcs  "FJ;?-1046:37.24837C04AE7;IMKO-1#CBC9C+ C . C 4 C1C,C2C1C-C ?C5CGC I!C"+#C$ %CJ>,&%   "% _/ _:^ _  _ 6:1504 8>>8>H8>'3 8> / 8> . 8> 8>t P# J0-^!F$L''%%((  CGuf&#"  *. !      '    ,S^st *.  !  '    u  UYm@D  <  *   8<$()-/4' '5 ' " ' ' '-' "'' 8<$()- C C5 C " C ' C#C >CC8<$()-%*# #5 # " # ' ### >#JW&VZ  Y&X\  ,0-104 #8<$()-/4(- # #) #+ # . #5 #" #' #- #& #  # #,0-104 ?8<$()-(- ? ?) ?+ ? . ?5 ?" ?' ?# ?& ? : ? ?,0-104 28<$()-/4 2 2) 2+ 2 . 25 2" 2' 2- 2 2 - 2 2,0-104 N8<$()- N N) N+ N . N5 N" N' N# N N I N N",0-104 98<$()-%*#99)9+ 9 . 959"9'9#99 I9v8n@:SWi,0 $ 8<$()-/4 $ $) $ 5 $ " $' $- $  $ $,0 @ 8<$()- @ @) @ 5 @ " @' @# @ ; @ @,0% 8<$()-%*%%)% 5 % " %'%#% ;%V48  D ! 1    ,QU D'RQ\qrKsK 5 ?B Ld   D<'<2D< .<& 2$%N-L5-L?B-LLd-L -L^INr]r)rYr|r}r~)rbrjrcrjr}rXr{)rsrdr}r^)ryrr}-Callable[[dict[str, Any], CallOptions], None]) ryrrr|rr|rz2Callable[[str, Mapping[str, Any]], dict[str, str]]rr_r}rrrrrrr)rzResultClaim[Any]rNrr}rX)rz*Mapping[str, tuple[ResultClaim[Any], ...]]rNrr}zdict[str, ResultClaim[Any]])rzMapping[str, ResultClaim[Any]]r}r)rrarr`r}z'dict[str, tuple[ResultClaim[Any], ...]])rrbr}z#dict[str, NotificationBinding[Any]])rfrr}r) __future__rr`loggingcollections.abcrrr dataclassesr functoolsroperatorr rpr typingr r r rrrrrrr anyio.abcanyio.lowlevel mcp_typesanyio.streams.memoryrrrrrrrrrrrrr r!ramcp_types.versionr"r#r$r%pydanticr&r'r(r)r*typing_extensionsr+r,r-mcp.client._transportr.r/mcp.client.extensionr0r1r2mcp.client.subscriptionsr3mcp.shared._compatr4mcp.shared.dispatcherr5r6r7r8r9mcp.shared.exceptionsr:r;mcp.shared.inboundr<r=r>r?r@rArBrCmcp.shared.jsonrpc_dispatcherrDrEmcp.shared.messagerFrGmcp.shared.subscriptionsrHrImcp.shared.transport_contextrJjsonschema.protocolsrKrqr rrPr getLoggerrOr\rdrmrtrrrrrrrrrNrNrrrrrrr ClientResultrrrrrGetPromptResultrReadResourceResultrrrrrrrrrjr]r[rsc" 77!eee R    * QP779ZZ0,ffA   ^DN9/*e**wG"%%%   8 $J* ,0 &&&!&N & ) &3&R); 4***_(_3X3686 ZZ#55 AADD& ! ,V ! %* !, 2   EPPUPbPbejetetPtDuAuhs 5444hd[f E555[Wal u888a]  C NQ   L *LQL4B0-4 D ( SNSNr]