
    k7i                         S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	  SSK
r
SSKJrJr  SSKJr  SSKJrJrJrJrJrJr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  \(       a    " S S\5      r " S S\5      r g)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)FastMCPComponent)find_kwarg_by_typeget_fn_namec                    ^  \ rS rSr% Sr\" SS9r\" SSS9rS\	S	'   \" S
SS9r
S\	S'   \" SSSS9rS\	S'   SrS\	S'   S$U 4S jjrS$U 4S jjr\         S%                       S&S jj5       r\" SSS9\S'S j5       5       r\" SS9S(S j5       rS)S jrSS.     S*S  jjrS+S! jr\S+S" j5       rS#rU =r$ ),r
   !   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 contentz^[a-zA-Z0-9]+/[a-zA-Z0-9\-+.]+$)r   r   pattern	mime_typeNzfAnnotated[Annotations | None, Field(description="Optional annotations about the resource's behavior")]r   c                x   > [         TU ]  5          [        5       nUR                  5         g ! [         a     g f = fN)superenabler   _queue_resource_list_changedRuntimeErrorselfcontext	__class__s     T/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/resources/resource.pyr%   Resource.enable4   s7    	!mG002 		   , 
99c                x   > [         TU ]  5          [        5       nUR                  5         g ! [         a     g f = fr#   )r$   disabler   r&   r'   r(   s     r,   r0   Resource.disable<   s7    	!mG002 		r.   c                <    [         R                  U UUUUUUUUU	U
S9$ )Nfnr   r   titler   iconsr!   tagsenabledr   meta)FunctionResourcefrom_functionr3   s              r,   r;   Resource.from_functionD   s=      --## . 
 	
    before)modec                    U(       a  U$ g)z&Set default MIME type if not provided.r    )clsr!   s     r,   set_default_mime_typeResource.set_default_mime_type`   s     r=   afterc                    U R                   (       a   U $ U R                  (       a  [        U R                  5      U l         U $ [        S5      e)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_nameResource.set_default_nameh   sB     99
 	 XXDHHDI  BCCr=   c                    #    [        S5      e7f)z}Read the resource content.

This method is not implemented in the base Resource class and must be
implemented by subclasses.
z Subclasses must implement read())NotImplementedErrorrH   s    r,   readResource.reads   s      ""DEEs   include_fastmcp_metac                  [        UR                  SU R                  5      UR                  SU R                  5      UR                  SU R                  5      UR                  SU R
                  5      UR                  SU R                  5      UR                  SU R                  5      UR                  SU R                  5      UR                  SU R                  US	95      S
9$ )z'Convert the resource to an MCPResource.r   r   r   mimeTyper5   r6   r   _metarO   )r   r   r   rR   r5   r6   r   rS   )
MCPResourcegetr   r   r   r!   r5   r6   r   get_meta)r)   rP   	overridess      r,   to_mcp_resourceResource.to_mcp_resource{   s     vtyy1eTXX.!mT5E5EF]]:t~~>--4--4!mT5E5EF--<PQ
 	
r=   c           
         U R                   R                   SU R                  < SU R                  < SU R                  < SU R
                   S3
$ )Nz(uri=z, name=z, description=z, tags=))r+   __name__r   r   r   r7   rH   s    r,   __repr__Resource.__repr__   sb    ..))*%|7499-~^b^n^n]qqxy}  zC  zC  yD  DE  F  	Fr=   c                R    U R                   =(       d    [        U R                  5      $ )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   rH   s    r,   keyResource.key   s     yy)CM)r=   )r   )returnNone	NNNNNNNNNr4   Callable[..., Any]r   zstr | AnyUrlr   
str | Noner5   rh   r   rh   r6   zlist[Icon] | Noner!   rh   r7   zset[str] | Noner8   bool | Noner   zAnnotations | Noner9   zdict[str, Any] | Nonerc   r:   )r!   rh   rc   r   )rc   r   rc   zstr | bytes)rP   ri   rW   r   rc   rT   )rc   r   )r\   
__module____qualname____firstlineno____doc__r   model_configr   r   __annotations__r   r!   r   r%   r0   staticmethodr;   r   classmethodrC   r   rI   rM   rX   r]   propertyra   __static_attributes____classcell__)r+   s   @r,   r
   r
   !   s   't4LBG!6CC	?  b.DED#E72Is  	   
    "&#' $ $#*.&*


 
 	

  
 !
 
 
 
 (
 $
 

 
6 [x0  1 '" #F -1
 *
 	

 

*F * *r=   r
   c                      \ rS rSr% SrS\S'   \         S	                       S
S jj5       rSS jrSr	g)r:      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
rg   r4   Nc                    [        U[        5      (       a  [        U5      nU " UUU=(       d    [        U5      UU=(       d    [        R
                  " U5      UU=(       d    SU=(       d
    [        5       U	b  U	OSU
US9$ )z*Create a FunctionResource from a function.r   Tr3   )
isinstancer   r   r   inspectgetdocset)rB   r4   r   r   r5   r   r6   r!   r7   r8   r   r9   s               r,   r;   FunctionResource.from_function   sq      c3+C(R#9w~~b'9/<&2G#
 	
r=   c                  #    SSK Jn  0 n[        U R                  US9nUb  [	        5       X#'   U R                  " S0 UD6n[
        R                  " U5      (       a
  UI Sh  vN n[        U[        5      (       a  UR                  5       I Sh  vN $ [        U[        [        -  5      (       a  U$ [        R                  " U[        S9R                  5       $  Nv NK7f)z2Read the resource by calling the wrapped function.r   )Context)
kwarg_typeN)fallbackrA   )fastmcp.server.contextr   r   r4   r   rz   isawaitablery   r
   rM   bytesr   pydantic_coreto_jsondecode)r)   r   kwargscontext_kwargresults        r,   rM   FunctionResource.read   s     2*477wG$$/MF!"6"v&&!\Ffh''&&,,M ((#>EEGG " 's%   AC C!,CCA
CCrA   re   rf   rj   )
r\   rk   rl   rm   rn   rp   rr   r;   rM   rt   rA   r=   r,   r:   r:      s    
 	
   "&#' $ $#*.&*

 
 	

 
  
 !
 
 
 
 (
 $
 

 
>Hr=   r:   )!rn   
__future__r   rz   collections.abcr   typingr   r   r   r   	mcp.typesr   r	   r
   rT   pydanticr   r   r   r   r   r   typing_extensionsr   fastmcp.server.dependenciesr   fastmcp.utilities.componentsr   fastmcp.utilities.typesr   r   r:   rA   r=   r,   <module>r      sb    8 "  $ 0 0  ' -  # 3 9
 z* z*zAHx AHr=   