
    )`iS                        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	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d0d(Z	 d1d2d-Zd	S )3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   z,Optional metadata for this resource templatedict[str, Any] | NonemetaT)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)   r*   )__name__
ValueErrorr   r   	arg_modelmodel_json_schemar	   __doc__)clsr'   r   r   r   r   r   r!   r   r$   r*   	func_namefunc_arg_metadatar)   s                 z/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/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/<#!'
 
 
 	
    uric                    | 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)selfr:   patternrB   s       r7   matcheszResourceTemplate.matchesU   sb     #++C88@@iPPW-- 	%??$$$tr9   paramscontext:Context[ServerSessionT, LifespanContextT, RequestT] | Noner   c                X  K   	 t          | j        ||| j                  } | j        di |t          j                  r d{V t          || j        | 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   r7   <lambda>z2ResourceTemplate.create_resource.<locals>.<lambda>w   s    6 r9   )	r:   r   r   r   r   r!   r   r$   r'   z'Error creating resource from template: rM   )r   r'   r*   inspectiscoroutiner
   r   r   r   r   r!   r   r$   	Exceptionr0   )rD   r:   rG   rH   erN   s        @r7   create_resourcez ResourceTemplate.create_resource^   s      	L#DGVWd>PQQF TW&&v&&F"6** &%#Yj ,.j ,Y!>>>
 
 
 
  	L 	L 	LJqJJKKK	Ls   BB 
B)B$$B))NNNNNNNN)r'   r&   r   r   r   r   r   r   r   r   r   r   r!   r    r   r"   r$   r#   r*   r   r+   r   )r:   r   r+   r#   rL   )r:   r   rG   r(   rH   rI   r+   r   )r/   
__module____qualname__r3   r   r   __annotations__r   r   r   r   r!   r   r$   r'   r)   r*   classmethodr8   rF   rT   rM   r9   r7   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"'%Bp"q"q"qDqqqq"U4000B0000!&3X!Y!Y!YJYYYY %d8g h h hMhhhh
   "& $#'*.&*$(,
 ,
 ,
 ,
 [,
\    OS	L L L L L L Lr9   r   )!r3   
__future__r   rP   rA   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   rM   r9   r7   <module>rd      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========cL cL cL cL cLy cL cL cL cL cLr9   