
    {h                       d Z ddlmZ ddlZddlmZmZ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lmZ  ed	e
      Z G d deee         Z G d de      Z G d de      Zee   ez  ez  ZeeeefZddZddZ	 d	 	 	 	 	 	 	 	 	 ddZy)z&Elicitation utilities for MCP servers.    )annotationsN)GenericLiteralTypeVarUnionget_args
get_origin)	BaseModel)	FieldInfo)ServerSession)	RequestIdElicitSchemaModelT)boundc                  *    e Zd ZU dZdZded<   ded<   y)AcceptedElicitationz)Result when user accepts the elicitation.acceptzLiteral['accept']actionr   dataN__name__
__module____qualname____doc__r   __annotations__     W/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/mcp/server/elicitation.pyr   r      s    3 (F(
r   r   c                       e Zd ZU dZdZded<   y)DeclinedElicitationz*Result when user declines the elicitation.declinezLiteral['decline']r   Nr   r   r   r   r   r      s    4!*F*r   r   c                       e Zd ZU dZdZded<   y)CancelledElicitationz)Result when user cancels the elicitation.cancelzLiteral['cancel']r   Nr   r   r   r   r"   r"      s    3 (F(r   r"   c                    | j                   j                         D ]&  \  }}t        |      rt        d| dt         d       y)zCValidate that a Pydantic model only contains primitive field types.zElicitation schema field 'z' must be a primitive type z_ or Optional of these types. Complex types like lists, dicts, or nested models are not allowed.N)model_fieldsitems_is_primitive_field	TypeError_ELICITATION_PRIMITIVE_TYPES)schema
field_name
field_infos      r   _validate_elicitation_schemar-   +   sV    "("5"5";";"= 
J":.,ZL8S/0 1UV r   c                    | j                   }|t        j                  u ry|t        v ryt	        |      }|t
        u s|t        j                  u rt        |      }t        d |D              S y)zDCheck if a field is a primitive type allowed in elicitation schemas.Tc              3  T   K   | ]   }|t         j                  u xs |t        v  " y wN)typesNoneTyper)   ).0args     r   	<genexpr>z&_is_primitive_field.<locals>.<genexpr>G   s(     `TW3%..(OC3O,OO`s   &(F)	
annotationr1   r2   r)   r	   r   	UnionTyper   all)r,   r6   originargss       r   r'   r'   6   si    &&J U^^# 11 
#F&EOO3
#`[_```r   c                  K   t        |       |j                         }| j                  |||       d{   }|j                  dk(  r3|j                  r'|j                  |j                        }t        |      S |j                  dk(  r
t               S |j                  dk(  r
t               S t        d|j                         7 w)a  Elicit information from the client/user with schema validation.

    This method can be used to interactively ask for additional information from the
    client within a tool's execution. The client might display the message to the
    user and collect a response according to the provided schema. Or in case a
    client is an agent, it might decide how to handle the elicitation -- either by asking
    the user or automatically generating a response.
    )messagerequestedSchemarelated_request_idNr   )r   r    r#   zUnexpected elicitation action: )
r-   model_json_schemaelicitr   contentmodel_validater   r   r"   
ValueError)sessionr<   r*   r>   json_schemaresultvalidated_datas          r   elicit_with_validationrH   L   s      !(**,K>>#- "  F }} V^^..v~~>"77	)	#"$$	(	"#%% :6==/JKK!s   3CCBC)r*   ztype[BaseModel]returnNone)r,   r   rI   boolr0   )
rD   r   r<   strr*   ztype[ElicitSchemaModelT]r>   zRequestId | NonerI   z%ElicitationResult[ElicitSchemaModelT]) r   
__future__r   r1   typingr   r   r   r   r   r	   pydanticr
   pydantic.fieldsr   mcp.server.sessionr   	mcp.typesr   r   r   r   r"   ElicitationResultrL   intfloatrK   r)   r-   r'   rH   r   r   r   <module>rV      s    , "  I I  % , 1C )W-?%@ +) +)9 ) ((:;>QQThh  !$S%6 4 ,0	#L#L#L %#L )	#L
 +#Lr   