o
    i                     @   s  d Z ddlZddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
mZ e
r2ddlmZmZmZ dd	lmZmZ dd
lmZ eeZeedgdf Zeedgdf ZG dd dejZeddG dd dZeejdgZdedee defddZg dZ dS )z+Route mapping logic for OpenAPI operations.    N)Callable)	dataclassfield)Pattern)TYPE_CHECKINGLiteral   )OpenAPIResourceOpenAPIResourceTemplateOpenAPITool)
HttpMethod	HTTPRoute)
get_loggerMCPTypezMCPType | Nonez7OpenAPITool | OpenAPIResource | OpenAPIResourceTemplatec                   @   s    e Zd ZdZdZdZdZdZdS )r   ax  Type of FastMCP component to create from a route.

    Enum values:
        TOOL: Convert the route to a callable Tool
        RESOURCE: Convert the route to a Resource (typically GET endpoints)
        RESOURCE_TEMPLATE: Convert the route to a ResourceTemplate (typically GET with path params)
        EXCLUDE: Exclude the route from being converted to any MCP component
    TOOLRESOURCERESOURCE_TEMPLATEEXCLUDEN)__name__
__module____qualname____doc__r   r   r   r    r   r   q/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/experimental/server/openapi/routing.pyr   !   s    	T)kw_onlyc                   @   s   e Zd ZU dZeddZee ed B e	d< eddZ
ee eB e	d< eeddid	Zee e	d
< eddidZee	d< eeddid	Zee e	d< dS )RouteMapzAMapping configuration for HTTP routes to FastMCP component types.*)defaultmethodsz.*patterndescriptionz,A set of tags to match. All tags must match.)default_factorymetadatatagsz(The type of FastMCP component to create.)r"   mcp_typez:A set of tags to apply to the generated FastMCP component.mcp_tagsN)r   r   r   r   r   r   listr   r   __annotations__r   r   strsetr#   r$   r   r%   r   r   r   r   r   2   s    
 r   r$   routemappingsreturnc              	   C   s   |D ]L}|j dks| j|j v rNt|jtr|j| j}nt|j| j}|rN|jr8t	| jp/g }|j
|s8qtd| j d| j d|jj  |  S qttjdS )a'  
    Determines the FastMCP component type based on the route and mappings.

    Args:
        route: HTTPRoute object
        mappings: List of RouteMap objects in priority order

    Returns:
        The RouteMap that matches the route, or a catchall "Tool" RouteMap if no match is found.
    r   zRoute  z mapped to r*   )r   method
isinstancer   r   searchpathrer#   r)   issubsetloggerdebugr$   namer   r   r   )r+   r,   	route_mappattern_matchesroute_tags_setr   r   r   _determine_route_typeO   s    r;   )DEFAULT_ROUTE_MAPPINGSComponentFnr   r   
RouteMapFnr;   )!r   enumr3   collections.abcr   dataclassesr   r   r   typingr   r   
componentsr	   r
   r   &fastmcp.experimental.utilities.openapir   r   fastmcp.utilities.loggingr   r   r5   r>   r=   Enumr   r   r   r<   r&   r;   __all__r   r   r   r   <module>   sB    	

,