
    )`i                    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__     j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/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
++4yyA~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       
 
ilC5>!dS,H%HdL_`cLdLd
 
 
 
 
 
r   F)r4   r
   r   r/   	UnionTyper	   allr?   s      r   r1   r1   W   s{     111t 
##F&EO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	)	#	#"$$$	(	"	"#%%% J6=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 }  %'''	)	#	#"$$$	(	"	"#%%% J6=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QThh ) ) ) ) )Y ) ) ) .0CCFZZ  !$S%6    &       , ,0	%L %L %L %L %LZ ,0-L -L -L -L -L -L -Lr   