
    Ch6                        S SK Jr  S SKrS SKrS SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJr  S SKJr  S SKJr  S S	KJrJr  S S
KJrJr  \	(       a  S SKJr  S SKJr  S SKJrJr   " S S\5      rSS jr g)    )annotationsN)Callable)cached_property)TYPE_CHECKINGAny)	BaseModelField)	ToolError)find_context_parameter)FuncMetadatafunc_metadata)IconToolAnnotations)Context)ServerSessionT)LifespanContextTRequestTc                  z   \ rS rSr% Sr\" SS9rS\S'   \" SS9rS	\S
'   \" SSS9r	S\S'   \" SS9r
S	\S'   \" SS9rS\S'   \" SS9rS\S'   \" SS9rS\S'   \" SSS9rS\S'   \" SSS9rS\S'   \" SSS 9rS!\S"'   \S'S# j5       r\       S(                 S)S$ jj5       r  S*       S+S% jjrS&rg),Tool   z 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   z$Optional list of icons for this tool)defaultr   list[Icon] | Noneiconsc                .    U R                   R                  $ )N)r!   output_schema)selfs    W/home/james-whalen/.local/lib/python3.13/site-packages/mcp/server/fastmcp/tools/base.pyr*   Tool.output_schema&   s    ---    c	                .   U=(       d    UR                   n	U	S:X  a  [        S5      eU=(       d    UR                  =(       d    Sn
[        U5      nUc  [	        U5      n[        UUb  U/O/ US9nUR                  R                  SS9nU " UU	UU
UUUUUUS9
$ )zCreate a Tool from a function.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   r(   )__name__
ValueError__doc___is_async_callabler   r   	arg_modelmodel_json_schema)clsr   r   r   r   r$   r   r(   r2   	func_namefunc_docr#   func_arg_metadatar    s                 r,   from_functionTool.from_function*   s     'BKK	
"KLL2"**2%b) 226M)*7*C/

 '00BBDBQ
 !)'#
 	
r.   c                ^  #     U R                   R                  U R                  U R                  UU R                  b  U R                  U0OS5      I Sh  vN nU(       a  U R                   R                  U5      nU$  N(! [         a!  n[        SU R                   SU 35      UeSnAff = f7f)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contextrB   resultes         r,   runTool.runV   s     	M++GG151C1C1O##W-UY	 F ))88@M  	M3DII;bDE1L	Ms;   B-AA? A='A? <B-=A? ?
B*	B%%B**B- )returnzdict[str, Any] | None)NNNNNNN)r   r   r   r   r   r   r   r   r$   r   r   r%   r(   r'   r2   zbool | NonerK   r   )NF)rD   r   rE   z:Context[ServerSessionT, LifespanContextT, RequestT] | NonerB   r"   rK   r   )r4   
__module____qualname____firstlineno__r6   r	   r   __annotations__r   r   r   r    r!   r#   r$   r   r(   r   r*   classmethodr>   rH   __static_attributes__rJ   r.   r,   r   r      s   *"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$T?efEf. .    "&$(.2#')-)
)
 )
 	)

  )
 ")
 ,)
 !)
 ')
 
)
 )
\ OS$	M!M LM 	M
 
M Mr.   r   c                :   [        U [        R                  5      (       a-  U R                  n [        U [        R                  5      (       a  M-  [        R
                  " U 5      =(       d3    [        U 5      =(       a!    [        R
                  " [        U SS 5      5      $ )N__call__)
isinstance	functoolspartialfuncinspectiscoroutinefunctioncallablegetattr)objs    r,   r7   r7   m   sm    
S)++
,
,hh S)++
,
, &&s+ U'55gc:t6TUr.   )r\   r   rK   r"   )!
__future__r   _annotationsrU   rX   collections.abcr   r   typingr   r   pydanticr   r	   mcp.server.fastmcp.exceptionsr
   .mcp.server.fastmcp.utilities.context_injectionr   *mcp.server.fastmcp.utilities.func_metadatar   r   	mcp.typesr   r   mcp.server.fastmcp.serverr   mcp.server.sessionr   mcp.shared.contextr   r   r   r7   rJ   r.   r,   <module>ri      sH    2   $ % % % 3 Q R +11=TM9 TMnr.   