o
    h6                     @  s   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
 d dlmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZmZ e	r\d dlmZ d dlmZ d dlmZmZ G dd deZdddZ dS )    )annotationsN)Callable)cached_property)TYPE_CHECKINGAny)	BaseModelField)	ToolError)find_context_parameter)FuncMetadatafunc_metadata)IconToolAnnotations)Context)ServerSessionT)LifespanContextTRequestTc                   @  s
  e Zd ZU dZeddZded< eddZded	< ed
ddZded< eddZ	ded< eddZ
ded< eddZded< eddZded< ed
ddZded< ed
ddZded< ed
ddZd ed!< ed2d$d%Ze	
	
	
	
	
	
	
d3d4d(d)Z	
	*d5d6d0d1Zd
S )7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   z$Optional list of icons for this tool)defaultr   list[Icon] | Noneiconsreturndict[str, Any] | Nonec                 C  s   | j jS )N)r   output_schema)self r*   ^/var/www/html/openai_agents/venv/lib/python3.10/site-packages/mcp/server/fastmcp/tools/base.pyr(   &   s   zTool.output_schemastructured_outputbool | Nonec	                 C  s   |p|j }	|	dkrtd|p|jpd}
t|}|du r t|}t||dur)|gng |d}|jjdd}| ||	||
||||||d
S )	zCreate a Tool from a function.z<lambda>z,You must provide a name for lambda functions N)
skip_namesr,   T)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%   r,   	func_namefunc_docr    func_arg_metadatar   r*   r*   r+   from_function*   s2   
zTool.from_functionF	argumentscontext:Context[ServerSessionT, LifespanContextT, RequestT] | Noneconvert_resultr   c              
     sz   z#| j | j| j|| jdur| j|indI dH }|r"| j |}|W S  ty< } ztd| j d| |d}~ww )zRun the tool with arguments.NzError executing tool z: )	r   call_fn_with_arg_validationr   r    r!   r?   	Exceptionr	   r   )r)   r<   r=   r?   resulter*   r*   r+   runV   s   
zTool.run)r&   r'   )NNNNNNN)r   r   r   r   r   r   r   r   r!   r   r   r"   r%   r$   r,   r-   r&   r   )NF)r<   r   r=   r>   r?   r   r&   r   )r1   
__module____qualname__r3   r   r   __annotations__r   r   r   r   r   r    r!   r   r%   r   r(   classmethodr;   rD   r*   r*   r*   r+   r      s8   
 .r   objr   r&   r   c                 C  sB   t | tjr| j} t | tjst| p t| o tt| dd S )N__call__)
isinstance	functoolspartialfuncinspectiscoroutinefunctioncallablegetattr)rI   r*   r*   r+   r4   m   s   
r4   )rI   r   r&   r   )!
__future__r   _annotationsrL   rO   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   r4   r*   r*   r*   r+   <module>   s"    W