
    !<i~                        d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
mZmZ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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S )z Resource template functionality.    )annotationsN)Callable)TYPE_CHECKINGAny)	BaseModelFieldvalidate_call)FunctionResourceResource)find_context_parameterinject_context)func_metadata)AnnotationsIcon)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d          Z
ded<    ed	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	d           Zded!<   e	 	 	 	 	 	 	 d,d-d#            Zd.d&Z	 d/d0d+Zd	S )1ResourceTemplatez.A template for dynamically creating resources.z<URI template with parameters (e.g. weather://{city}/current))descriptionstruri_templatezName of the resourcenamez$Human-readable title of the resourceN)r   default
str | Nonetitlez%Description of what the resource doesr   
text/plainz!MIME type of the resource content)r   r   	mime_typez0Optional list of icons for the resource templatelist[Icon] | Noneiconsz.Optional annotations for the resource templateAnnotations | Noner   T)excludeCallable[..., Any]fnz#JSON schema for function parametersdict[str, Any]
parametersz-Name of the kwarg that should receive contextcontext_kwargreturnc
                   |p|j         }
|
dk    rt          d          |	t          |          }	t          ||	|	gng           }|j                                        }t          |          } | ||
||p|j        pd|pd|||||	
  
        S )z"Create a template from a function.z<lambda>z,You must provide a name for lambda functionsN)
skip_names r   )
r   r   r   r   r   r!   r   r%   r'   r(   )__name__
ValueErrorr   r   	arg_modelmodel_json_schemar	   __doc__)clsr%   r   r   r   r   r   r!   r   r(   	func_namefunc_arg_metadatar'   s                /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/mcp/server/fastmcp/resources/templates.pyfrom_functionzResourceTemplate.from_function%   s     'BK	
""KLLL  2266M **7*C
 
 
 '0BBDD
 2s%#7rz7R/<#!'
 
 
 	
    uridict[str, Any] | Nonec                    | j                             dd                              dd          }t          j        d| d|          }|r|                                S dS )z5Check if URI matches template and extract parameters.{z(?P<}z>[^/]+)^$N)r   replacerematch	groupdict)selfr8   patternrA   s       r5   matcheszResourceTemplate.matchesR   sb     #++C88@@iPPW-- 	%??$$$tr7   paramscontext:Context[ServerSessionT, LifespanContextT, RequestT] | Noner   c                L  K   	 t          | j        ||| j                  } | j        di |t          j                  r d{V t          || j        | j        | j        | j	        | j
        | j        fd          S # t          $ r}t          d|           d}~ww xY w)z>Create a resource from the template with the given parameters.Nc                      S N )results   r5   <lambda>z2ResourceTemplate.create_resource.<locals>.<lambda>s   s    6 r7   )r8   r   r   r   r   r!   r   r%   z'Error creating resource from template: rL   )r   r%   r(   inspectiscoroutiner
   r   r   r   r   r!   r   	Exceptionr.   )rC   r8   rF   rG   erM   s        @r5   create_resourcez ResourceTemplate.create_resource[   s      	L#DGVWd>PQQF TW&&v&&F"6** &%#Yj ,.j ,!>>>	 	 	 	  	L 	L 	LJqJJKKK	Ls   A<B 
B#BB#)NNNNNNN)r%   r$   r   r   r   r   r   r   r   r   r   r   r!   r    r   r"   r(   r   r)   r   )r8   r   r)   r9   rK   )r8   r   rF   r&   rG   rH   r)   r   )r-   
__module____qualname__r1   r   r   __annotations__r   r   r   r   r!   r   r%   r'   r(   classmethodr6   rE   rS   rL   r7   r5   r   r      s        88*hiiiLiiii"8999D9999*PZ^___E____#e0WXXXKXXXXU<=`aaaIaaaa$uT?qrrrErrrr&+eDFv&w&w&wKwwww"U4000B0000!&3X!Y!Y!YJYYYY %d8g h h hMhhhh
   "& $#'*.$(*
 *
 *
 *
 [*
X    OS	L L L L L L Lr7   r   )!r1   
__future__r   rO   r@   collections.abcr   typingr   r   pydanticr   r   r	   "mcp.server.fastmcp.resources.typesr
   r   .mcp.server.fastmcp.utilities.context_injectionr   r   *mcp.server.fastmcp.utilities.func_metadatar   	mcp.typesr   r   mcp.server.fastmcp.serverr   mcp.server.sessionr   mcp.shared.contextr   r   r   rL   r7   r5   <module>rc      s]   & & " " " " " "  				 $ $ $ $ $ $ % % % % % % % % 4 4 4 4 4 4 4 4 4 4 I I I I I I I I a a a a a a a a D D D D D D ' ' ' ' ' ' ' ' >111111111111========_L _L _L _L _Ly _L _L _L _L _Lr7   