
    "<i                        d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
Z
ddlmZmZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddl m!Z! er	  G d de          Z G d de          Z"dS )z2Base classes and interfaces for FastMCP resources.    )annotationsN)Callable)TYPE_CHECKING	AnnotatedAny)AnnotationsIcon)Resource)AnyUrl
ConfigDictFieldUrlConstraintsfield_validatormodel_validator)Self)get_contextwithout_injected_parameters
TaskConfig)FastMCPComponent)get_fn_namec                      e Zd ZU dZ ed          Z edd          Zded<    ed	d
          Z	ded<    edd          Z
ded<   dZded<   d: fdZd: fdZe	 	 	 	 	 	 	 	 	 	 d;d<d)            Z edd*+          ed=d,                        Z ed-+          d>d/            Zd?d1Zdd2d@d7ZdAd8ZedAd9            Z xZS )Br
   zBase class for all resources.T)validate_default.zURI of the resource)defaultdescriptionz6Annotated[AnyUrl, UrlConstraints(host_required=False)]uri zName of the resourcestrname
text/plainz!MIME type of the resource content	mime_typeNzfAnnotated[Annotations | None, Field(description="Optional annotations about the resource's behavior")]r   returnNonec                    t                                                       	 t                      }|                                 d S # t          $ r Y d S w xY wN)superenabler   _queue_resource_list_changedRuntimeErrorselfcontext	__class__s     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/resources/resource.pyr'   zResource.enable3   s_    	!mmG0022222 	 	 	DD	   "A 
AAc                    t                                                       	 t                      }|                                 d S # t          $ r Y d S w xY wr%   )r&   disabler   r(   r)   r*   s     r.   r1   zResource.disable;   s_    	!mmG0022222 	 	 	DD	r/   fnCallable[..., Any]str | AnyUrl
str | Nonetitler   iconslist[Icon] | Nonetagsset[str] | Noneenabledbool | NoneAnnotations | Nonemetadict[str, Any] | Nonetaskbool | TaskConfig | NoneFunctionResourcec                N    t                               | |||||||||	|
|          S )Nr2   r   r   r6   r   r7   r!   r9   r;   r   r>   r@   )rB   from_functionrD   s               r.   rE   zResource.from_functionC   sE      --## . 
 
 	
    beforemodec                    |r|S dS )z&Set default MIME type if not provided.r     )clsr!   s     r.   set_default_mime_typezResource.set_default_mime_typea   s      	|rF   afterr   c                v    | j         rn0| j        rt          | j                  | _         nt          d          | S )z*Set default name from URI if not provided.z#Either name or uri must be provided)r   r   r   
ValueErrorr+   s    r.   set_default_namezResource.set_default_namei   sB     9 	DX 	DDHDIIBCCCrF   str | bytesc                $   K   t          d          )zRead the resource content.

        This method is not implemented in the base Resource class and must be
        implemented by subclasses.
        z Subclasses must implement read())NotImplementedErrorrQ   s    r.   readzResource.readt   s       ""DEEErF   include_fastmcp_metarX   	overridesr   MCPResourcec                  t          |                    d| j                  |                    d| j                  |                    d| j                  |                    d| j                  |                    d| j                  |                    d| j                  |                    d| j                  |                    d| 	                    |	                    
          S )z'Convert the resource to an MCPResource.r   r   r   mimeTyper6   r7   r   _metarW   )r   r   r   r\   r6   r7   r   r]   )
rZ   getr   r   r   r!   r6   r7   r   get_meta)r+   rX   rY   s      r.   to_mcp_resourcezResource.to_mcp_resource|   s     vty11eTX..!mT5EFF]]:t~>>--44--44!mT5EFF--<PQQ 
 
 
 	
