
    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  SSKJr  SSKJrJr  SS	KJr  SS
KJr  SSKJr   SS\S\S\\   S-  4S jjrS rS\4S jr SS\\   4S jjrS\4S jrg)z
Routes and helpers for managing tools, resources, and prompts in FastMCP.
Provides endpoints for enabling/disabling components via HTTP, with optional authentication scopes.
    )Any)RequireAuthMiddleware)	Starlette)HTTPExceptionRequest)JSONResponse)MountRoute)ComponentService)NotFoundError)FastMCPNserverpathrequired_scopesc                 p   [        U 5      n/ n/ nSUR                  UR                  S.SUR                  UR                  S.SUR
                  UR                  S.S.nUc  UR                  [        Xa5      5        OUS:w  a  UR                  [        XaU5      5        OcUR                  [        SUS   0S	U5      5        UR                  [        S
US
   0SU5      5        UR                  [        SUS   0SU5      5        U R                  R                  U5        U R                  R                  U5        g)a-  Set up routes for enabling/disabling tools, resources, and prompts.
Args:
    server: The FastMCP server instance
    path: Path used to mount all component-related routes on the server
    required_scopes: Optional list of scopes required for these routes. Applies only if authentication is enabled.
	tool_name)paramenabledisablezuri:pathprompt_name)toolresourcepromptN/r   /toolsr   
/resourcesr   /prompts)r   _enable_tool_disable_tool_enable_resource_disable_resource_enable_prompt_disable_promptextend!build_component_manager_endpointsappendbuild_component_manager_mount_additional_http_routes)r   r   r   serviceroutesmountsroute_configss          m/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/contrib/component_manager/component_manager.pyset_up_component_managerr/      sK    v&GFF !**,,
  ..00
 #,,..
M$ 7LM3;MM-m?S MM-]623X
 MM-z!:; # MM-}X67_ ""))&1
""))&1    c                 ,   ^ ^^ S[         4U UU4S jjnU$ )aD  
Factory for creating Starlette endpoint functions for enabling/disabling a component.
Args:
    action: 'enable' or 'disable'
    component: The component type (e.g., 'tool', 'resource', or 'prompt')
    config: Dict with param and handler functions for the component
Returns:
    An async endpoint function for Starlette.
requestc                   >#    U R                   TS   R                  S5      S      n TT   " U5      I S h  vN   [        STR                  5        ST SU 305      $  N'! [         a  n[        SST SU 3S	9UeS nAff = f7f)
Nr   :r   messagezd z: i  zUnknown )status_codedetail)path_paramssplitr	   
capitalizer   StarletteHTTPException)r2   nameeaction	componentconfigs      r.   endpointmake_endpoint.<locals>.endpoint\   s     ""6'?#8#8#=a#@A		.&&&v00232i[4&IJ  '  	(!)Btf5 	s8   %BA! A&A! BA! !
B+A<<BBr   )r>   r?   r@   rA   s   ``` r.   make_endpointrC   Q   s       Or0   returnc                     [        XU5      nUb  US;   a  SUS    SU  3nO(US:w  a  Uc  U SU SUS    SU  3nOSU SUS    SU  3n[        XeS/S9$ )	aH  
Creates a Starlette Route for enabling/disabling a component.
Args:
    action: 'enable' or 'disable'
    component: The component type
    config: Dict with param and handler functions
    required_scopes: Optional list of required auth scopes
    root_path: The base path for the route
Returns:
    A Starlette Route object.
)r   r   r   z/{r   z}/r   zs/{POST)rA   methods)rC   r   )r>   r?   r@   r   	root_pathrA   r   s          r.   
make_routerI   m   s     V7H"y 5 (
 VG_%S1 7[)D0AVHMDykfWo%6c&BD6(;;r0   c                 n    / nU  H,  nX   nS H  nUR                  [        XdXRU5      5        M!     M.     U$ )a?  
Build a list of Starlette Route objects for all components/actions.
Args:
    route_configs: Dict describing component types and their handlers
    root_path: The base path for the routes
    required_scopes: Optional list of required auth scopes
Returns:
    List of Starlette Route objects for component management.
r   r   )r'   rI   r-   rH   r   component_management_routesr?   r@   r>   s          r.   r&   r&      sH     02"	!.!9+F'..6fyQ , # '&r0   c                     / nU  H,  nX   nS H  nUR                  [        XdXRU5      5        M!     M.     [        U [        [	        US9U5      S9$ )a=  
Build a Starlette Mount with authentication for component management routes.
Args:
    route_configs: Dict describing component types and their handlers
    root_path: The base path for the mount
    required_scopes: List of required auth scopes
Returns:
    A Starlette Mount object with authentication middleware.
rK   )r+   )app)r'   rI   r
   r   r   rL   s          r.   r(   r(      sg     02"	!.!9+F'..6fyQ , # +!89?
 r0   )r   N)N)__doc__typingr   &mcp.server.auth.middleware.bearer_authr   starlette.applicationsr   starlette.exceptionsr   r;   starlette.requestsr   starlette.responsesr	   starlette.routingr
   r   3fastmcp.contrib.component_manager.component_servicer   fastmcp.exceptionsr   fastmcp.server.serverr   strlistr/   rC   rI   r&   r(    r0   r.   <module>r^      s   
  H , H & , * P , ) KO:2:2:27;Cy47G:2z8< << /3'	%['0PU r0   