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   út/var/www/html/karishye-ai-python/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    
&