
    Ki                    `    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Z	 	 	 	 	 	 	 	 	 	 d	dZ	y)
z(Context injection utilities for FastMCP.    )annotationsN)Callable)Anyc                   ddl m} 	 t        j                  |       }|j                         D ]  \  }}t        j                  |      rt        ||      r|c S t        j                  |      }|Ct        j                  |      }|D ]*  }t        j                  |      st        ||      s&|c c S   y# t        $ r Y yw xY w)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)fnr   hints
param_name
annotationoriginargsargs           z/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/mcp/server/fastmcp/utilities/context_injection.pyfind_context_parameterr      s     2%%b) #(++- &
J??:&:j'+J "":.??:.D &??3'JsG,D%%&& %  s   B7 7	CCc                    |
|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
     )r   kwargscontextcontext_kwargs       r   inject_contextr    1   s&    "  W%81&1-11M    )r   Callable[..., Any]return
str | None)
r   r"   r   dict[str, Any]r   z
Any | Noner   r$   r#   r%   )
__doc__
__future__r   r   r	   collections.abcr   r   r   r    r   r!   r   <module>r)      sP    . "   $ #L  	
 r!   