
    Ki                     X   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
r
ddlmZmZmZ dd	lmZ dd
lmZmZ  ee      Zeedgdf   Zeedgdf   Z G d dej2                        Z ed       G d d             Z eej8                        gZdedee   defdZg dZ y)z+Route mapping logic for OpenAPI operations.    N)Callable)	dataclassfield)Pattern)TYPE_CHECKINGLiteral   )OpenAPIResourceOpenAPIResourceTemplateOpenAPITool)
get_logger)
HttpMethod	HTTPRouteMCPTypezMCPType | Nonez7OpenAPITool | OpenAPIResource | OpenAPIResourceTemplatec                        e Zd ZdZdZdZdZdZy)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        j/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/server/openapi/routing.pyr   r   !   s     DH+Gr   T)kw_onlyc                       e Zd ZU dZ ed      Zee   ed   z  e	d<    ed      Z
ee   ez  e	d<    eeddi	      Zee   e	d
<    eddi      Zee	d<    eeddi	      Zee   e	d<   y)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    K/4S/AGT*,A"'"6GWS\C6!OPD#c(  !KLHg  W
Hc#h r   r   r(   routemappingsreturnc           	         |D ]!  }|j                   dk(  s| j                  |j                   v s,t        |j                  t              r&|j                  j                  | j                        }n*t        j
                  |j                  | j                        }|s|j                  r5t        | j                  xs g       }|j                  j                  |      st        j                  d| j                   d| j                   d|j                  j                          |c S  t        t         j"                        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/   r0   	route_mappattern_matchesroute_tags_sets        r   _determine_route_typer@   O   s      !	#u||y7H7H'H)++W5"+"3"3":":5::"F"$))I,=,=uzz"J >>%()9r%:N$>>22>B U\\N!EJJ<{9CUCUCZCZB[\ ! -!2 W\\**r   )DEFAULT_ROUTE_MAPPINGSComponentFnr   r   
RouteMapFnr@   )!r   enumr8   collections.abcr   dataclassesr   r   r   typingr   r   
componentsr
   r   r   fastmcp.utilities.loggingr   fastmcp.utilities.openapir   r   r   r:   rC   rB   Enumr   r   r   rA   r*   r@   __all__r   r   r   <module>rM      s    1  	 $ (  )  1 ;	H	 y),.>>?
A 		
dii " 4  0 gll# 
(+(+8n(+ (+Xr   