
    i                        d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZ d dlZd dlmZ  ed	e
      Z G d ded      ZddZ G d de      Z G d de      Zy)    )annotations)Sequence)	AnnotatedAny	TypedDictcast)Icon)BeforeValidatorFieldPrivateAttr)SelfTypeVarN)FastMCPBaseModelTdefaultc                      e Zd ZU ded<   y)FastMCPMetaz	list[str]tagsN)__name__
__module____qualname____annotations__     /home/jay/workspace/.worktrees/task-2116-dev1/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/utilities/components.pyr   r      s    
Or   r   F)totalc                T    | 
t               S t        | t               r| S t        |       S )z@Convert a sequence to a set, defaulting to an empty set if None.)set
isinstance)	maybe_sets    r   _convert_set_default_noner"      s)    u)S!y>r   c                      e Zd ZU dZ 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e
d      Zded<    edd      Zded<    edd      Zded<    e       Zd	ed<   ddd( fdZed)d       Z	 d*	 	 	 d+dZdd dd!	 	 	 	 	 	 	 d, fd"Zd-d#Zd)d$Zd.d%Zd.d&Zd/d'Z xZS )0FastMCPComponentzIBase class for FastMCP tools, prompts, resources, and resource templates.zThe name of the component.)descriptionstrnameNz0The title of the component for display purposes.)r   r%   
str | Nonetitlez!The description of the component.r%   zHOptional list of icons for this component to display in user interfaces.zlist[Icon] | NoneiconszTags for the component.)default_factoryr%   z?Annotated[set[str], BeforeValidator(_convert_set_default_none)]r   z$Meta information about the componentdict[str, Any] | NonemetaTz!Whether the component is enabled.boolenabled_key)keyc               2    t        |   di | || _        y Nr   )super__init__r0   )selfr1   kwargs	__class__s      r   r5   zFastMCPComponent.__init__=   s    "6"	r   c                6    | j                   xs | 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.
        )r0   r'   r6   s    r   r1   zFastMCPComponent.keyA   s     yy%DII%r   c                    |t         j                  j                  }| j                  xs i }|r<t	        t        | j                              }|j                  d      x}r||z  }||d<   |xs dS )z
        Get the meta information about the component.

        If include_fastmcp_meta is True, a `_fastmcp` key will be added to the
        meta, containing a `tags` field with the tags of the component.
        N)r   _fastmcp)fastmcpsettingsinclude_fastmcp_metar-   r   sortedr   get)r6   r?   r-   fastmcp_metaupstream_metas        r   get_metazFastMCPComponent.get_metaK   sq      '#*#3#3#H#H yyB&F499,=>L $ 44}4,|;+D|tr   F)updatedeepr1   c               X    t         |   ||      }|||_        t        t        |      S )z
        Create a copy of the component.

        Args:
            update: A dictionary of fields to update.
            deep: Whether to deep copy the component.
            key: The key to use for the copy.
        )rE   rF   )r4   
model_copyr0   r   r   )r6   rE   rF   r1   copyr8   s        r   rH   zFastMCPComponent.model_copyc   s2    $ w!d!;?DID$r   c                    t        |       t        |      uryt        |t        |             sy| j                         |j                         k(  S )NF)typer    
model_dump)r6   others     r   __eq__zFastMCPComponent.__eq__z   sA    :T%[(%d, E$4$4$666r   c                    | j                   j                   d| j                  d| j                  d| j                  d| j
                   d| j                   dS )Nz(name=z, title=z, description=z, tags=z
, enabled=))r8   r   r'   r)   r%   r   r/   r:   s    r   __repr__zFastMCPComponent.__repr__   s    ..))*&Xdjj^Sabfbrbrauu|  ~B  ~G  ~G  }H  HR  SW  S_  S_  R`  `a  b  	br   c                    d| _         y)Enable the component.TNr/   r:   s    r   enablezFastMCPComponent.enable   s	    r   c                    d| _         y)Disable the component.FNrT   r:   s    r   disablezFastMCPComponent.disable   s	    r   c                "    | j                         S )zCreate a copy of the component.)rH   r:   s    r   rI   zFastMCPComponent.copy   s      r   )r1   r(   r7   r   returnNone)rZ   r&   )N)r?   zbool | NonerZ   r,   )rE   r,   rF   r.   r1   r(   rZ   r   )rM   objectrZ   r.   rZ   r[   rZ   r   )r   r   r   __doc__r   r'   r   r)   r%   r*   r   r   r-   r/   r   r0   r5   propertyr1   rD   rH   rN   rQ   rU   rX   rI   __classcell__r8   s   @r   r$   r$      sL   S0D#  FE:  $7K   %^ E  MR-MD
I  #("H#D
  7GT 
 #}D*$,0  & & 37$/	6 )-  &  	 
   
 .7b!r   r$   c                  h     e Zd ZU dZ ed      Zded<   ddd fdZd fdZd fd	Z	dd
Z
 xZS )MirroredComponentzBase class for components that are mirrored from a remote server.

    Mirrored components cannot be enabled or disabled directly. Call copy() first
    to create a local version you can modify.
    Fr   r.   	_mirrored)re   c               2    t        |   di | || _        y r3   )r4   r5   re   )r6   re   r7   r8   s      r   r5   zMirroredComponent.__init__   s    "6""r   c                    | j                   r&t        d| j                   d| j                   d      t        |           y)rS   z"Cannot enable mirrored component '"'. Create a local copy first with ".copy() and add it to your server.N)re   RuntimeErrorr'   r4   rU   r6   r8   s    r   rU   zMirroredComponent.enable   sF    >>4TYYK @226))<^`  	r   c                    | j                   r&t        d| j                   d| j                   d      t        |           y)rW   z#Cannot disable mirrored component 'rh   ri   N)re   rj   r'   r4   rX   rk   s    r   rX   zMirroredComponent.disable   sF    >>5dii[ A226))<^`  	r   c                4    | j                         }d|_        |S )z4Create a copy of the component that can be modified.F)rH   re   )r6   copieds     r   rI   zMirroredComponent.copy   s     " r   )re   r.   r7   r   rZ   r[   r]   r^   )r   r   r   r_   r   re   r   r5   rU   rX   rI   ra   rb   s   @r   rd   rd      s0     "%0It0,1 #r   rd   )r!   zset[T] | Sequence[T] | NonerZ   zset[T])
__future__r   collections.abcr   typingr   r   r   r   	mcp.typesr	   pydanticr
   r   r   typing_extensionsr   r   r=   fastmcp.utilities.typesr   r   r   r"   r$   rd   r   r   r   <module>rv      s_    " $ 2 2  8 8 +  4C)5 q!' q!h$( $r   