Xj9` 2UddlZddlZddlmZddlmZmZmZddlZ ddl m Z m Z ddl mZmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZmZmZdd l m!Z!ejDd dZ#dZ$ejJdZ&GddeZ'GddeZ(GddeZ)GddeZ*GddeZ+deejXejZfej\ze/zddfdZ0ded efd!ejbdejdejfzejhzfd"Z5ded efd!ejldejnejhzfd#Z8ded efdejrejhzfd$Z:d!ejvddfd%Z<eejZejhzZ=eejZejhze>d&<Gd'd eej~ejejZejXej\fZAy)(N) timedelta)AnyProtocoloverload)MemoryObjectReceiveStreamMemoryObjectSendStream)AnyUrl TypeAdapter) deprecated)ExperimentalClientFeatures)ExperimentalTaskHandlers)RequestContext)SessionMessage) BaseSession ProgressFnTRequestResponder)SUPPORTED_PROTOCOL_VERSIONSmcpz0.1.0)nameversionThe experimental tasks API is deprecated and will be removed in mcp 2.0: tasks (SEP-1686) were removed from the MCP specification and are expected to return as a separate MCP extension.clientceZdZdedefdej dejejzejzfdZ y) SamplingFnTcontext ClientSessionparamsreturnc KywNselfrrs f/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/mcp/client/session.py__call__zSamplingFnT.__call__"s \_N) __name__ __module__ __qualname__rrtypesCreateMessageRequestParamsCreateMessageResultCreateMessageResultWithTools ErrorDatar%r!r$rr!sQ_ 45_00_  " "U%G%G G%// Y _r/rcleZdZdedefdej dejejzfdZ y)ElicitationFnTrrrrc Kywr r!r"s r$r%zElicitationFnT.__call__*s 03r&N) r'r(r)rrr*ElicitRequestParams ElicitResultr.r%r!r/r$r1r1)sB3 453))3   eoo - 3r/r1cTeZdZdedefdej ejzfdZy) ListRootsFnTrrrc Kywr r!)r#rs r$r%zListRootsFnT.__call__2s 25r&N) r'r(r)rrr*ListRootsResultr.r%r!r/r$r6r61s06%os&:;6    06r/r6c0eZdZdejddfdZy) LoggingFnTrrNc Kywr r!r#rs r$r%zLoggingFnT.__call__8 r&)r'r(r)r* LoggingMessageNotificationParamsr%r!r/r$r:r:7s66 r/r:cneZdZdeej ej fejzezddfdZ y)MessageHandlerFnTmessagerNc Kywr r!)r#rAs r$r%zMessageHandlerFnT.__call__?r=r&) r'r(r)rr* ServerRequest ClientResultServerNotification Exceptionr%r!r/r$r@r@>s@!%"5"5u7I7I"IJUMeMeehqq r/r@rArc\Ktjjd{y7wr )anyiolowlevel checkpoint)rAs r$_default_message_handlerrKEs .. # # %%%s ",*,rrrcTKtjtjdSw)NzSampling not supportedcoderAr*r.INVALID_REQUESTrrs r$_default_sampling_callbackrRKs% ??  " "( &(cTKtjtjdSw)NzElicitation not supportedrMrOrQs r$_default_elicitation_callbackrUUs% ??  " "+ rScTKtjtjdSw)NzList roots not supportedrMrO)rs r$_default_list_roots_callbackrW_s% ??  " "* rSc Kywr r!rs r$_default_logging_callbackrZhs  r&ClientResponseceZdZ dKddddeeezdeededzdedzde dzde dzd e dzd e dzd e jdzd e jdzd edzddffdZde j$fdZde j(dzfdZeeddefdZde j4fdZ dLdeezdededzdedzddf dZde j@de j4fdZ!e"eddedzde jFfdZ$e"de jJdzde jFfd Z$e"de jFfd!Z$ dMdd"dedzde jJdzde jFfd#Z$e"ed$dedzde jLfd%Z'e"de jJdzde jLfd&Z'e"de jLfd'Z' dMdd"dedzde jJdzde jLfd(Z'd)e(de jRfd*Z*d)e(de j4fd+Z+d)e(de j4fd,Z, dNdd-d.ed/e-ee.fdzdedzd0e/dzd1e-ee.fdzde j`f d2Z1d.ed3e j`ddfd4Z2e"ed5dedzde jffd6Z4e"de jJdzde jffd7Z4e"de jffd8Z4 dMdd"dedzde jJdzde jffd9Z4dMd.ed/e-eefdzde jjfd:Z6 dMd;e jne jpzdZ:e"ed?dedzde jvfd@Ze j~e jfddfdFZAdGe>e j~e jfe jzezddfdHZCdIe jddfdJZDxZES)PrN)sampling_capabilitiesexperimental_task_handlers read_stream write_streamread_timeout_secondssampling_callbackelicitation_callbacklist_roots_callbacklogging_callbackmessage_handler client_infor]r^rc t |||tjtj|| xst |_|xst|_| |_ |xst|_ |xst|_ |xst|_|xst |_i|_d|_d|_| t+j,t.t0d| xs t3|_y)N)ra) stacklevel)super__init__r*rCrEDEFAULT_CLIENT_INFO _client_inforR_sampling_callback_sampling_capabilitiesrU_elicitation_callbackrW_list_roots_callbackrZ_logging_callbackrK_message_handler_tool_output_schemas_server_capabilities_experimental_featureswarningswarn_EXPERIMENTAL_TASKS_DEPRECATIONDeprecationWarningr _task_handlers) r#r_r`rarbrcrdrerfrgr]r^ __class__s r$rlzClientSession.__init__zs        $ $!5  (>+>"3"Q7Q&;#%9%Z=Z"$7$W;W!!1!N5N / K3KFH!EI!IM# & 1 MM9;MZ[ \8V[>[>]%^___ 5 0 `s%EGGA8GGGGc|jS)zReturn the server capabilities received during initialization. Returns None if the session has not been initialized yet. )rvr#s r$get_server_capabilitiesz%ClientSession.get_server_capabilitiess (((r/rcR|jt||_|jS)aExperimental APIs for tasks and other features. Deprecated: the experimental tasks API will be removed in mcp 2.0. Tasks (SEP-1686) were removed from the MCP specification and are expected to return as a separate MCP extension. Example: status = await session.experimental.get_task(task_id) result = await session.experimental.get_task_result(task_id, CallToolResult) )rwr rs r$rzClientSession.experimentals)  & & .*DT*JD '***r/cK|jtjtjtjd{S7w)zSend a ping request.N)rr*r PingRequest EmptyResultrs r$ send_pingzClientSession.send_pingsC&&    1 1 3 4       sA A A Aprogress_tokenprogresstotalrAc K|jtjtjtj||||d{y7w)zSend a progress notification.) progressTokenrrrArYN)rr*rProgressNotificationProgressNotificationParams)r#rrrrAs r$send_progress_notificationz(ClientSession.send_progress_notificationsV$$  $ $** ;;&4!)# '    sAAAAlevelc K|jtjtjtj|tj d{S7w)z Send a logging/setLevel request.)rrYN)rr*rSetLevelRequestSetLevelRequestParamsr)r#rs r$set_logging_levelzClientSession.set_logging_level sX&&   %% 66UC         AA(!A&"A(z>Use list_resources(params=PaginatedRequestParams(...)) insteadcursorc Kywr r!r#rs r$list_resourceszClientSession.list_resourcess UXr&rc Kywr r!r<s r$rzClientSession.list_resourcess qtr&c Kywr r!rs r$rzClientSession.list_resourcess ADr&rYc K| | td||}n|tj|}nd}|jtjtj |tj d{S7w)zSend a resources/list request. Args: cursor: Simple cursor string for pagination (deprecated, use params instead) params: Full pagination parameters including cursor and any future fields N%Cannot specify both cursor and paramsrrY) ValueErrorr*PaginatedRequestParamsrrListResourcesRequestListResourcesResultr#rrrequest_paramss r$rzClientSession.list_resourcess  &"4DE E  #N  "99HN!N&&    : :. Q R  % %    A:B<B=BzGUse list_resource_templates(params=PaginatedRequestParams(...)) insteadc Kywr r!rs r$list_resource_templatesz%ClientSession.list_resource_templates:s fir&c Kywr r!r<s r$rz%ClientSession.list_resource_templates>s -0r&c Kywr r!rs r$rz%ClientSession.list_resource_templatesCs RUr&c K| | td||}n|tj|}nd}|jtjtj |tj d{S7w)zSend a resources/templates/list request. Args: cursor: Simple cursor string for pagination (deprecated, use params instead) params: Full pagination parameters including cursor and any future fields NrrrY)rr*rrrListResourceTemplatesRequestListResourceTemplatesResultrs r$rz%ClientSession.list_resource_templatesFs  &"4DE E  #N  "99HN!N&&    B B. Y Z  - -    ruric K|jtjtjtj|tj d{S7w)zSend a resources/read request.rrYN)rr*rReadResourceRequestReadResourceRequestParamsReadResourceResultr#rs r$ read_resourcezClientSession.read_resourceasX&&   )) ::sC   $ $     rc K|jtjtjtj|tj d{S7w)z#Send a resources/subscribe request.rrYN)rr*rSubscribeRequestSubscribeRequestParamsrrs r$subscribe_resourcez ClientSession.subscribe_resourcelsX&&   && 77C@         rc K|jtjtjtj|tj d{S7w)z%Send a resources/unsubscribe request.rrYN)rr*rUnsubscribeRequestUnsubscribeRequestParamsrrs r$unsubscribe_resourcez"ClientSession.unsubscribe_resourcewsX&&   (( 99cB         r)metar argumentsprogress_callbackrc xKd}|tjjdi|}|jtjtj tj |||tj||d{}|js|j||d{|S7,7w)zBSend a tools/call request with optional progress callback support.N)rr_metarY)request_read_timeout_secondsrr!) r* RequestParamsMetarrCallToolRequestCallToolRequestParamsCallToolResultisError_validate_tool_result)r#rrrarrrrs r$ call_toolzClientSession.call_tools26  '',,4t4E((   %% 66DI]bc   )=/)   ~~,,T6: : :    ;s$BB: B6 %B:/B80B:8B:rcK||jvr|jd{d}||jvr|jj|}ntj d|d|:ddlm}m}m}|jtd|d ||j|yy7#|$r}td|d|d}~w|$r}td |d|d}~wwxYww) zKValidate the structured content of a tool result against its output schema.NzTool z= not listed by server, cannot validate any structured contentr) SchemaErrorValidationErrorvalidatez; has an output schema but did not return structured contentz,Invalid structured content returned by tool z: zInvalid schema for tool ) ru list_toolsgetloggerwarning jsonschemarrrstructuredContentr)r#rr output_schemarrres r$rz#ClientSession._validate_tool_results  t00 0//# # # 4,, , 5599$?M NNU4&(ef g  $ I I''/"D6!\] K11=A % $"# _"%QRVQWWYZ[Y\#]^^ K"%=dV2aS#IJJ Ks@"C$B+A0C$B-)C$-C!2CC! CC!!C$z`>`>b%cddds:AAA responderc.Ktttf|j|j|d}|j j |jr0|5|j j||d{dddy|jjxtjdx\}|5|j0|j j|||jd{}n|j||d{}tj!|}|j#|d{dddyxtj$dx\}|5|j0|j j'|||jd{}n|j)||d{}tj!|}|j#|d{dddyxtj*dxV\|5|j-|d{}tj!|}|j#|d{dddytj.dxM\|5|j#tj0tj2d{cdddS y7D#1swYyxYw777#1swYyxYw7K737#1swYyxYw77#1swYyxYw7Z#1swYyxYww)N) request_idrsessionlifespan_contextrYr!)root)rrrr request_metar|handles_requestrequesthandle_requestrr*CreateMessageRequesttaskaugmented_samplingror[validate_pythonrespond ElicitRequestaugmented_elicitationrqListRootsRequestrrrrDr)r#rctxrresponseclient_responses r$_received_requestzClientSession._received_request3s]C/0 ++''!      . .y/@/@ A I))88iHHH I$$:++:={{.)-)<)<)O)OPSU[]c]h]h)i#i)-)@)@f)M#M&4&D&DX&NO#++O<<<=@C;4$$3={{.)-)<)<)R)RSVX^`f`k`k)l#l)-)C)CC)P#P&4&D&DX&NO#++O<<<=,/4*'')=%)%>%>s%CCH&4&D&DX&NO#++O<<<=* ""$a!*!2!253E3E5K\K\K^3_!``aa%MI I$j#M<=@'$m#P<=, D<= aa s2AL K:J>;K?8L77K.K /K K -K7K8K<$L 7K+K"K+2K%3-K+ K(!K+%#LK;K7-K; K9 K;!L1;L ,L-L 0L>KK L KKKKL"K+%K+(K++K40L7K;9K;;LLL  LLreqcBK|j|d{y7w)z>Handle incoming messages by forwarding to the message handler.N)rt)r#r,s r$_handle_incomingzClientSession._handle_incomingfs ##C(((s  notificationcK|jxtjdx\}|j|d{ytjdx\}y y7 w)z%Handle notifications from the server.rYN)rr*LoggingMessageNotificationrsElicitCompleteNotification)r#r/rs r$_received_notificationz$ClientSession._received_notificationms]@11@,,V444A11@ A 5s8AA!A)NNNNNNN)NNr )NNN)rN)Fr'r(r)rrrFrrrr1r6r:r@r*Implementationrr rlrrServerCapabilitiesrpropertyr r rrrstrintfloatr LoggingLevelrrrrrrrr rrrrdictrrrrrrrrrResourceTemplateReferencePromptReferencerr rrrrrCrDr+rEr.r3 __classcell__)r}s@r$rrqs26046:37.24837$WBFFJ$W.~ /IJ$W-^<$W($. $W '- $W -t3 $W*D0$W%t+$W+T1$W))D0$W %77$>$W%=t$C$W $WL1%"8"81f))A)AD)H) ^ +8 +  + !2!2 #"  c   t|  t    *  U-?-?  EDUDU  PQX3:X%:S:SXRX te.J.JT.QtV[VoVott De&?&?DD" 7;  d  ,,t3   " "  6YZiC$Ji5CdCdi[i 055<0  * *00Uu/P/PUU" 7;  d  ,,t3   * *  6  v  %2J2J    F  u7H7H    f  9J9J  ,01504 '+S>D(($.  '- 38nt#   >KKU=Q=QKVZK4NOTtT8O8OTPT pE,H,H4,OpTYTkTkpp @E$;$;@@" 7;  d  ,,t3    6  S  T#s(^d5J  V[VkVk  48   , ,u/D/D D sCx.  S>D0      0LMPsTzPe6K6KPNP l%*F*F*MlRWRgRgll <%"7"7<<" 7; d  ,,t3     De11A%BUBUW\WiWiBi1j1os1f) e1153E3EE FIaIa adm m) ) 9Q9Q VZ r/)Bloggingrxdatetimertypingrrranyio.lowlevelrHanyio.streams.memoryrrpydanticr r typing_extensionsr mcp.typesr*mcp.client.experimentalr %mcp.client.experimental.task_handlersr mcp.shared.contextrmcp.shared.messagermcp.shared.sessionrrrmcp.shared.versionrr4rmrz getLoggerrrr1r6r:r@rCrDrErFrKr+r,r-r.rRr3r4rUr8rWr>rZr[__annotations__rrrr!r/r$rOs6**R((>J--II:*e**wGZ   8 $_(_3X3686 & e1153E3EE FIaIa adm m& &  OS0 1  , , !C!CCeooU OS0 1  % % %//) OS0 1 U__,  2 2   EPPUPbPbejetetPtDu E..@AuH          "Hr/