rF   c           
     `    | j         j         d| j        d| j        d| j        d| j         d
S )Nz(uri=z, name=z, description=z, tags=))r-   __name__r   r   r   r9   rQ   s    r.   __repr__zResource.__repr__   sj    .)  F  F  F  F49  F  F^b^n  F  Fy}  zC  F  F  F  	FrF   c                8    | j         pt          | j                  S )a*  
        The key of the component. This is used for internal bookkeeping
        and may reflect e.g. prefixes or other identifiers. You should not depend on
        keys having a certain value, as the same tool loaded from different
        hierarchies of servers may have different keys.
        )_keyr   r   rQ   s    r.   keyzResource.key   s     y)CMM)rF   )r"   r#   
NNNNNNNNNNr2   r3   r   r4   r   r5   r6   r5   r   r5   r7   r8   r!   r5   r9   r:   r;   r<   r   r=   r>   r?   r@   rA   r"   rB   )r!   r5   r"   r   )r"   r   r"   rS   )rX   r<   rY   r   r"   rZ   )r"   r   )rc   
__module____qualname____doc__r   model_configr   r   __annotations__r   r!   r   r'   r1   staticmethodrE   r   classmethodrM   r   rR   rV   r`   rd   propertyrg   __classcell__)r-   s   @r.   r
   r
   !   s9        '':t444LBG%!6C C CC     b.DEEEDEEEEU7  I     	     
              "&#' $ $#*.&*)-
 
 
 
 \
: _[x000   [ 10 _'"""   #"F F F F -1
 
 
 
 
 
*F F F F * * * X* * * * *rF   r
   c                  x    e Zd ZU dZded<    ed           Zded<   e	 	 	 	 	 	 	 	 	 	 d d!d            Zd"dZ	dS )#rB   a  A resource that defers data loading by wrapping a function.

    The function is only called when the resource is read, allowing for lazy loading
    of potentially expensive data. This is particularly useful when listing resources,
    as the function won't be called until the resource is actually accessed.

    The function can return:
    - str for text content (default)
    - bytes for binary content
    - other types will be converted to JSON
    r3   r2   c                 "    t          d          S )N	forbiddenrH   r   rK   rF   r.   <lambda>zFunctionResource.<lambda>   s    jk&B&B&B rF   )default_factoryz_Annotated[TaskConfig, Field(description='Background task execution configuration (SEP-1686).')]task_configNr   r4   r   r5   r6   r   r7   r8   r!   r9   r:   r;   r<   r   r=   r>   r?   r@   rA   r"   c                   t          |t                    rt          |          }|pt          |          }|t	          d          }n,t          |t
                    rt	          j        |          }n|}|                    ||           t          |          } | |||pt          |          ||pt          j
        |          ||pd|pt                      |	|	nd|
||          S )z*Create a FunctionResource from a function.Nrv   rH   r    T)r2   r   r   r6   r   r7   r!   r9   r;   r   r>   ry   )
isinstancer   r   r   r   bool	from_boolvalidate_functionr   inspectgetdocset)rL   r2   r   r   r6   r   r7   r!   r9   r;   r   r>   r@   	func_namery   
wrapped_fns                   r.   rE   zFunctionResource.from_function   s   " c3 	++C+KOO	 <$+666KKd## 	$.t44KKK%%b)444 144
s(R#9w~b'9'9/<&2GG##
 
 
 	
rF   rS   c                \  K   |                                  }t          j        |          r| d{V }t          |t                    r|                                 d{V S t          |t          t          z            r|S t          j	        |t                    
                                S )z2Read the resource by calling the wrapped function.N)fallback)r2   r   isawaitabler{   r
   rV   bytesr   pydantic_coreto_jsondecode)r+   results     r.   rV   zFunctionResource.read   s       v&& 	"!\\\\\\Ffh'' 	H&&&&&&&,, 	HM (#>>>EEGGGrF   rh   ri   rj   )
rc   rk   rl   rm   ro   r   ry   rq   rE   rV   rK   rF   r.   rB   rB      s         
 
  	BBCCC  D D D D
 
   "&#' $ $#*.&*)-.
 .
 .
 .
 [.
`H H H H H HrF   rB   )#rm   
__future__r   r   collections.abcr   typingr   r   r   r   	mcp.typesr   r	   r
   rZ   pydanticr   r   r   r   r   r   typing_extensionsr   fastmcp.server.dependenciesr   r   fastmcp.server.tasks.configr   fastmcp.utilities.componentsr   fastmcp.utilities.typesr   rB   rK   rF   r.   <module>r      s   8 8 " " " " " "  $ $ $ $ $ $ 0 0 0 0 0 0 0 0 0 0     ' ' ' ' ' ' ' ' - - - - - -                # " " " " " P P P P P P P P 2 2 2 2 2 2 9 9 9 9 9 9       	{* {* {* {* {* {* {* {*|QH QH QH QH QHx QH QH QH QH QHrF   