§
    öŽ’jÃ  ã                  ón  — 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#dS )/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<   dS )ÚAcceptedElicitationz)Result when user accepts the elicitation.ÚacceptúLiteral['accept']Úactionr   ÚdataN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__© ó    úDC:\Projects\DSCons\.venv\Lib\site-packages\mcp\server\elicitation.pyr   r      s5   € € € € € € Ø3Ð3à (€FÐ(Ð(Ð(Ñ(ØÐÐÑÐÐr   r   c                  ó"   — e Zd ZU dZdZded<   dS )ÚDeclinedElicitationz*Result when user declines the elicitation.ÚdeclinezLiteral['decline']r   Nr   r   r   r   r    r       s)   € € € € € € Ø4Ð4à!*€FÐ*Ð*Ð*Ñ*Ð*Ð*r   r    c                  ó"   — e Zd ZU dZdZded<   dS )ÚCancelledElicitationz)Result when user cancels the elicitation.ÚcancelzLiteral['cancel']r   Nr   r   r   r   r#   r#      s)   € € € € € € Ø3Ð3à (€FÐ(Ð(Ð(Ñ(Ð(Ð(r   r#   c                  ó"   — e Zd ZU dZdZded<   dS )ÚAcceptedUrlElicitationz0Result when user accepts a URL mode elicitation.r   r   r   Nr   r   r   r   r&   r&   '   s)   € € € € € € Ø:Ð:à (€FÐ(Ð(Ð(Ñ(Ð(Ð(r   r&   Úschemaútype[BaseModel]ÚreturnÚNonec                óè   — | j                              ¦   «         D ]W\  }}|j        }|�|t          j        u rŒt          |¦  «        rŒ-t          |¦  «        rŒ=t          d|› dt          › d�¦  «        ‚dS )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)r'   Ú
field_nameÚ
field_infor.   s       r   Ú_validate_elicitation_schemar7   4   s­   € à"(Ô"5×";Ò";Ñ"=Ô"=ð ð Ñˆ
�JØÔ*ˆ
àÐ ­u¬~Ð!=Ð!=ØÝ  Ñ,Ô,ð 		ØÝ  Ñ,Ô,ð 	Øåð`¨Zð `ð `Ý/ð`ð `ð `ñô ð ðð r   r.   ÚtypeÚboolc                óØ   — t          | ¦  «        }|rX	 t          |t          ¦  «        r1t          | ¦  «        }t	          |¦  «        dk    o|d         t
          u S n# t          $ r Y nw xY wdS )zMCheck if annotation is a sequence of strings (list[str], Sequence[str], etc).é   r   F)r
   Ú
