+
    Q(iv@                       R t ^ RIHt ^ RIt^ RIt^ RIHtHtHtH	t	 ^ RI
t^ RIHt ]'       d   ^ RIt^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RI H!t! ^ RI"H#t# ]! ]$4      t%]]PL                  PN                  ]PL                  P                   ,          ,          t( ! R R4      t)RR R llt*R# )z(Tool-related methods for FastMCP Client.)annotationsN)TYPE_CHECKINGAnyLiteraloverload)	RootModel)CallToolResultClient)ProgressHandler)ToolTask)client_span)	ToolError)inject_trace_context)json_schema_to_type)
get_logger)normalize_timeout_to_timedelta)get_cached_typeadapterc                     ] tR t^ tRtRR/R R lltR R ltR R R	 lltR!R R llt]	R"RRRRRRRRRRRR
/R R lll4       t
]	R"RRRRRRRRRRRRRR/R R lll4       t
R"RRRRRRRRRRRR
RRRR/R R lllt
R#R R lltRtR# )$ClientToolsMixinz0Mixin providing tool-related methods for Client.cursorNc               $    V ^8  d   QhRRRRRR/# )   selfr	   r   
str | Nonereturnzmcp.types.ListToolsResult )formats   "a/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/client/mixins/tools.py__annotate__ClientToolsMixin.__annotate__%   s$      !+	"    c                  "   \         P                  RV P                   R24       V P                  V P                  P                  VR7      4      G Rj  xL
 pV#  L5i)a  Send a tools/list request and return the complete MCP protocol result.

Args:
    cursor: Optional pagination cursor from a previous request's nextCursor.

Returns:
    mcp.types.ListToolsResult: The complete response object from the protocol,
        containing the list of tools and any additional metadata.

Raises:
    RuntimeError: If called while the client is not connected.
    McpError: If the request results in a TimeoutError | JSONRPCError
[z] called list_toolsr   N)loggerdebugname_await_with_session_monitoringsession
list_tools)r   r   results   &$ r   list_tools_mcpClientToolsMixin.list_tools_mcp%   sW       	q#678::LL##6#2
 
 
s   AAAAc                    V ^8  d   QhRRRR/# )r   r   r	   r   zlist[mcp.types.Tool]r   )r   s   "r   r   r   <   s        v  *>  r    c                  "   . pRp\        4       p V P                  VR7      G Rj  xL
 pVP                  VP                  4       VP                  '       g    V# VP                  V9   d5   \
        P                  RV P                   RVP                  : R24        V# VP                  VP                  4       VP                  pK   L5i)a  Retrieve all tools available on the server.

This method automatically fetches all pages if the server paginates results,
returning the complete list. For manual pagination control (e.g., to handle
large result sets incrementally), use list_tools_mcp() with the cursor parameter.

Returns:
    list[mcp.types.Tool]: A list of all Tool objects.

Raises:
    RuntimeError: If called while the client is not connected.
    McpError: If the request results in a TimeoutError | JSONRPCError
