
    jKj                        d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
 ddlmZ ddlmZ dd	Z	 	 	 	 dd
Z	 	 	 d	 	 	 	 	 	 	 	 	 ddZy)zInject a required ``context`` parameter into a tool's JSON Schema so agents
state their intent. Operates on the already-serialized JSON Schema dict (the
``mcp`` SDK exposes tool ``inputSchema`` as a plain dict).    )annotationsN)AnyDictOptionalUnion   )%DEFAULT_CONTEXT_PARAMETER_DESCRIPTION)log)MCPAnalyticsContextOptionsc                
    | duS )NF contexts    p/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/posthog/mcp/_context_parameters.pyis_context_enabledr      s    %    c                <    t        | t              r| j                  S y )N)
isinstancer   descriptionr   s    r   get_context_descriptionr      s     '56"""r   c                z   | }|r7t        |j                  d      t              rd|d   v rt        d| d       |S |rD|j                  d      s"|j                  d      s|j                  d      rt        d| d       |S |sd	i g d
}t	        j
                  |      }t        |j                  d      t              si |d<   |j                  d      du r|j                  dd       d|xs t        d|d   d<   |r>|j                  d      }t        |t              rd|vr|j                  d       |S dg|d<   |S )u  Return a new JSON Schema dict with a ``context`` string property added.

    Returns the input unchanged (logging a warning) for schemas that already
    define ``context`` or use ``oneOf``/``allOf``/``anyOf``. ``required`` controls
    whether ``context`` is added to the schema's ``required`` list — pass ``False``
    where the advertised schema is also used to validate inbound calls (the
    low-level server), so a call omitting ``context`` is not rejected.
propertiesr   zWARN: Tool "z>" already has 'context' parameter. Skipping context injection.oneOfallOfanyOfzE" has complex schema (oneOf/allOf/anyOf). Skipping context injection.object)typer   requiredadditionalPropertiesFNstring)r   r   r   )
r   getdictr
   copydeepcopypopr	   listappend)input_schema	tool_namedescription_overrider   schemarequired_lists         r   add_context_parameter_to_schemar-      sU    F 	vzz,/6--I;&ef	
 6::g&&**W*=GAT9+%jk	
 """E ]]6"Ffjj.5!| zz()U2

)40 +T/T'F<#
 

:.mT*-$$Y/ M #,F:Mr   )r   -Union[bool, MCPAnalyticsContextOptions, None]returnbool)r   r.   r/   Optional[str])unknownNT)
r(   Optional[Dict[str, Any]]r)   strr*   r1   r   r0   r/   r3   )__doc__
__future__r   r#   typingr   r   r   r   	constantsr	   loggerr
   typesr   r   r   r-   r   r   r   <module>r;      sy   
> #  - - <  - : *.	:*:: (: 	:
 :r   