Ë
    ïñþi  ã                  ój  — d Z ddlmZ ddlZddlm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  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 G d„ de«      Zeez  ez  ZeeeefZdd„Zdd„Z dd„Z!	 d	 	 	 	 	 	 	 	 	 dd„Z"	 d	 	 	 	 	 	 	 	 	 	 	 dd„Z#y)z&Elicitation utilities for MCP servers.é    )ÚannotationsN)ÚSequence)ÚGenericÚLiteralÚTypeVarÚUnionÚget_argsÚ
get_origin)Ú	BaseModel)Ú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.ÚacceptúLiteral['accept']Úactionr   ÚdataN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__© ó    úV/root/aria/mcps/aria-brain/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                  ó    — e Zd ZU dZdZded<   y)ÚAcceptedUrlElicitationz0Result when user accepts a URL mode elicitation.r   r   r   Nr   r   r   r   r&   r&   '   s   … Ù:à (€FÐÔ(r   r&   c                óä   — | j                   j                  «       D ]S  \  }}|j                  }|�|t        j                  u rŒ't        |«      rŒ3t        |«      rŒ?t        d|› dt        › d�«      ‚ y)zCValidate that a Pydantic model only contains primitive field types.NzElicitation schema field 'z' must be a primitive type zw, a sequence of strings (list[str], etc.), or Optional of these types. Nested models and complex types are not allowed.)	Úmodel_fieldsÚitemsÚ
annotationÚtypesÚNoneTypeÚ_is_primitive_fieldÚ_is_string_sequenceÚ	TypeErrorÚ_ELICITATION_PRIMITIVE_TYPES)ÚschemaÚ
field_nameÚ
field_infor*   s       r   Ú_validate_elicitation_schemar4   4   sƒ   € à"(×"5Ñ"5×";Ñ";Ó"=ò Ñˆ
�JØ×*Ñ*ˆ
àÐ ¬u¯~©~Ñ!=ØÜ  Ô,ØÜ  Ô,ØäØ,¨Z¨LÐ8SÜ/Ð0ð 1_ð`óð ñr   c                ó®   — t        | «      }|r9	 t        |t        «      r&t        | «      }t	        |«      dk(  xr |d   t
        u S 	 yy# t        $ r Y yw xY w)zMCheck if annotation is a sequence of strings (list[str], Sequence[str], etc).é   r   F)r
   Ú
issubclassr   r	   ÚlenÚstrr/   ©r*   ÚoriginÚargss      r   r.   r.   G   sd   € ä˜
Ó#€Fáð	Ü˜&¤(Ô+Ü 
Ó+�ä˜4“y A‘~Ò8¨$¨q©'´S¨.Ð8ð ,ñ øô ò 	àØð	ús   �5A Á	AÁAc                óš   — | 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  ón   K  — | ]-  }|t         j                  u xs |t        v xs t        |«      –— Œ/ y ­w©N)r+   r,   r0   r.   )Ú.0Úargs     r   ú	<genexpr>z&_is_primitive_field.<locals>.<genexpr>b   s8   è ø€ ò 
ØilˆC”5—>‘>Ð!Òd SÔ,HÐ%HÒdÔL_Ð`cÓLdÓdñ
ùs   ‚35F)r0   r
   r   r+   Ú	UnionTyper	   Úallr:   s      r   r-   r-   W   sW   € ð Ô1Ñ1Øô ˜
Ó#€FØ”�˜&¤E§O¡OÑ3Ü˜
Ó#ˆäñ 
Øptô
ó 
ð 	
ð r   c              ƒ  ó”  K  — t        |«       |j                  «       }| j                  |||¬«      ƒ d{  –—† }|j                  dk(  r3|j                  �'|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 (form mode).

    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.

    For sensitive data like credentials or OAuth flows, use elicit_url() instead.
    )ÚmessageÚrequestedSchemaÚrelated_request_idNr   )r   r!   r$   úUnexpected elicitation action: )