issubclassr   r	   ÚlenÚstrr3   ©r.   ÚoriginÚargss      r   r2   r2   G   s†   € å˜
Ñ#Ô#€Fàð ð	Ý˜&¥(Ñ+Ô+ð 9Ý 
Ñ+Ô+�å˜4‘y”y A’~Ð8¨$¨q¬'µS¨.Ð8ð9øõ ð 	ð 	ð 	àˆDð	øøøð ˆ5s   “AA Á
A'Á&A'c                ó¸   — | t           v rdS t          | ¦  «        }|t          u s|t          j        u r(t          | ¦  «        }t          d„ |D ¦   «         ¦  «        S dS )zDCheck if a field is a primitive type allowed in elicitation schemas.Tc              3  ób   K  — | ]*}|t           j        u p|t          v pt          |¦  «        V — Œ+d S ©N)r/   r0   r4   r2   )Ú.0Úargs     r   ú	<genexpr>z&_is_primitive_field.<locals>.<genexpr>b   sT   è è € ð 
ð 
ØilˆC•5”>Ð!Ðd SÕ,HÐ%HÐdÕL_Ð`cÑLdÔLdð
ð 
ð 
ð 
ð 
ð 
r   F)r4   r
   r   r/   Ú	UnionTyper	   Úallr?   s      r   r1   r1   W   s{   € ð Õ1Ð1Ð1Øˆtõ ˜
Ñ#Ô#€FØ•€€˜&¥E¤OÐ3Ð3Ý˜
Ñ#Ô#ˆåð 
ð 
Øptð
ñ 
ô 
ñ 
ô 
ð 	
ð ˆ5r   Úsessionr   Úmessager>   útype[ElicitSchemaModelT]Úrelated_request_idúRequestId | Noneú%ElicitationResult[ElicitSchemaModelT]c              ƒ  ó’  K  — t          |¦  «         |                     ¦   «         }|                      |||¬¦  «        ƒ d{V —†}|j        dk    r1|j        �*|                     |j        ¦  «        }t          |¬¦  «        S |j        dk    rt          ¦   «         S |j        dk    rt          ¦   «         S t          d|j        › �¦  «        ‚)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.
    )rK   ÚrequestedSchemarM   Nr   )r   r!   r$   úUnexpected elicitation action: )
r7   Úmodel_json_schemaÚelicit_formr   ÚcontentÚmodel_validater   r    r#   Ú
ValueError)rJ   rK   r'   rM   Újson_schemaÚresultÚvalidated_datas          r   Úelicit_with_validationr[   i   sñ   è è € õ" ! Ñ(Ô(Ð(à×*Ò*Ñ,Ô,€Kà×&Ò&ØØ#Ø-ð 'ñ ô ð ð ð ð ð ð €Fð „}˜Ò Ð  V¤^Ð%?à×.Ò.¨v¬~Ñ>Ô>ˆÝ"¨Ð7Ñ7Ô7Ð7Ø	Œ˜)Ò	#Ð	#Ý"Ñ$Ô$Ð$Ø	Œ˜(Ò	"Ð	"Ý#Ñ%Ô%Ð%õ ÐJ¸6¼=ÐJÐJÑKÔKÐKr   ÚurlÚelicitation_idÚUrlElicitationResultc              ƒ  ó  K  — |                       ||||¬¦  «        ƒ d{V —†}|j        dk    rt          ¦   «         S |j        dk    rt          ¦   «         S |j        dk    rt	          ¦   «         S t          d|j        › �¦  «        ‚)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
    )rK   r\   r]   rM   Nr   r!   r$   rR   )Ú
elicit_urlr   r&   r    r#   rW   )rJ   rK   r\   r]   rM   rY   s         r   r`   r`   ‘   s´   è è € ð< ×%Ò%ØØØ%Ø-ð	 &ñ ô ð ð ð ð ð ð €Fð „}˜Ò Ð Ý%Ñ'Ô'Ð'Ø	Œ˜)Ò	#Ð	#Ý"Ñ$Ô$Ð$Ø	Œ˜(Ò	"Ð	"Ý#Ñ%Ô%Ð%õ ÐJ¸6¼=ÐJÐJÑKÔKÐKr   )r'   r(   r)   r*   )r.   r8   r)   r9   rD   )
rJ   r   rK   r>   r'   rL   rM   rN   r)   rO   )rJ   r   rK   r>   r\   r>   r]   r>   rM   rN   r)   r^   )$r   Ú
__future__r   r/   Úcollections.abcr   Útypingr   r   r   r   r	   r
   Úpydanticr   Úmcp.server.sessionr   Ú	mcp.typesr   r   r   r    r#   ÚElicitationResultr&   r^   r>   ÚintÚfloatr9   r4   r7   r2   r1   r[   r`   r   r   r   ú<module>rj      s2  ðØ ,Ð ,à "Ð "Ð "Ð "Ð "Ð "à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ Ià Ð Ð Ð Ð Ð à ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø Ð Ð Ð Ð Ð à�WÐ1¸ÐCÑCÔCÐ ðð ð ð ð ˜) WÐ-?Ô%@ñ ô ð ð+ð +ð +ð +ð +˜)ñ +ô +ð +ð)ð )ð )ð )ð )˜9ñ )ô )ð )ð (Ð(:Ô;Ð>QÑQÐThÑhÐ ð)ð )ð )ð )ð )˜Yñ )ô )ð )ð .Ð0CÑCÐFZÑZÐ ð !$ S¨%°Ð6Ð ðð ð ð ð&ð ð ð ð ð ð ð ð, ,0ð	%Lð %Lð %Lð %Lð %LðZ ,0ð-Lð -Lð -Lð -Lð -Lð -Lð -Lr   