Nr#   r"   z.] Server returned duplicate pagination cursor z$ for list_tools; stopping pagination)	setr+   extendtools
nextCursorr$   warningr&   add)r   	all_toolsr   seen_cursorsr*   s   &    r   r)   ClientToolsMixin.list_tools<   s      +-	!!$..f.==FV\\*$$$    L0		{ #)),,PR   V../&&F >s   %CC
0CA2Cc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r   r   r	   r&   str	argumentszdict[str, Any]progress_handlerProgressHandler | Nonetimeout'datetime.timedelta | float | int | Nonemetadict[str, Any] | Noner   mcp.types.CallToolResultr   )r   s   "r   r   r   `   sN     3 333 "3 1	3
 93 $3 
"3r    c                  "   \        RV 2RVV P                  P                  4       R7      ;_uu_ 4        \        P	                  RV P
                   RV 24       \        V4      pT P                  V P                  P                  TT\        V4      T;'       g    V P                  V'       d   TMRR7      4      G Rj  xL
 pVuuRRR4       #  L  + '       g   i     R# ; i5i)a  Send a tools/call request and return the complete MCP protocol result.

This method returns the raw CallToolResult object, which includes an isError flag
and other metadata. It does not raise an exception if the tool call results in an error.

Args:
    name (str): The name of the tool to call.
    arguments (dict[str, Any]): Arguments to pass to the tool.
    timeout (datetime.timedelta | float | int | None, optional): The timeout for the tool call. Defaults to None.
    progress_handler (ProgressHandler | None, optional): The progress handler to use for the tool call. Defaults to None.
    meta (dict[str, Any] | None, optional): Additional metadata to include with the request.
        This is useful for passing contextual information (like user IDs, trace IDs, or preferences)
        that shouldn't be tool arguments but may influence server-side processing. The server
        can access this via `context.request_context.meta`. Defaults to None.

Returns:
    mcp.types.CallToolResult: The complete response object from the protocol,
        containing the tool result and any additional metadata.

Raises:
    RuntimeError: If called while the client is not connected.
    McpError: If the tool call requests results in a TimeoutError | JSONRPCError
ztools/call z
tools/call)
session_idr"   z] called call_tool: N)r&   r:   read_timeout_secondsprogress_callbackr?   )r   	transportget_session_idr$   r%   r&   r   r'   r(   	call_toolr   _progress_handler)r   r&   r:   r;   r=   r?   propagated_metar*   s   &&&&&&  r   call_tool_mcpClientToolsMixin.call_tool_mcp`   s     > $ ~~446	
 
 LL1TYYK';D6BC 348O>>&&')G)P&6&P&P$:P:P,; '  F )
 

 
 
s5   3C&A9C/C?C CC&CC#		C&Fc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r   r   r	   r&   r9   r*   rA   raise_on_errorboolr   r   r   )r   s   "r   r   r      s:     
 


 )
 	

 

r    c           	        "   \        VVV P                  P                  V P                  P                  V P                  VR7      G Rj  xL
 #  L5i)a  Parse an mcp.types.CallToolResult into our CallToolResult dataclass.

Args:
    name: Tool name (for schema lookup)
    result: Raw MCP protocol result
    raise_on_error: Whether to raise ToolError on errors

