
    Ch                       S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  \" S	\S
9r " S S\\\   5      r " S S\5      r " S S\5      r\\   \-  \-  r\\\\4rSS jrSS jr S         SS jjrg)z&Elicitation utilities for MCP servers.    )annotationsN)GenericLiteralTypeVarUnionget_args
get_origin)	BaseModel)	FieldInfo)ServerSession)	RequestIdElicitSchemaModelT)boundc                  2    \ rS rSr% SrSrS\S'   S\S'   Srg	)
AcceptedElicitation   z)Result when user accepts the elicitation.acceptzLiteral['accept']actionr   data N__name__
__module____qualname____firstlineno____doc__r   __annotations____static_attributes__r       P/home/james-whalen/.local/lib/python3.13/site-packages/mcp/server/elicitation.pyr   r      s    3 (F(
r   r   c                  (    \ rS rSr% SrSrS\S'   Srg)DeclinedElicitation   z*Result when user declines the elicitation.declinezLiteral['decline']r   r   Nr   r   r   r    r"   r"      s    4!*F*r   r"   c                  (    \ rS rSr% SrSrS\S'   Srg)CancelledElicitation   z)Result when user cancels the elicitation.cancelzLiteral['cancel']r   r   Nr   r   r   r    r&   r&      s    3 (F(r   r&   c                    U R                   R                  5        H+  u  p[        U5      (       a  M  [        SU S[         S35      e   g)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_schemar2   +   sR    "("5"5";";"=
":..,ZL8S/0 1UV  #>r   c                    U R                   nU[        R                  L a  gU[        ;   a  g[	        U5      nU[
        L d  U[        R                  L a  [        U5      n[        S U 5       5      $ g)zDCheck if a field is a primitive type allowed in elicitation schemas.Tc              3  d   #    U  H&  o[         R                  L =(       d	    U[        ;   v   M(     g 7fN)typesNoneTyper.   ).0args     r    	<genexpr>&_is_primitive_field.<locals>.<genexpr>G   s(     `[_TW%..(OC3O,OO[_s   .0F)	
annotationr6   r7   r.   r	   r   	UnionTyper   all)r1   r<   originargss       r    r,   r,   6   si    &&J U^^# 11 
#F&EOO3
#`[_```r   c                  #    [        U5        UR                  5       nU R                  UUUS9I Sh  vN nUR                  S:X  a1  UR                  b$  UR                  UR                  5      n[        US9$ UR                  S:X  a
  [        5       $ UR                  S:X  a
  [        5       $ [        SUR                   35      e N7f)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: )
r2   model_json_schemaelicitr   contentmodel_validater   r"   r&   
ValueError)sessionrB   r/   rD   json_schemaresultvalidated_datas          r    elicit_with_validationrN   L   s      !(**,K>>#- "  F }} V^^%?..v~~>"77	)	#"$$	(	"#%% :6==/JKK!s   0CCBC)r/   ztype[BaseModel]returnNone)r1   r   rO   boolr5   )
rJ   r   rB   strr/   ztype[ElicitSchemaModelT]rD   zRequestId | NonerO   z%ElicitationResult[ElicitSchemaModelT]) r   
__future__r   r6   typingr   r   r   r   r   r	   pydanticr
   pydantic.fieldsr   mcp.server.sessionr   	mcp.typesr   r   r   r"   r&   ElicitationResultrR   intfloatrQ   r.   r2   r,   rN   r   r   r    <module>r\      s    , "  I I  % , 1C )W-?%@ +) +)9 ) ((:;>QQThh  !$S%6 4 ,0	#L#L#L %#L )	#L
 +#Lr   