r4   Úmodel_json_schemaÚelicit_formr   ÚcontentÚmodel_validater   r    r#   Ú
ValueError)ÚsessionrF   r1   rH   Újson_schemaÚresultÚvalidated_datas          r   Úelicit_with_validationrS   i   s¿   è ø€ ô" ! Ô(à×*Ñ*Ó,€Kà×&Ñ&ØØ#Ø-ð 'ó ÷ €Fð ‡}�}˜Ò  V§^¡^Ð%?à×.Ñ.¨v¯~©~Ó>ˆÜ"¨Ô7Ð7Ø	�‰˜)Ò	#Ü"Ó$Ð$Ø	�‰˜(Ò	"Ü#Ó%Ð%ô Ð:¸6¿=¹=¸/ÐJÓKÐKð!ús   ‚3CµC¶BCc              ƒ  ó  K  — | j                  ||||¬«      ƒ d{  –—† }|j                  dk(  r
t        «       S |j                  dk(  r
t        «       S |j                  dk(  r
t	        «       S t        d|j                  › �«      ‚7 Œg­w)a[  Elicit information from the user via out-of-band URL navigation (URL mode).

    This method directs the user to an external URL where sensitive interactions can
    occur without passing data through the MCP client. Use this for:
    - Collecting sensitive credentials (API keys, passwords)
    - OAuth authorization flows with third-party services
    - Payment and subscription flows
    - Any interaction where data should not pass through the LLM context

    The response indicates whether the user consented to navigate to the URL.
    The actual interaction happens out-of-band. When the elicitation completes,
    the server should send an ElicitCompleteNotification to notify the client.

    Args:
        session: The server session
        message: Human-readable explanation of why the interaction is needed
        url: The URL the user should navigate to
        elicitation_id: Unique identifier for tracking this elicitation
        related_request_id: Optional ID of the request that triggered this elicitation

    Returns:
        UrlElicitationResult indicating accept, decline, or cancel
    )rF   ÚurlÚelicitation_idrH   Nr   r!   r$   rI   )Ú
elicit_urlr   r&   r    r#   rN   )rO   rF   rU   rV   rH   rQ   s         r   rW   rW   ‘   s�   è ø€ ð< ×%Ñ%ØØØ%Ø-ð	 &ó ÷ €Fð ‡}�}˜Ò Ü%Ó'Ð'Ø	�‰˜)Ò	#Ü"Ó$Ð$Ø	�‰˜(Ò	"Ü#Ó%Ð%ô Ð:¸6¿=¹=¸/ÐJÓKÐKðús   ‚B›BœA(B)r1   ztype[BaseModel]ÚreturnÚNone)r*   ÚtyperX   Úboolr?   )
rO   r   rF   r9   r1   ztype[ElicitSchemaModelT]rH   úRequestId | NonerX   z%ElicitationResult[ElicitSchemaModelT])rO   r   rF   r9   rU   r9   rV   r9   rH   r\   rX   ÚUrlElicitationResult)$r   Ú
__future__r   r+   Úcollections.abcr   Útypingr   r   r   r   r	   r
   Úpydanticr   Úmcp.server.sessionr   Ú	mcp.typesr   r   r   r    r#   ÚElicitationResultr&   r]   r9   ÚintÚfloatr[   r0   r4   r.   r-   rS   rW   r   r   r   ú<module>rg      s<  ðÙ ,å "ã Ý $ß I× Iå å ,Ý áÐ1¸ÔCÐ ô˜) WÐ-?Ñ%@ô ô+˜)ô +ô)˜9ô )ð (Ð(:Ñ;Ð>QÑQÐThÑhÐ ô)˜Yô )ð .Ð0CÑCÐFZÑZÐ ð !$ S¨%°Ð6Ð óó&ó ð, ,0ð	%LØð%Làð%Lð %ð%Lð )ð	%Lð
 +ó%LðZ ,0ð-LØð-Làð-Lð 
ð-Lð ð	-Lð
 )ð-Lð ô-Lr   