
    Ki,                          d 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mZ ddlmZ ddlmZ  ee      Z G d	 d
      Zy)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                       e Zd ZdZdefdZdedefdZdedefdZ	dede
ez  fdZdede
ez  fd	Zdedefd
ZdedefdZy)ComponentServicezCService for managing components like tools, resources, and prompts.serverc                 x    || _         |j                  | _        |j                  | _        |j                  | _        y )N)_server_tool_manager_resource_manager_prompt_manager)selfr   s     /home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/contrib/component_manager/component_service.py__init__zComponentService.__init__   s3    #11!'!9!9%55    keyreturnc                 F  K   t         j                  d|       || j                  j                  j                  v r5| j                  j                  |       d{   }|j                          |S t        | j                  j                        D ]}  }|j                  s|j                  |j                   d      rP|j                  |j                   d      }t        |j                        }|j                  |       d{   }|c S  t        d|       7 7 w)zHandle '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'   zComponentService._enable_tool   s      	(#. $,,,,333#||44S99DKKMK   = => 	G~~>>W^^$4A"6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                 F  K   t         j                  d|       || j                  j                  j                  v r5| j                  j                  |       d{   }|j                          |S t        | j                  j                        D ]}  }|j                  s|j                  |j                   d      rP|j                  |j                   d      }t        |j                        }|j                  |       d{   }|c S  t        d|       7 7 w)zHandle '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   r0   zComponentService._disable_tool7   s      	'- $,,,,333#||44S99DLLNK   = => 	G~~>>W^^$4A"67"//7>>2B!0DEH&6w~~&FO!0!>!>x!HHDK	 nSE233 : Ir-   c                   K   t         j                  d|       || j                  j                  v r5| j                  j                  |       d{   }|j                          |S || j                  j                  v r5| j                  j                  |       d{   }|j                          |S t        | j                  j                        D ]m  }|j                  r_t        ||j                        s&t        ||j                        }t        |j                        }|j!                  |       d{   }|c S o t#        d|       7 7 7 w)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   r	   r   r   _enable_resourcer   r   r   resourcetemplater*   r,   mounted_resources          r   r7   z!ComponentService._enable_resourceT   s-     	,c2 $((333'+||'@'@'E!EHOOO$((333/3||/Q/QRU/V)VHOOO   = => 
	G~~&sGNN;0gnnEC&6w~~&FO .>>sCC % ,+
	 0677) "F *W D>   AEEAEEAE8?E7E8EEEc                   K   t         j                  d|       || j                  j                  v r5| j                  j                  |       d{   }|j                          |S || j                  j                  v r5| j                  j                  |       d{   }|j                          |S t        | j                  j                        D ]m  }|j                  r_t        ||j                        s&t        ||j                        }t        |j                        }|j!                  |       d{   }|c S o t#        d|       7 7 7 w)zHandle 'disableResource' requests.

        Args:
            key: The key of the resource to disable

        Returns:
            The resource that was disabled
        zDisable resource: %sNr2   )r   r   r   r3   r   r4   r/   r5   r6   r"   r#   r$   r   r	   r   r   _disable_resourcer   r8   s          r   r>   z"ComponentService._disable_resourcew   s1     	+S1 $((333'+||'@'@'E!EHO$((333/3||/Q/QRU/V)VHO   = => 
	G~~&sGNN;0gnnEC&6w~~&FO .??DD % ,+
	 0677) "F *W Er<   c                 F  K   t         j                  d|       || j                  j                  j                  v r5| j                  j                  |       d{   }|j                          |S t        | j                  j                        D ]}  }|j                  s|j                  |j                   d      rP|j                  |j                   d      }t        |j                        }|j                  |       d{   }|c S  t        d|       7 7 w)zHandle '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   rC   zComponentService._enable_prompt   s      	*C0 $,,..777#'<<#:#:3#??FMMOM   = => 	G~~>>W^^$4A"67!$!1!1W^^4DA2F!GJ&6w~~&FO#2#A#A*#MMF!M	 .se455 @ Nr-   c                   K   || j                   j                  j                  v r5| j                   j                  |       d{   }|j	                          |S t        | j                   j                        D ]}  }|j                  s|j                  |j                   d      rP|j                  |j                   d      }t        |j                        }|j                  |       d{   }|c S  t        d|       7 7 w)zHandle 'disablePrompt' requests.

        Args:
            key: The key of the prompt to disable

        Returns:
            The prompt that was disabled
        Nr   r@   )r   r   rA   rB   r/   r"   r#   r$   r%   r&   r   r   _disable_promptr   rD   s         r   rH   z ComponentService._disable_prompt   s      $,,..777#'<<#:#:3#??FNNM   = => 	G~~>>W^^$4A"6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N)__name__
__module____qualname____doc__r   r   strr
   r'   r0   r   r   r7   r>   r   rC   rH    r   r   r   r      s    M6w 64c 4d 4:4s 4t 4:!8# !8(=M2M !8F!83 !88>N3N !8F6 6 6:6 6 6r   r   N)rL   fastmcp.exceptionsr   fastmcp.prompts.promptr   fastmcp.resources.resourcer   fastmcp.resources.templater   fastmcp.server.serverr   r   r	   fastmcp.tools.toolr
   fastmcp.utilities.loggingr   rI   r   r   rN   r   r   <module>rV      s:   
 - ) / 7 V V # 0	H	@6 @6r   