
    {h                        d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZmZ d d	lmZ e	rd d
lmZ d dlmZ d dlmZmZ  G d de      ZddZy)    )annotationsN)Callable)cached_property)TYPE_CHECKINGAny
get_origin)	BaseModelField)	ToolError)FuncMetadatafunc_metadata)ToolAnnotationsContext)ServerSessionT)LifespanContextTRequestTc                     e Zd ZU dZ ed      Zded<    ed      Zded	<    ed
d      Zded<    ed      Z	ded<    ed      Z
ded<    ed      Zded<    ed      Zded<    ed
d      Zded<    ed
d      Zded<   ed!d       Ze	 	 	 	 	 	 d"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#d       Z	 	 d$	 	 	 	 	 	 	 d%d Zy
)&Toolz Internal tool registration info.T)excludeCallable[..., Any]fnzName of the tool)descriptionstrnameNz Human-readable title of the tool
str | Nonetitlez!Description of what the tool doesr   zJSON schema for tool parametersdict[str, Any]
parameterszIMetadata about the function including a pydantic model for tool argumentsr   fn_metadatazWhether the tool is asyncboolis_asyncz-Name of the kwarg that should receive contextcontext_kwargz!Optional annotations for the toolToolAnnotations | Noner   c                .    | j                   j                  S )N)r    output_schema)selfs    ^/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/mcp/server/fastmcp/tools/base.pyr&   zTool.output_schema$   s    ---    c                   ddl m} |xs |j                  }	|	dk(  rt        d      |xs |j                  xs d}
t        |      }|gt        j                  |      }|j                  j                         D ]5  \  }}t        |j                        t        |j                  |      s3|} n t        |||gng |      }|j                  j                  d      } | ||	||
|||||		      S )
zCreate a Tool from a function.r   r   z<lambda>z,You must provide a name for lambda functions )
skip_namesstructured_outputT)by_alias)	r   r   r   r   r   r    r"   r#   r   )mcp.server.fastmcp.serverr   __name__
ValueError__doc___is_async_callableinspect	signaturer   itemsr   
annotation
issubclassr   	arg_modelmodel_json_schema)clsr   r   r   r   r#   r   r-   r   	func_namefunc_docr"   sig
param_nameparamfunc_arg_metadatar   s                    r(   from_functionzTool.from_function(   s    	6'BKK	
"KLL2"**2%b) ##B'C%(^^%9%9%; !
Ee../;e..8$.M **7*C/

 '00BBDBQ
 !)'#

 
	
r)   c                P  K   	 | j                   j                  | j                  | j                  || j                  | j                  |ind       d{   }|r| j                   j                  |      }|S 7 ## t        $ r!}t        d| j                   d|       |d}~ww xY ww)zRun the tool with arguments.NzError executing tool z: )	r    call_fn_with_arg_validationr   r"   r#   convert_result	Exceptionr   r   )r'   	argumentscontextrE   resultes         r(   runzTool.runZ   s     	M++GG151C1C1O##W-UY	 F ))88@M  	M3DII;bDE1L	Ms;   B&AA9 A7"A9 6B&7A9 9	B#BB##B&)returnzdict[str, Any] | None)NNNNNN)r   r   r   r   r   r   r   r   r#   r   r   r$   r-   zbool | NonerL   r   )NF)rG   r   rH   z:Context[ServerSessionT, LifespanContextT, RequestT] | NonerE   r!   rL   r   )r0   
__module____qualname__r2   r
   r   __annotations__r   r   r   r   r    r"   r#   r   r   r&   classmethodrB   rK    r)   r(   r   r      sf   *"40B0"45D#5d0RSE:S)LMKM!&3T!UJU %_!K  'BCHdC %d8g hM:h*/Be*fK'f. .    "&$(.2)-/
/
 /
 	/

  /
 "/
 ,/
 '/
 
/
 /
h OS$	M!M LM 	M
 
Mr)   r   c                   t        | t        j                        r'| j                  } t        | t        j                        r't	        j
                  |       xs- t        |       xr  t	        j
                  t        | dd             S )N__call__)
isinstance	functoolspartialfuncr4   iscoroutinefunctioncallablegetattr)objs    r(   r3   r3   q   sg    
S)++
,hh S)++
, &&s+ U'55gc:t6TUr)   )r[   r   rL   r!   )
__future__r   _annotationsrU   r4   collections.abcr   r   typingr   r   r   pydanticr	   r
   mcp.server.fastmcp.exceptionsr   *mcp.server.fastmcp.utilities.func_metadatar   r   	mcp.typesr   r/   r   mcp.server.sessionr   mcp.shared.contextr   r   r   r3   rQ   r)   r(   <module>rf      sH    2   $ % 1 1 % 3 R %11=YM9 YMxr)   