
    k7i"                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
JrJr  SSKJr  SSKJr  \" \5      r " S	 S
5      rg)z
ComponentService: Provides async management of tools, resources, and prompts for FastMCP servers.
Handles enabling/disabling components both locally and across mounted servers.
    )NotFoundError)Prompt)Resource)ResourceTemplate)FastMCPhas_resource_prefixremove_resource_prefix)Tool)
get_loggerc                       \ rS rSrSrS\4S jrS\S\4S jr	S\S\4S jr
S\S\\-  4S	 jrS\S\\-  4S
 jrS\S\4S jrS\S\4S jrSrg)ComponentService   zCService for managing components like tools, resources, and prompts.serverc                 v    Xl         UR                  U l        UR                  U l        UR                  U l        g )N)_server_tool_manager_resource_manager_prompt_manager)selfr   s     m/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/contrib/component_manager/component_service.py__init__ComponentService.__init__   s1    #11!'!9!9%55    keyreturnc                 b  #    [         R                  SU5        XR                  R                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ [        U R                  R                  5       H  nUR                  (       d  M  UR                  UR                   S35      (       aP  UR                  UR                   S35      n[        UR                  5      nUR                  U5      I Sh  vN nUs  $ M     [        SU 35      e N N7f)ztHandle 'enableTool' requests.

Args:
    key: The key of the tool to enable

Returns:
    The tool that was enabled
zEnabling tool: %sN_Unknown tool: )loggerdebugr   r   _toolsget_toolenablereversed_mounted_serversprefix
startswithremoveprefixr   r   _enable_toolr   r   r   toolmountedtool_keymounted_services         r   r)   ComponentService._enable_tool   s      	(#. ,,,,333#||44S99DKKMK   = =>G~~~>>W^^$4A"677"//7>>2B!0DEH&6w~~&FO!0!=!=h!GGDK ? nSE233 : H,   AD/D+AD/&A*D/D-D/-D/c                 b  #    [         R                  SU5        XR                  R                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ [        U R                  R                  5       H  nUR                  (       d  M  UR                  UR                   S35      (       aP  UR                  UR                   S35      n[        UR                  5      nUR                  U5      I Sh  vN nUs  $ M     [        SU 35      e N N7f)zwHandle 'disableTool' requests.

Args:
    key: The key of the tool to disable

Returns:
    The tool that was disabled
zDisable tool: %sNr   r   )r   r    r   r   r!   r"   disabler$   r%   r&   r'   r(   r   r   _disable_toolr   r*   s         r   r3   ComponentService._disable_tool7   s      	'- ,,,,333#||44S99DLLNK   = =>G~~~>>W^^$4A"677"//7>>2B!0DEH&6w~~&FO!0!>!>x!HHDK ? nSE233 : Ir0   c                   #    [         R                  SU5        XR                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ XR                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ [        U R                  R                  5       H  nUR                  (       a{  [        UUR                  UR                  5      (       aS  [        UUR                  UR                  5      n[        UR                   5      nUR#                  U5      I Sh  vN nUs  $ M  M     [%        SU 35      e GN% N N!7f)zHandle 'enableResource' requests.

Args:
    key: The key of the resource to enable

Returns:
    The resource that was enabled
zEnabling resource: %sNUnknown resource: )r   r    r   
_resourcesr   get_resourcer#   
_templatesget_resource_templater$   r%   r&   r   resource_prefix_formatr	   r   r   _enable_resourcer   r   r   resourcetemplater,   r.   mounted_resources          r   r<   !ComponentService._enable_resourceT   sK     	,c2 ((333'+||'@'@'E!EHOOO((333/3||/Q/QRU/V)VHOOO   = =>G~~&NN22 
 166C
 '7w~~&FO .>>sCC % ,+  % ?& 06779 "F *W( D8   AE<E5AE<E8B9E<E:E<8E<:E<c                   #    [         R                  SU5        XR                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ XR                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ [        U R                  R                  5       H  nUR                  (       a{  [        UUR                  UR                  5      (       aS  [        UUR                  UR                  5      n[        UR                   5      nUR#                  U5      I Sh  vN nUs  $ M  M     [%        SU 35      e GN% N N!7f)zHandle 'disableResource' requests.

Args:
    key: The key of the resource to disable

Returns:
    The resource that was disabled
zDisable resource: %sNr6   )r   r    r   r7   r   r8   r2   r9   r:   r$   r%   r&   r   r;   r	   r   r   _disable_resourcer   r=   s          r   rD   "ComponentService._disable_resource   sO     	+S1 ((333'+||'@'@'E!EHO((333/3||/Q/QRU/V)VHO   = =>G~~&NN22 
 166C
 '7w~~&FO .??DD % ,+  % ?& 06779 "F *W( ErB   c                 b  #    [         R                  SU5        XR                  R                  R                  ;   a5  U R                  R                  U5      I Sh  vN nUR                  5         U$ [        U R                  R                  5       H  nUR                  (       d  M  UR                  UR                   S35      (       aP  UR                  UR                   S35      n[        UR                  5      nUR                  U5      I Sh  vN nUs  $ M     [        SU 35      e N N7f)zzHandle 'enablePrompt' requests.

Args:
    key: The key of the prompt to enable

Returns:
    The prompt that was enabled
zEnabling prompt: %sNr   Unknown prompt: )r   r    r   r   _prompts
get_promptr#   r$   r%   r&   r'   r(   r   r   _enable_promptr   r   r   promptr,   
prompt_keyr.   s         r   rJ   ComponentService._enable_prompt   s      	*C0 ,,..777#'<<#:#:3#??FMMOM   = =>G~~~>>W^^$4A"677!$!1!1W^^4DA2F!GJ&6w~~&FO#2#A#A*#MMF!M ? .se455 @ Nr0   c                 6  #    XR                   R                  R                  ;   a5  U R                   R                  U5      I Sh  vN nUR	                  5         U$ [        U R                   R                  5       H  nUR                  (       d  M  UR                  UR                   S35      (       aP  UR                  UR                   S35      n[        UR                  5      nUR                  U5      I Sh  vN nUs  $ M     [        SU 35      e N N7f)z}Handle 'disablePrompt' requests.

Args:
    key: The key of the prompt to disable

Returns:
    The prompt that was disabled
Nr   rG   )r   r   rH   rI   r2   r$   r%   r&   r'   r(   r   r   _disable_promptr   rK   s         r   rP    ComponentService._disable_prompt   s      ,,..777#'<<#:#:3#??FNNM   = =>G~~~>>W^^$4A"677!$!1!1W^^4DA2F!GJ&6w~~&FO#2#B#B:#NNF!M ? .se455 @ Os,   ADDADA*D:D;DD)r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   strr
   r)   r3   r   r   r<   rD   r   rJ   rP   __static_attributes__ r   r   r   r      s    M6w 64c 4d 4:4s 4t 4:)8# )8(=M2M )8V)83 )88>N3N )8V6 6 6:6 6 6r   r   N)rV   fastmcp.exceptionsr   fastmcp.prompts.promptr   fastmcp.resources.resourcer   fastmcp.resources.templater   fastmcp.server.serverr   r   r	   fastmcp.tools.toolr
   fastmcp.utilities.loggingr   rR   r   r   rY   r   r   <module>ra      s:   
 - ) / 7 V V # 0	H	P6 P6r   