
    )`i                        d Z ddl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 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  ee          Z G d d          ZdS )zResource manager functionality.    )annotations)Callable)TYPE_CHECKINGAny)AnyUrl)Resource)ResourceTemplate)
get_logger)AnnotationsIcon)Context)ServerSessionT)LifespanContextTRequestTc                  X    e Zd ZdZd&d'dZd(d	Z	 	 	 	 	 	 	 d)d*dZ	 d+d,d!Zd-d#Zd.d%Z	d
S )/ResourceManagerzManages FastMCP resources.Twarn_on_duplicate_resourcesboolc                0    i | _         i | _        || _        d S N)
_resources
_templatesr   )selfr   s     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/mcp/server/fastmcp/resources/resource_manager.py__init__zResourceManager.__init__   s    /179+F(((    resourcer   returnc                h   t                               d|j        t          |          j        |j        d           | j                            t          |j                            }|r+| j	        r"t           
                    d|j                    |S || j        t          |j                  <   |S )zAdd a resource to the manager.

        Args:
            resource: A Resource instance to add

        Returns:
            The added resource. If a resource with the same URI already exists,
            returns the existing resource.
        zAdding resource)urityperesource_nameextrazResource already exists: )loggerdebugr    r!   __name__namer   getstrr   warning)r   r   existings      r   add_resourcezResourceManager.add_resource   s     	|X/!)  	 	
 	
 	
 ?&&s8<'8'899 	/ KI8<IIJJJO-5HL))*r   NfnCallable[..., Any]uri_templater*   r(   
str | Nonetitledescription	mime_typeiconslist[Icon] | Noner   Annotations | Nonemetadict[str, Any] | Noner	   c
                ^    t          j        |||||||||		  	        }
|
| j        |
j        <   |
S )zAdd a template from a function.)r0   r(   r2   r3   r4   r5   r   r8   )r	   from_functionr   r0   )r   r.   r0   r(   r2   r3   r4   r5   r   r8   templates              r   add_templatezResourceManager.add_template9   sL     $1%##

 

 

 2:-.r   r    AnyUrl | strcontext:Context[ServerSessionT, LifespanContextT, RequestT] | NoneResource | Nonec                  K   t          |          }t                              dd|i           | j                            |          x}r|S | j                                        D ]^}|                    |          x}rE	 |                    |||           d{V c S # t          $ r}t          d|           d}~ww xY w_t          d|           )zGGet resource by URI, checking concrete resources first, then templates.zGetting resourcer    r#   )r?   Nz'Error creating resource from template: zUnknown resource: )r*   r%   r&   r   r)   r   valuesmatchescreate_resource	Exception
ValueError)r   r    r?   uri_strr   r<   paramses           r   get_resourcezResourceManager.get_resourceT   s#      c(('w/?@@@ **73338 	O ..00 	T 	TH!))'222v TT!)!9!9'6SZ!9![![[[[[[[[[[  T T T$%Rq%R%RSSSTT 3c33444s   B!!
C+B==Clist[Resource]c                    t                               ddt          | j                  i           t	          | j                                                  S )zList all registered resources.zListing resourcescountr#   )r%   r&   lenr   listrC   r   s    r   list_resourceszResourceManager.list_resourcesk   D    (#do:N:N0OPPPDO**,,---r   list[ResourceTemplate]c                    t                               ddt          | j                  i           t	          | j                                                  S )zList all registered templates.zListing templatesrN   r#   )r%   r&   rO   r   rP   rC   rQ   s    r   list_templateszResourceManager.list_templatesp   rS   r   )T)r   r   )r   r   r   r   )NNNNNNN)r.   r/   r0   r*   r(   r1   r2   r1   r3   r1   r4   r1   r5   r6   r   r7   r8   r9   r   r	   r   )r    r>   r?   r@   r   rA   )r   rL   )r   rT   )
r'   
__module____qualname____doc__r   r-   r=   rK   rR   rV    r   r   r   r      s        $$G G G G G
   <   "& $#'*.&*    < OS5 5 5 5 5.. . . .
. . . . . .r   r   N)rY   
__future__r   collections.abcr   typingr   r   pydanticr   !mcp.server.fastmcp.resources.baser   &mcp.server.fastmcp.resources.templatesr	   $mcp.server.fastmcp.utilities.loggingr
   	mcp.typesr   r   mcp.server.fastmcp.serverr   mcp.server.sessionr   mcp.shared.contextr   r   r'   r%   r   rZ   r   r   <module>rf      s6   % % " " " " " " $ $ $ $ $ $ % % % % % % % %       6 6 6 6 6 6 C C C C C C ; ; ; ; ; ; ' ' ' ' ' ' ' ' >111111111111========	H		\. \. \. \. \. \. \. \. \. \.r   