o
    *i                     @  sP   d Z ddlmZ ddlZddlZddlmZ ddlmZ dd
dZdddZ	dS )z(Context injection utilities for FastMCP.    )annotationsN)Callable)AnyfnCallable[..., Any]return
str | Nonec                 C  s   ddl m} zt| }W n
 ty   Y dS w | D ]5\}}t|r.t||r.|  S t	|}|durQt
|}|D ]}t|rPt||rP|    S q>qdS )a#  Find the parameter that should receive the Context object.

    Searches through the function's signature to find a parameter
    with a Context type annotation.

    Args:
        fn: The function to inspect

    Returns:
        The name of the context parameter, or None if not found
    r   )ContextN)mcp.server.fastmcp.serverr	   typingget_type_hints	Exceptionitemsinspectisclass
issubclass
get_originget_args)r   r	   hints
param_name
annotationoriginargsarg r   k/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/mcp/server/fastmcp/utilities/context_injection.pyfind_context_parameter   s"   

r   kwargsdict[str, Any]context
Any | Nonecontext_kwargc                 C  s$   |dur|duri |||iS |S )aY  Inject context into function kwargs if needed.

    Args:
        fn: The function that will be called
        kwargs: The current keyword arguments
        context: The context object to inject (if any)
        context_kwarg: The name of the parameter to inject into

    Returns:
        Updated kwargs with context injected if applicable
    Nr   )r   r   r   r!   r   r   r   inject_context1   s   r"   )r   r   r   r   )
r   r   r   r   r   r    r!   r   r   r   )
__doc__
__future__r   r   r   collections.abcr   r   r   r"   r   r   r   r   <module>   s    
&