Returns:
    CallToolResult: Parsed result with structured data
)r&   r*   tool_output_schemaslist_tools_fnclient_namerN   N)_parse_call_tool_resultr(   _tool_output_schemasr)   r&   )r   r&   r*   rN   s   &&&&r   rT   (ClientToolsMixin._parse_call_tool_result   sH     " - $ A A,,11		)
 
 	
 
s   AA	A
Aversionr=   r;   rN   Tr?   taskc               @    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRR/
# )r   r   r	   r&   r9   r:   r@   rW   r   r=   r>   r;   r<   rN   rO   r?   rX   zLiteral[False]r   r   r   )r   s   "r   r   r      sl       )
  9 1  $  
r    c               	   "   R # 5iNr   )	r   r&   r:   rW   r=   r;   rN   r?   rX   s	   &&&$$$$$$r   rH   ClientToolsMixin.call_tool   s
         task_idttl`  c               H    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRR/# )r   r   r	   r&   r9   r:   r@   rW   r   r=   r>   r;   r<   rN   rO   r?   rX   zLiteral[True]r^   r_   intr   r   r   )r   s   "r   r   r      s       )
  9 1  $    
r    c               	   "   R # 5ir[   r   )r   r&   r:   rW   r=   r;   rN   r?   rX   r^   r_   s   &&&$$$$$$$$r   rH   r\      s
      r]   c               H    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRR/# )r   r   r	   r&   r9   r:   r@   rW   r   r=   r>   r;   r<   rN   rO   r?   rX   r^   r_   rb   r   zCallToolResult | ToolTaskr   )r   s   "r   r   r      s     E
 E
E
E
 )E

 E
 9E
 1E
 E
 $E
 E
 E
 E
 
#E
r    c               t  "   V'       d   \        V4      M/ pVe   / VP                  R/ 4      CRV/CVR&   V'       d'   T P                  YYT;'       g    RR7      G Rj  xL
 # T P                  TT;'       g    / TTT;'       g    RR7      G Rj  xL
 pV P	                  WVR7      G Rj  xL
 #  LQ L! L5i)a  Call a tool on the server.

Unlike call_tool_mcp, this method raises a ToolError if the tool call results in an error.

Args:
    name (str): The name of the tool to call.
    arguments (dict[str, Any] | None, optional): Arguments to pass to the tool. Defaults to None.
    version (str | None, optional): Specific tool version to call. If None, calls highest version.
    timeout (datetime.timedelta | float | int | None, optional): The timeout for the tool call. Defaults to None.
    progress_handler (ProgressHandler | None, optional): The progress handler to use for the tool call. Defaults to None.
    raise_on_error (bool, optional): Whether to raise an exception if the tool call results in an error. Defaults to True.
    meta (dict[str, Any] | None, optional): Additional metadata to include with the request.
        This is useful for passing contextual information (like user IDs, trace IDs, or preferences)
        that shouldn't be tool arguments but may influence server-side processing. The server
        can access this via `context.request_context.meta`. Defaults to None.
    task (bool): If True, execute as background task (SEP-1686). Defaults to False.
    task_id (str | None): Optional client-provided task ID (auto-generated if not provided).
    ttl (int): Time to keep results available in milliseconds (default 60s).

Returns:
    CallToolResult | ToolTask: The content returned by the tool if task=False,
        or a ToolTask object if task=True. If the tool returns structured
        outputs, they are returned as a dataclass (if an output schema
        is available) or a dictionary; otherwise, a list of content
        blocks is returned. Note: to receive both structured and
        unstructured outputs, use call_tool_mcp instead and access the
        raw result object.

Raises:
    ToolError: If the tool call results in an error.
    McpError: If the tool call request results in a TimeoutError | JSONRPCError
    RuntimeError: If called while the client is not connected.
NfastmcprW   )r?   )r&   r:   r=   r;   r?   )rN   )dictget_call_tool_as_taskrK   rT   )r   r&   r:   rW   r=   r;   rN   r?   rX   r^   r_   request_metar*   s   &&&$$$$$$$$  r   rH   r\      s     ` &*tDzr'""9b1'7'L#
 00L4H4HD 1    ))oo2-%% * 
 
 11 2 
 
 	


sL   <B8B8B8 B2!B8:B8B8B4B8-B6.B84B86B8c               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r   r   r	   r&   r9   r:   r@   r^   r   r_   rb   r?   r   r   r   )r   s   "r   r   r     sW     C CCC )C 	C
 C $C 
Cr    c           
     >  "   \        V4      p\        P                  P                  \        P                  P	                  TT;'       g    / \        P                  P                  VR7      VR7      R7      pV P                  V P                  P                  V\        R7      4      G Rj  xL
 pVP                  p	\        V	\        P                  P                  4      '       de   V	P                  P                  p
