
    Vi                    r   S r SSKJr  SSKrSSKJ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
9r " S S\\\   5      r " S S\5      r " S S\5      r\\   \-  \-  r " S S\5      r\\-  \-  r\\\\4rSS jrSS jr SS jr! S         SS jjr" S           SS jjr#g)z&Elicitation utilities for MCP servers.    )annotationsN)Sequence)GenericLiteralTypeVarUnionget_args
get_origin)	BaseModel)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.acceptLiteral['accept']actionr   data N__name__
__module____qualname____firstlineno____doc__r   __annotations____static_attributes__r       i/home/james-whalen/.local/share/pipx/venvs/semgrep/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                  (    \ rS rSr% SrSrS\S'   Srg)AcceptedUrlElicitation'   z0Result when user accepts a URL mode elicitation.r   r   r   r   Nr   r   r    r!   r+   r+   '   s    : (F(r    r+   c                   U R                   R                  5        Ha  u  pUR                  nUb  U[        R                  L a  M)  [        U5      (       a  M;  [        U5      (       a  MM  [        SU S[         S35      e   g)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_infor0   s       r!   _validate_elicitation_schemar:   4   s    "("5"5";";"=
**
u~~!= ,, ,,,ZL8S/0 1_`  #>r    c                    [        U 5      nU(       aC   [        U[        5      (       a+  [        U 5      n[	        U5      S:H  =(       a    US   [
        L $  gg! [         a     gf = f)zMCheck if annotation is a sequence of strings (list[str], Sequence[str], etc).   r   F)r
   
issubclassr   r	   lenstrr5   r0   originargss      r!   r4   r4   G   sg    
#F	&(++
+4yA~8$q'S.8 ,   		s   ?A 
A$#A$c                    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     #    U  H8  o[         R                  L =(       d    U[        ;   =(       d    [        U5      v   M:     g 7fN)r1   r2   r6   r4   ).0args     r!   	<genexpr>&_is_primitive_field.<locals>.<genexpr>b   s6      
ptil5>>!dS,H%HdL_`cLddpts   A AF)r6   r
   r   r1   	UnionTyper	   allr@   s      r!   r3   r3   W   sW     11 
#F&EOO3
# 
pt
 
 	
 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 (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: )
r:   model_json_schemaelicit_formr   contentmodel_validater   r#   r'   
ValueError)sessionrM   r7   rO   json_schemaresultvalidated_datas          r!   elicit_with_validationrZ   i   s     " !(**,K&&#- '  F }} V^^%?..v~~>"77	)	#"$$	(	"#%% :6==/JKK!s   0CCBCc                  #    U R                  UUUUS9I Sh  vN nUR                  S:X  a
  [        5       $ UR                  S:X  a
  [        5       $ UR                  S:X  a
  [	        5       $ [        SUR                   35      e Nj7f)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
)rM   urlelicitation_idrO   Nr   r%   r)   rP   )
elicit_urlr   r+   r#   r'   rU   )rV   rM   r\   r]   rO   rX   s         r!   r^   r^      s     < %%%-	 &  F }} %''	)	#"$$	(	"#%% :6==/JKKs   BBA+B)r7   ztype[BaseModel]returnNone)r0   typer_   boolrE   )
rV   r   rM   r?   r7   ztype[ElicitSchemaModelT]rO   RequestId | Noner_   z%ElicitationResult[ElicitSchemaModelT])rV   r   rM   r?   r\   r?   r]   r?   rO   rc   r_   UrlElicitationResult)$r   
__future__r   r1   collections.abcr   typingr   r   r   r   r	   r
   pydanticr   mcp.server.sessionr   	mcp.typesr   r   r   r#   r'   ElicitationResultr+   rd   r?   intfloatrb   r6   r:   r4   r3   rZ   r^   r   r    r!   <module>rn      s<   , "  $ I I  , 1C )W-?%@ +) +)9 ) ((:;>QQThh )Y ) .0CCFZZ  !$S%6 & , ,0	%L%L%L %%L )	%L
 +%LZ ,0-L-L-L 
-L 	-L
 )-L -Lr    