V P                  P!                  V
4       \#        W
VRR7      p\$        P&                  ! V4      V P(                  V
&   V# V P+                  W4      G Rj  xL
 pT;'       g    \-        \.        P0                  ! 4       4      p\#        V VVVR7      #  L L=5i)a  Call a tool for background execution (SEP-1686).

Returns a ToolTask object that handles both background and immediate execution.
If the server accepts background execution, ToolTask will poll for results.
If the server declines (graceful degradation), ToolTask wraps the immediate result.

Args:
    name: Tool name to call
    arguments: Tool arguments
    task_id: Optional client-provided task ID (ignored, for backward compatibility)
    ttl: Time to keep results available in milliseconds (default 60s)
    meta: Optional request metadata (e.g., version info)

Returns:
    ToolTask: Future-like object for accessing task status and results
)r_   )r&   r:   rX   _meta)params)requestresult_typeN)	tool_nameimmediate_result)r   mcptypesCallToolRequestCallToolRequestParamsTaskMetadatar'   r(   send_requestToolTaskResponseUnionroot
isinstanceCreateTaskResultrX   taskId_submitted_task_idsr4   r   weakrefref_task_registryrT   r9   uuiduuid4)r   r&   r:   r^   r_   r?   rJ   ro   wrapped_result
raw_resultserver_task_idtask_objparsed_resultsynthetic_task_ids   &&&&&&        r   ri   #ClientToolsMixin._call_tool_as_task  se    4 /t4 ))++9922#//rYY+++4%	 3  , 
  $BBLL%%1 &  
 
 $((
j#))"<"<=='__33N$$((8tH 3:++h2GD/O #'">">t"PPM ' < <3tzz|+<!!.	 -
( Qs+   B(F*F+B2FFF+/FFr   )NNN)Fr[   )NNr`   N)__name__
__module____qualname____firstlineno____doc__r+   r)   rK   rT   r   rH   ri   __static_attributes__r   r    r   r   r       sA   :.2. H3j
4 
 # <@ 48  $ '+  %  
 # <@ 48  $ '+ #  E

 #E
 <@E
 48E
  $E
 '+E
 E
 #E
 E
 E
NC Cr    r   c               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r   r&   r9   r*   rA   rQ   z dict[str, dict[str, Any] | None]rR   r   rS   r   rN   rO   r   r   r   )r   s   "r   r   r   Z  sN     ; ;
;$; :; 	;
 ; ; ;r    c                  "   ^ RI Hp ^ RIHp RpVP                  '       dP   V'       dH   V! \
        P                  P                  VP                  ^ ,          4      P                  p	\        V	4      hVP                  '       d    W9  d   V! 4       G Rj  xL
  W9   d   VP                  V 4      p
V
'       d   V
P                  R4      '       d>   V
P                  R/ 4      P                  R4      p
VP                  P                  R4      pMVP                  p\        V
4      p\        V4      pVP                  V4      pMVP                  pV! VP                  VP                  VP&                  VVP                  R
7      #  L  \          d0   p\"        P%                  RT;'       g    R R	T 24        Rp?LlRp?ii ; i5i)a  Parse an mcp.types.CallToolResult into our CallToolResult dataclass.

Args:
    name: Tool name (for schema lookup)
    result: Raw MCP protocol result
    tool_output_schemas: Dictionary mapping tool names to their output schemas
    list_tools_fn: Async function to refresh tool schemas if needed
    client_name: Optional client name for logging
    raise_on_error: Whether to raise ToolError on errors

Returns:
    CallToolResult: Parsed result with structured data
)cast)r   Nzx-fastmcp-wrap-result
propertiesr*   r"   clientz$] Error parsing structured content: )contentstructured_contentr?   datais_error)typingr   fastmcp.client.clientr   isErrorrs   rt   TextContentr   textr   structuredContentrh   r   r   validate_python	Exceptionr$   errorr?   )r&   r*   rQ   rR   rS   rN   r   r   r   msgoutput_schemar   output_typetype_adapteres   &&&&&&         r   rT   rT   Z  s    * 4D~~~.399((&..*;<AAn		!	!	!	.#o%%* 3 7 7 = $(()@AA(5(9(9,(K(O(O$) .4-E-E-I-I(-S*-3-E-E*"5m"DK#9+#FL'778JKD!33D !33[[ + &   	LLK++8,,PQRPST 	s`   (GAGF F"F 9F A0F  GF 5GF F>%F94G9F>>G)NF)+r   
__future__r   r   r   r   r   r   r   r   	mcp.typesrs   pydanticr   datetimer   r   r	   fastmcp.client.progressr
   fastmcp.client.tasksr   fastmcp.client.telemetryr   fastmcp.exceptionsr   fastmcp.telemetryr   "fastmcp.utilities.json_schema_typer   fastmcp.utilities.loggingr   fastmcp.utilities.timeoutr   fastmcp.utilities.typesr   r   r$   rt   r|   ry   r   rT   r   r    r   <module>r      s    . "   8 8  < 3 ) 0 ( 2 B 0 D :	H	 "#))"<"<syy?W?W"WX w wt	; ;r    